Skip to content

Ridimo/hospitalSimulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hospital Simulator

Strictly compliant version with case-sensitive codes:

  • Patients: F,H,D,T,X
  • Drugs: As,An,I,P

Build & Run

Technical versions

  • Java 17
  • Spring Boot 3.5.x

Multiple parameters:

mvn clean package
java -jar target/hospital-simulator-1.0.0.jar "T,F,D" "An,I"
# => F:2,H:0,D:1,T:0,X:0

Single parameter (no drugs):

java -jar target/hospital-simulator-1.0.0.jar "D,D"
# => F:0,H:0,D:0,T:0,X:2

Input / Output

  • Param 1: Inputs of patient states (D,F,F)
  • Param 2 (optional): Inputs of drugs (As,I)
  • Output (fixed order):
F:#,H:#,D:#,T:#,X:#

Rule Order (per patient)

  1. Cures / Deaths
    • As or P cure FH
    • An cures TH
    • D dies (X) if I is absent
  2. Side Effect
    • I + AnHF
  3. Fatal Mix
    • As + Pall living (F/H/D/T) → X
  4. Resurrection
    • probability 1 / 1,000,000 : XH (can be enabled/disabled)

X is unaffected by anything except resurrection.

Configuration

src/main/resources/application.properties

logging.level.com.evooq.hospital=INFO
simulator.resurrection.enabled=true

Tests & Coverage

mvn test jacoco:report
# report: target/site/jacoco/index.html

Tested

  • Cures (As, P, An)
  • D dies without I, survives with I
  • I+An effect (including T cured → H then HF)
  • Fatal mix As+P
  • Deterministic resurrection via RandomProvider stub (0% / 100%)
  • Strict parsing (invalid tokens with WARN), empty inputs OK

Design & additional decisions

  • Strict but tolerant parsing: unknown tokens are ignored (and logged as WARN) instead of throwing exceptions.
    Reason: remain robust for CLI, avoid a stray character blocking the entire simulation.
    Alternative (easy to enable): throw an exception on the first error — not chosen for KISS principle.
  • Deterministic processing order: Phases are fixed (1→4): cures/deathsside effectsfatal mixresurrection. Guarantees consistent outcomes.
  • Injectable RNG: RandomProvider enables reproducible tests (0% / 100%) and toggling resurrection via configuration.
  • Data structures by intent:
    • Patients = List to preserve order and duplicates (realistic: multiple diabetics, etc.).
    • Drugs = LinkedHashSet/EnumSet for deduplication and O(1) membership checks; insertion order helps debugging.
    • Counting = EnumMap<HealthState,Integer> for compact, fast enum-keyed aggregation.
  • Robust, strict parsing:
    • Unknown tokens are ignored and WARN-logged; empty/whitespace tokens are tolerated.
    • Trimming applied; null or empty inputs return empty collections (CLI remains resilient).
  • CLI contract:
    • 0 args → usage is printed; >2 args → extra args ignored with WARN logging.
    • Output is always F,H,D,T,X in that order (script-friendly).
  • Testability:
    • Unit tests cover cures, diabetes rule, side effects, fatal mix, resurrection (true/false), and edge cases.
    • End-to-end tests execute the CLI, capture stdout/stderr, and assert on the last non-empty line.
    • Parameterized tests reduce duplication for simple cure and diabetes scenarios.
  • Challenge examples: examples #1, #2, #3 are covered, along with an end-to-end integration test (CLI).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages