Skip to content

BetssonGroup/web3-be-qa-assessment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Collatz Assessment Solution

This repository contains a small .NET8 solution structured to demonstrate clean layering, basic domain logic (Collatz sequence generation), and accompanying automated tests.

Solution Structure

/README.md
/src
 /Collatz.Core -> Core library containing domain abstractions & implementations
 /Collatz.Api -> ASP.NET Core Web API exposing Collatz functionality
 /Collatz.Core.UnitTests -> Unit tests for the core library
 /Collatz.Api.IntegrationTests-> Integration tests for the API layer

Projects

  • Collatz.Core

    • Provides the domain model for generating Collatz sequences.
    • Exposes a generic interface ICollatzSequenceGenerator<T> with two concrete implementations:
    • ULongCollatzSequenceGenerator (fast path for numbers that fit in ulong).
    • BigIntegerCollatzSequenceGenerator (arbitrary length integers via BigInteger).
    • Includes DI extension methods (AddCollatz, AddULongCollatz, AddBigIntegerCollatz).
  • Collatz.Api

    • ASP.NET Core minimal hosting model.
    • Registers the generators plus an internal application service (CollatzService) that:
    • Validates string input representing a positive integer.
    • Chooses the appropriate generator (tries ulong, falls back to BigInteger).
    • CollatzController exposes a single GET endpoint: /Collatz/{value} returning the sequence as an array of strings.
  • Collatz.Core.UnitTests

    • Uses xUnit to validate correctness, edge cases, and error handling of the core generators.
  • Collatz.Api.IntegrationTests

    • Uses Microsoft.AspNetCore.Mvc.Testing to spin up an in-memory test server and verify end?to?end API behavior.

Prerequisites

Verify installation:

dotnet --version

Should report 8.x.

Restore, Build, Test

From the repository root:

dotnet restore
dotnet build

Run all tests:

dotnet test

Running the API

dotnet run --project src/Collatz.Api

The API will start (default Kestrel ports). In development, Swagger UI is enabled at:

https://localhost:xxxxx/swagger

Example Request

GET https://localhost:xxxxx/Collatz/27

Response (truncated example):

["27","82","41", ... , "1"]

For very large values:

GET https://localhost:xxxxx/Collatz/18446744073709551616

The service automatically chooses the BigInteger path as needed.

Design Notes

  • Separation of concerns: API contains only transport & orchestration; domain logic lives in Collatz.Core.
  • Generic abstraction allows future numeric type extensions without changing API surface.
  • Dependency Injection: explicit service registrations via AddCollatz() extension for clarity and testability.
  • Validation: input accepted only as a digit string > 0; sequences always terminate at 1 per conjecture definition.

About

Assessment for backend quality assurance.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages