This project showcases my proficiency in Go by creating a clear and readable poker hand evaluator. The primary focus is on writing clean, maintainable code that effectively demonstrates the logic behind evaluating various poker hands.
- Provide 2 poker hands with 5 cards in each hand.
- Each card must start with the rank and then the suit e.g.
5C
as in the5 of Clubs
. - Cards are case-insensitive. Therefore,
aH
is the same asAh
orAH
.
- 2-9 are the same, e.g.
2
or8
- 10 is
T
- Jack is
J
- Queen is
Q
- King is
K
- Ace is
A
- Clubs are
C
- Diamonds are
D
- Hearts are
H
- Spades are
S
- Go 1.23.0 or above
- make (if you want to use the
Makefile
provided) - Docker
IMPORTANT: No 3rd party dependencies are used.
I could easily use Cobra (and usually I do, because it allows me to write powerful CLIs), but I felt it was too much for such a tiny project. I only ever use dependencies when it's say an adapter for an external service e.g. Redis, MySQL or Prometheus.
go run . "AH AC AD QC QD" "QD QH QC AD AC"
Output the result as JSON, instead of text
go run . --json "AH AC AD QC QD" "QD QH QC AD AC"
or when using make
make
# As text
./bin/poker-evaluator "AH AC AD QC QD" "QD QH QC AD AC"
# As JSON
./bin/poker-evaluator --json "AH AC AD QC QD" "QD QH QC AD AC"
Display the version of the application and exit.
# As text
./bin/poker-evaluator --version
# As JSON
./bin/poker-evaluator --json --version
Display the help text and exit.
./bin/poker-evaluator --help
- Build the Docker image with the tag
poker-evaluator
.
docker build -t poker-evaluator .
- Run the Docker image with the provided arguments.
# As text
docker run --rm poker-evaluator "AH AC AD QC QD" "QD QH QC AD AC"
# As JSON
docker run --rm poker-evaluator --json "AH AC AD QC QD" "QD QH QC AD AC"
Display the version of the application and exit.
# As text
docker run --rm poker-evaluator --version
# As JSON
docker run --rm poker-evaluator --json --version
Display the help text and exit.
docker run --rm poker-evaluator --help
Tests are written as Table-Driven Tests.
go test -cover -v ./...
or when using make
make test
For the poker
package (found under internal
), the test coverage is about
97%. This isn't to say there aren't any "bugs" 😀, but that it's better than 0%
and is an indication that it's passing the
Poker rules.
go test -cover -v github.com/softwarespot/poker-evaluator/internal/poker
Docker
docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:latest golangci-lint run -v --tests=false --disable-all -E durationcheck,errorlint,exhaustive,gocritic,gosimple,ineffassign,misspell,predeclared,revive,staticcheck,unparam,unused,whitespace --max-issues-per-linter=10000 --max-same-issues=10000
Local
golangci-lint run --tests=false --disable-all -E durationcheck,errorlint,exhaustive,gocritic,gosimple,ineffassign,misspell,predeclared,revive,staticcheck,unparam,unused,whitespace --max-issues-per-linter=10000 --max-same-issues=10000
This section documents any additional information which might be deemed important for the reviewer.
- Despite using 1.23.0+ and the
slices
pkg being available, I have opted not to use it, and instead went for how I've been writing Go code before theslices
pkg existed. Although for production code, I have started to use it where applicable. - I haven't used an assertion library, as I have never used one in production code and have opted for creating my own simple test helpers.
- The
Hand.Compare()
func returns anint
as an alias type ofWinner
, as I thought since it returns 3 exclusive values, that it should be similar to that of [https://pkg.go.dev/cmp#Compare]. - Naming is hard, so I have tried my best to name funcs, structs, variables etc... as best I can.
Commands used to setup the project's directory.
mkdir poker-evaluator
cd poker-evaluator
go mod init github.com/softwarespot/poker-evaluator
touch README.md
touch LICENSE
touch Dockerfile
The code has been licensed under the MIT license.