Expand
This is an intentionally over‑engineered implementation of the classic FizzBuzz problem. It highlights a common real-world pitfall: without a defined scope, you have no idea how "quality" to make your solution. Should FizzBuzz be a couple of if statements? A microservice? A distributed system with CI/CD, weighted rule engines, and Dockerized test suites? Without requirements, all of those answers are equally valid, and equally absurd. This project leans into the absurdity on purpose.
- FizzBuzz prints numbers from 1 to n.
- If a number is divisible by a rule's key (divisor), the rule's value (string) is appended to the output.
- When multiple rules match, they are ordered by their weight (lower weight = earlier in the output), then concatenated.
Default rules (defined inside FizzBuzz.fizzBuzz):
- 3 -> "Fizz" (weight 1)
- 5 -> "Buzz" (weight 2)
The ordering by weight ensures, for example, that for 15 both rules match and produce "FizzBuzz" in the expected order.
Key classes:
- src/main/java/FizzBuzz.java — main implementation and a tiny demo entry point.
- src/main/java/FizzRule.java — a record that stores key, value, and weight and implements Comparable by weight.
- src/main/java/FizzBuzzTests.java — self‑contained tests that validate expected output over several ranges.
- src/main/java/TestResult.java — small helper type used by the tests to report pass/fail.
Choose either setup:
- Docker (recommended for a zero‑setup run)
- OR Java 17+ (e.g., Eclipse Temurin 17)
- Build the test image
docker build -t fizzbuzz-test .- Run the test suite (container exits non‑zero on failures)
docker run --rm fizzbuzz-testOption B — Local Java From the repository root:
- Compile
javac -d . src/main/java/*.java- Run tests
java main.java.FizzBuzzTests- (Optional) Run the demo program
java main.java.FizzBuzzIf you modify the demo to call fizzBuzz(15), the output would be:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
- src/main/java/FizzBuzz.java
- src/main/java/FizzBuzzTests.java
- src/main/java/FizzRule.java
- src/main/java/TestResult.java
- Dockerfile
- .github/workflows/ci.yml
A GitHub Actions workflow (Java CI) builds a Docker image and runs the test suite on pushes and PRs to main. The Badge is visible at the top of this README.
Rules are currently created inside FizzBuzz.fizzBuzz. To experiment, you can change the defaultRules array in that method. For example, to add a rule for 7:
- new FizzRule(7, "Bazz", 3) Make sure to give it an appropriate weight so the concatenation order matches your preference.
- java: command not found — Install Java 17+ (e.g., Eclipse Temurin) or use the Docker path instead.
- docker: permission denied / not found — Ensure Docker Desktop (macOS/Windows) or Docker Engine (Linux) is installed and running.
- Tests fail locally — Recompile cleanly (remove old .class files or compile to a fresh directory) and ensure you are in the repo root when running java main.java.FizzBuzzTests.
Issues and PRs welcome! This project is for fun and learning—clear test coverage and small, focused changes are appreciated.
This project is licensed under the MIT License — see the LICENSE file for details.