Strictly compliant version with case-sensitive codes:
- Patients:
F,H,D,T,X - Drugs:
As,An,I,P
- 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:0Single parameter (no drugs):
java -jar target/hospital-simulator-1.0.0.jar "D,D"
# => F:0,H:0,D:0,T:0,X:2- 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:#
- Cures / Deaths
AsorPcureF→HAncuresT→HDdies (X) ifIis absent
- Side Effect
I+An⇒H→F
- Fatal Mix
As+P⇒ all living (F/H/D/T) →X
- Resurrection
- probability 1 / 1,000,000 :
X→H(can be enabled/disabled)
- probability 1 / 1,000,000 :
Xis unaffected by anything except resurrection.
src/main/resources/application.properties
logging.level.com.evooq.hospital=INFO
simulator.resurrection.enabled=truemvn test jacoco:report
# report: target/site/jacoco/index.html- Cures (
As,P,An) Ddies withoutI, survives withII+Aneffect (includingTcured →HthenH→F)- Fatal mix
As+P - Deterministic resurrection via
RandomProviderstub (0% / 100%) - Strict parsing (invalid tokens with WARN), empty inputs OK
- 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/deaths→side effects→fatal mix→resurrection. Guarantees consistent outcomes. - Injectable RNG:
RandomProviderenables reproducible tests (0% / 100%) and toggling resurrection via configuration. - Data structures by intent:
- Patients =
Listto preserve order and duplicates (realistic: multiple diabetics, etc.). - Drugs =
LinkedHashSet/EnumSetfor deduplication and O(1) membership checks; insertion order helps debugging. - Counting =
EnumMap<HealthState,Integer>for compact, fast enum-keyed aggregation.
- Patients =
- 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,Xin 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).