This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Let's do a bit of a kata in gleam💎✨
Co-authored-by: Ashish Sehra <ashish.sehra@armakuni.com> Co-authored-by: Mark Bradley <mark.bradley@armkauni.com> Co-authored-by: Tom Oram <tom.oram@armakuni.com> Co-authored-by: Ryan Tiffany <ryan.tiffany@armakuni.com>
- Loading branch information
Showing
7 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: "26.0.2" | ||
gleam-version: "0.34.1" | ||
rebar3-version: "3" | ||
# elixir-version: "1.15.4" | ||
- run: gleam deps download | ||
- run: gleam test | ||
- run: gleam format --check src test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.beam | ||
*.ez | ||
/build | ||
erl_crash.dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# ak_day_play_gleam | ||
|
||
[![Package Version](https://img.shields.io/hexpm/v/ak_day_play_gleam)](https://hex.pm/packages/ak_day_play_gleam) | ||
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/ak_day_play_gleam/) | ||
|
||
```sh | ||
gleam add ak_day_play_gleam | ||
``` | ||
```gleam | ||
import ak_day_play_gleam | ||
pub fn main() { | ||
// TODO: An example of the project in use | ||
} | ||
``` | ||
|
||
Further documentation can be found at <https://hexdocs.pm/ak_day_play_gleam>. | ||
|
||
## Development | ||
|
||
```sh | ||
gleam run # Run the project | ||
gleam test # Run the tests | ||
gleam shell # Run an Erlang shell | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name = "ak_day_play_gleam" | ||
version = "1.0.0" | ||
|
||
# Fill out these fields if you intend to generate HTML documentation or publish | ||
# your project to the Hex package manager. | ||
# | ||
# description = "" | ||
# licences = ["Apache-2.0"] | ||
# repository = { type = "github", user = "username", repo = "project" } | ||
# links = [{ title = "Website", href = "https://gleam.run" }] | ||
# | ||
# For a full reference of all the available options, you can have a look at | ||
# https://gleam.run/writing-gleam/gleam-toml/. | ||
|
||
[dependencies] | ||
gleam_stdlib = "~> 0.34 or ~> 1.0" | ||
|
||
[dev-dependencies] | ||
gleeunit = "~> 1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This file was generated by Gleam | ||
# You typically do not need to edit this file | ||
|
||
packages = [ | ||
{ name = "gleam_stdlib", version = "0.35.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5443EEB74708454B65650FEBBB1EF5175057D1DEC62AEA9D7C6D96F41DA79152" }, | ||
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" }, | ||
] | ||
|
||
[requirements] | ||
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } | ||
gleeunit = { version = "~> 1.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import gleam/io | ||
import gleam/int | ||
import gleam/result | ||
import gleam/list | ||
|
||
pub fn main() { | ||
io.println("Hello from ak_day_play_gleam!") | ||
} | ||
|
||
pub fn score(rolls) { | ||
let frames = list.range(0, 9) | ||
int.sum(list.map(frames, fn(x) { frame_score(x, rolls) })) | ||
} | ||
|
||
fn frame_score(frame_number, rolls) { | ||
let initial_index = 2 * frame_number | ||
case | ||
result.unwrap(list.at(rolls, initial_index), 0) | ||
+ result.unwrap(list.at(rolls, initial_index + 1), 0) | ||
{ | ||
10 -> 10 + result.unwrap(list.at(rolls, initial_index + 2), 0) | ||
value -> value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import gleeunit | ||
import gleeunit/should | ||
import ak_day_play_gleam | ||
|
||
pub fn main() { | ||
gleeunit.main() | ||
} | ||
|
||
// gleeunit test functions end in `_test` | ||
pub fn gutter_ball_game_test() { | ||
ak_day_play_gleam.score([ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]) | ||
|> should.equal(0) | ||
} | ||
|
||
pub fn score_of_1_test() { | ||
ak_day_play_gleam.score([ | ||
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]) | ||
|> should.equal(1) | ||
} | ||
|
||
pub fn score_of_1_not_in_first_frame_test() { | ||
ak_day_play_gleam.score([ | ||
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]) | ||
|> should.equal(1) | ||
} | ||
|
||
pub fn score_of_2_with_two_singles_test() { | ||
ak_day_play_gleam.score([ | ||
0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]) | ||
|> should.equal(2) | ||
} | ||
|
||
pub fn score_of_3_with_two_non_zero_rolls_test() { | ||
ak_day_play_gleam.score([ | ||
0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]) | ||
|> should.equal(3) | ||
} | ||
|
||
pub fn score_spare_test() { | ||
ak_day_play_gleam.score([ | ||
6, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]) | ||
|> should.equal(12) | ||
} | ||
|
||
pub fn score_spare_test_doubling_two_test() { | ||
ak_day_play_gleam.score([ | ||
6, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]) | ||
|> should.equal(14) | ||
} | ||
|
||
pub fn score_strike_doubles_the_next_frame_test() { | ||
ak_day_play_gleam.score([ | ||
10, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]) | ||
|> should.equal(14) | ||
} | ||
|
||
pub fn score_adds_up_to_eleven_but_no_spare_test() { | ||
ak_day_play_gleam.score([ | ||
6, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, | ||
]) | ||
|> should.equal(11) | ||
} |