From bef98bd75f57f62c19c7d4ffd2b536eea0657cda Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Tue, 16 Jan 2024 15:00:08 +0000 Subject: [PATCH] Update exercises --- .tool-versions | 1 - .../src/exercise_generator.gleam | 42 +-- .../src/high_score_board.gleam | 2 +- .../test/high_score_board_test.gleam | 22 +- .../accumulate/test/accumulate_test.gleam | 14 +- .../alphametics/test/alphametics_test.gleam | 132 ++++---- .../practice/anagram/test/anagram_test.gleam | 7 +- .../practice/bowling/test/bowling_test.gleam | 33 +- .../practice/change/test/change_test.gleam | 6 +- .../practice/clock/test/clock_test.gleam | 6 +- exercises/practice/etl/src/etl.gleam | 2 +- exercises/practice/etl/test/etl_test.gleam | 100 +++---- exercises/practice/house/src/house.gleam | 5 +- .../src/nucleotide_count.gleam | 2 +- .../test/nucleotide_count_test.gleam | 10 +- exercises/practice/pov/test/pov_test.gleam | 281 ++++++++---------- .../satellite/test/satellite_test.gleam | 39 ++- .../practice/series/test/series_test.gleam | 6 +- .../practice/word-count/src/word_count.gleam | 2 +- .../word-count/test/word_count_test.gleam | 30 +- 20 files changed, 364 insertions(+), 378 deletions(-) delete mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index 5a0198418..000000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -gleam 0.30.5 diff --git a/exercise_generator/src/exercise_generator.gleam b/exercise_generator/src/exercise_generator.gleam index 13e57f791..0afb6441c 100644 --- a/exercise_generator/src/exercise_generator.gleam +++ b/exercise_generator/src/exercise_generator.gleam @@ -1,5 +1,5 @@ import gleam/io -import gleam/map.{type Map} +import gleam/dict.{type Dict} import gleam/function import gleam/list import gleam/int @@ -83,7 +83,7 @@ fn json_data_to_gleam_value(data: JsonData) -> String { JsonObject(map) -> { let args = map - |> map.to_list + |> dict.to_list |> list.map(fn(arg) { clean_variable(arg.0) <> ": " <> json_data_to_gleam_value(arg.1) }) @@ -105,11 +105,11 @@ fn have_same_type(a: JsonData, b: JsonData) -> Bool { JsonObject(x), JsonObject(y) -> { let x: List(#(String, JsonData)) = x - |> map.to_list + |> dict.to_list |> list.sort(fn(a, b) { string.compare(a.0, b.0) }) let y: List(#(String, JsonData)) = y - |> map.to_list + |> dict.to_list |> list.sort(fn(a, b) { string.compare(a.0, b.0) }) let comparaison = list.strict_zip(x, y) @@ -181,7 +181,7 @@ fn write_solution_files( let content = functions - |> map.to_list + |> dict.to_list |> list.sort(by: fn(a, b) { int.compare({ a.1 }.order, { b.1 }.order) }) |> list.map(fn(item) { let #(name, Function(arguments, return_type, can_error, need_labels, _)) = @@ -215,7 +215,13 @@ fn write_solution_files( }) |> string.join(", ") - "pub fn " <> clean_variable(name) <> "(" <> args <> ") -> " <> return <> " {\n todo \n}" + "pub fn " + <> clean_variable(name) + <> "(" + <> args + <> ") -> " + <> return + <> " {\n todo \n}" }) |> string.join("\n") @@ -238,7 +244,7 @@ fn write_solution_files( } fn functions_to_implement(test_cases: List(TestCase)) -> Map(String, Function) { - list.fold(over: test_cases, from: map.new(), with: check_test_case) + list.fold(over: test_cases, from: dict.new(), with: check_test_case) } fn check_test_case( @@ -255,13 +261,13 @@ fn check_test_case( .., )) -> { let can_error = case expected { - JsonObject(object) -> map.has_key(object, "error") + JsonObject(object) -> dict.has_key(object, "error") _ -> False } let args = input - |> map.to_list + |> dict.to_list |> list.map(fn(arg) { Argument(arg.0, arg.1) }) let need_labels = case args { @@ -272,7 +278,7 @@ fn check_test_case( _ -> True } - let current_function = case map.get(functions, function) { + let current_function = case dict.get(functions, function) { Ok(func) -> { let func = Function(..func, need_labels: func.need_labels || need_labels) @@ -284,10 +290,10 @@ fn check_test_case( } Error(Nil) -> - Function(args, expected, can_error, need_labels, map.size(functions)) + Function(args, expected, can_error, need_labels, dict.size(functions)) } - map.insert(functions, function, current_function) + dict.insert(functions, function, current_function) } } } @@ -368,7 +374,9 @@ fn print_test( [ "This test reimplements the test with uuid " <> uuid, "Please identify that test and remove it. Link:", - "https://github.com/exercism/problem-specifications/blob/main/exercises/" <> slug <> "/canonical-data.json", + "https://github.com/exercism/problem-specifications/blob/main/exercises/" + <> slug + <> "/canonical-data.json", ] |> list.append(comments) |> print_comments() @@ -376,10 +384,10 @@ fn print_test( } let test_name = flatten_description(prefix <> description) let assert Ok(Function(need_labels: need_labels, ..)) = - map.get(functions, function) + dict.get(functions, function) let input = input - |> map.to_list + |> dict.to_list |> list.map(fn(item) { case need_labels { True -> @@ -427,11 +435,11 @@ fn get_expected_value( functions: Map(String, Function), expected: JsonData, ) { - case map.get(functions, function) { + case dict.get(functions, function) { Ok(Function(can_error: True, ..)) -> case expected { JsonObject(map) -> - case map.get(map, "error") { + case dict.get(map, "error") { Ok(value) -> "Error(" <> json_data_to_gleam_value(value) <> ")" Error(Nil) -> "Ok(" <> json_data_to_gleam_value(expected) <> ")" } diff --git a/exercises/concept/high-score-board/src/high_score_board.gleam b/exercises/concept/high-score-board/src/high_score_board.gleam index 88a74377f..1a2aeb950 100644 --- a/exercises/concept/high-score-board/src/high_score_board.gleam +++ b/exercises/concept/high-score-board/src/high_score_board.gleam @@ -1,4 +1,4 @@ -import gleam/map.{type Map} +import gleam/dict.{type Dict} pub type ScoreBoard = Map(String, Int) diff --git a/exercises/concept/high-score-board/test/high_score_board_test.gleam b/exercises/concept/high-score-board/test/high_score_board_test.gleam index f1a0319e6..e695e789e 100644 --- a/exercises/concept/high-score-board/test/high_score_board_test.gleam +++ b/exercises/concept/high-score-board/test/high_score_board_test.gleam @@ -1,7 +1,7 @@ import high_score_board import exercism/test_runner import exercism/should -import gleam/map +import gleam/dict pub fn main() { test_runner.main() @@ -9,14 +9,14 @@ pub fn main() { pub fn create_score_board_test() { high_score_board.create_score_board() - |> should.equal(map.from_list([#("The Best Ever", 1_000_000)])) + |> should.equal(dict.from_list([#("The Best Ever", 1_000_000)])) } pub fn add_player_board_test() { [#("Amil Pastorius", 99_373), #("Min-seo Shin", 0)] - |> map.from_list + |> dict.from_list |> high_score_board.add_player("Jessie Johnson", 1337) - |> should.equal(map.from_list([ + |> should.equal(dict.from_list([ #("Amil Pastorius", 99_373), #("Min-seo Shin", 0), #("Jessie Johnson", 1337), @@ -25,9 +25,9 @@ pub fn add_player_board_test() { pub fn remove_player_test() { [#("Amil Pastorius", 99_373), #("Min-seo Shin", 0), #("Jesse Johnson", 1337)] - |> map.from_list + |> dict.from_list |> high_score_board.remove_player("Jesse Johnson") - |> should.equal(map.from_list([ + |> should.equal(dict.from_list([ #("Amil Pastorius", 99_373), #("Min-seo Shin", 0), ])) @@ -35,7 +35,7 @@ pub fn remove_player_test() { pub fn remove_player_unknown_test() { let board = - map.from_list([ + dict.from_list([ #("Amil Pastorius", 99_373), #("Min-seo Shin", 0), #("Jesse Johnson", 1337), @@ -48,11 +48,11 @@ pub fn remove_player_unknown_test() { pub fn update_score_test() { [#("Amil Pastorius", 99_373), #("Min-seo Shin", 0), #("Jesse Johnson", 1337)] - |> map.from_list + |> dict.from_list |> high_score_board.update_score("Min-seo Shin", 1999) |> high_score_board.update_score("Jesse Johnson", 1337) |> high_score_board.update_score("Unknown player", 1) - |> should.equal(map.from_list([ + |> should.equal(dict.from_list([ #("Amil Pastorius", 99_373), #("Min-seo Shin", 1999), #("Jesse Johnson", 2674), @@ -61,9 +61,9 @@ pub fn update_score_test() { pub fn apply_monday_bonus_test() { [#("Amil Pastorius", 345), #("Min-seo Shin", 19), #("Jesse Johnson", 122)] - |> map.from_list + |> dict.from_list |> high_score_board.apply_monday_bonus - |> should.equal(map.from_list([ + |> should.equal(dict.from_list([ #("Amil Pastorius", 445), #("Min-seo Shin", 119), #("Jesse Johnson", 222), diff --git a/exercises/practice/accumulate/test/accumulate_test.gleam b/exercises/practice/accumulate/test/accumulate_test.gleam index dadf73d33..944eccbcc 100644 --- a/exercises/practice/accumulate/test/accumulate_test.gleam +++ b/exercises/practice/accumulate/test/accumulate_test.gleam @@ -28,14 +28,10 @@ pub fn accumulate_reversed_strings_test() { } pub fn accumulate_recursively_test() { - accumulate.accumulate( - ["a", "b", "c"], - fn(x) -> List(String) { - accumulate.accumulate( - ["1", "2", "3"], - fn(y) -> String { string.append(x, y) }, - ) - }, - ) + accumulate.accumulate(["a", "b", "c"], fn(x) -> List(String) { + accumulate.accumulate(["1", "2", "3"], fn(y) -> String { + string.append(x, y) + }) + }) |> should.equal([["a1", "a2", "a3"], ["b1", "b2", "b3"], ["c1", "c2", "c3"]]) } diff --git a/exercises/practice/alphametics/test/alphametics_test.gleam b/exercises/practice/alphametics/test/alphametics_test.gleam index 381337b65..537c60268 100644 --- a/exercises/practice/alphametics/test/alphametics_test.gleam +++ b/exercises/practice/alphametics/test/alphametics_test.gleam @@ -1,7 +1,7 @@ import exercism/test_runner import exercism/should import alphametics -import gleam/map +import gleam/dict pub fn main() { test_runner.main() @@ -9,7 +9,7 @@ pub fn main() { pub fn puzzle_with_three_letters_test() { alphametics.solve("I + BB == ILL") - |> should.equal(Ok(map.from_list([#("B", 9), #("I", 1), #("L", 0)]))) + |> should.equal(Ok(dict.from_list([#("B", 9), #("I", 1), #("L", 0)]))) } pub fn solution_must_have_unique_value_for_each_letter_test() { @@ -24,83 +24,105 @@ pub fn leading_zero_solution_is_invalid_test() { pub fn puzzle_with_two_digits_final_carry_test() { alphametics.solve("A + A + A + A + A + A + A + A + A + A + A + B == BCC") - |> should.equal(Ok(map.from_list([#("A", 9), #("B", 1), #("C", 0)]))) + |> should.equal(Ok(dict.from_list([#("A", 9), #("B", 1), #("C", 0)]))) } pub fn puzzle_with_four_letters_test() { alphametics.solve("AS + A == MOM") - |> should.equal(Ok(map.from_list([#("A", 9), #("M", 1), #("O", 0), #("S", 2)]))) + |> should.equal( + Ok(dict.from_list([#("A", 9), #("M", 1), #("O", 0), #("S", 2)])), + ) } pub fn puzzle_with_six_letters_test() { alphametics.solve("NO + NO + TOO == LATE") - |> should.equal(Ok(map.from_list([ - #("A", 0), - #("E", 2), - #("L", 1), - #("N", 7), - #("O", 4), - #("T", 9), - ]))) + |> should.equal( + Ok( + dict.from_list([ + #("A", 0), + #("E", 2), + #("L", 1), + #("N", 7), + #("O", 4), + #("T", 9), + ]), + ), + ) } pub fn puzzle_with_seven_letters_test() { alphametics.solve("HE + SEES + THE == LIGHT") - |> should.equal(Ok(map.from_list([ - #("E", 4), - #("G", 2), - #("H", 5), - #("I", 0), - #("L", 1), - #("S", 9), - #("T", 7), - ]))) + |> should.equal( + Ok( + dict.from_list([ + #("E", 4), + #("G", 2), + #("H", 5), + #("I", 0), + #("L", 1), + #("S", 9), + #("T", 7), + ]), + ), + ) } pub fn puzzle_with_eight_letters_test() { alphametics.solve("SEND + MORE == MONEY") - |> should.equal(Ok(map.from_list([ - #("D", 7), - #("E", 5), - #("M", 1), - #("N", 6), - #("O", 0), - #("R", 8), - #("S", 9), - #("Y", 2), - ]))) + |> should.equal( + Ok( + dict.from_list([ + #("D", 7), + #("E", 5), + #("M", 1), + #("N", 6), + #("O", 0), + #("R", 8), + #("S", 9), + #("Y", 2), + ]), + ), + ) } pub fn puzzle_with_ten_letters_test() { alphametics.solve("AND + A + STRONG + OFFENSE + AS + A + GOOD == DEFENSE") - |> should.equal(Ok(map.from_list([ - #("A", 5), - #("D", 3), - #("E", 4), - #("F", 7), - #("G", 8), - #("N", 0), - #("O", 2), - #("R", 1), - #("S", 6), - #("T", 9), - ]))) + |> should.equal( + Ok( + dict.from_list([ + #("A", 5), + #("D", 3), + #("E", 4), + #("F", 7), + #("G", 8), + #("N", 0), + #("O", 2), + #("R", 1), + #("S", 6), + #("T", 9), + ]), + ), + ) } pub fn puzzle_with_ten_letters_and_199_addends_test() { alphametics.solve( "THIS + A + FIRE + THEREFORE + FOR + ALL + HISTORIES + I + TELL + A + TALE + THAT + FALSIFIES + ITS + TITLE + TIS + A + LIE + THE + TALE + OF + THE + LAST + FIRE + HORSES + LATE + AFTER + THE + FIRST + FATHERS + FORESEE + THE + HORRORS + THE + LAST + FREE + TROLL + TERRIFIES + THE + HORSES + OF + FIRE + THE + TROLL + RESTS + AT + THE + HOLE + OF + LOSSES + IT + IS + THERE + THAT + SHE + STORES + ROLES + OF + LEATHERS + AFTER + SHE + SATISFIES + HER + HATE + OFF + THOSE + FEARS + A + TASTE + RISES + AS + SHE + HEARS + THE + LEAST + FAR + HORSE + THOSE + FAST + HORSES + THAT + FIRST + HEAR + THE + TROLL + FLEE + OFF + TO + THE + FOREST + THE + HORSES + THAT + ALERTS + RAISE + THE + STARES + OF + THE + OTHERS + AS + THE + TROLL + ASSAILS + AT + THE + TOTAL + SHIFT + HER + TEETH + TEAR + HOOF + OFF + TORSO + AS + THE + LAST + HORSE + FORFEITS + ITS + LIFE + THE + FIRST + FATHERS + HEAR + OF + THE + HORRORS + THEIR + FEARS + THAT + THE + FIRES + FOR + THEIR + FEASTS + ARREST + AS + THE + FIRST + FATHERS + RESETTLE + THE + LAST + OF + THE + FIRE + HORSES + THE + LAST + TROLL + HARASSES + THE + FOREST + HEART + FREE + AT + LAST + OF + THE + LAST + TROLL + ALL + OFFER + THEIR + FIRE + HEAT + TO + THE + ASSISTERS + FAR + OFF + THE + TROLL + FASTS + ITS + LIFE + SHORTER + AS + STARS + RISE + THE + HORSES + REST + SAFE + AFTER + ALL + SHARE + HOT + FISH + AS + THEIR + AFFILIATES + TAILOR + A + ROOFS + FOR + THEIR + SAFE == FORTRESSES", ) - |> should.equal(Ok(map.from_list([ - #("A", 1), - #("E", 0), - #("F", 5), - #("H", 8), - #("I", 7), - #("L", 2), - #("O", 6), - #("R", 3), - #("S", 4), - #("T", 9), - ]))) + |> should.equal( + Ok( + dict.from_list([ + #("A", 1), + #("E", 0), + #("F", 5), + #("H", 8), + #("I", 7), + #("L", 2), + #("O", 6), + #("R", 3), + #("S", 4), + #("T", 9), + ]), + ), + ) } diff --git a/exercises/practice/anagram/test/anagram_test.gleam b/exercises/practice/anagram/test/anagram_test.gleam index 131f6cec8..03709b9bb 100644 --- a/exercises/practice/anagram/test/anagram_test.gleam +++ b/exercises/practice/anagram/test/anagram_test.gleam @@ -27,10 +27,9 @@ pub fn detects_anagram_test() { } pub fn detects_three_anagrams_test() { - find_anagrams( - "allergy", - ["gallery", "ballerina", "regally", "clergy", "largely", "leading"], - ) + find_anagrams("allergy", [ + "gallery", "ballerina", "regally", "clergy", "largely", "leading", + ]) |> should.equal(["gallery", "regally", "largely"]) } diff --git a/exercises/practice/bowling/test/bowling_test.gleam b/exercises/practice/bowling/test/bowling_test.gleam index 5e141009f..a1fc0df8b 100644 --- a/exercises/practice/bowling/test/bowling_test.gleam +++ b/exercises/practice/bowling/test/bowling_test.gleam @@ -217,39 +217,30 @@ pub fn last_two_strikes_followed_by_only_last_bonus_non_strike_points_test() { fn roll_and_check_score(rolls: List(Int), correct_score: Int) { rolls - |> list.fold( - Game([]), - fn(game, pins) { - let assert Ok(new_game) = roll(game, pins) - new_game - }, - ) + |> list.fold(Game([]), fn(game, pins) { + let assert Ok(new_game) = roll(game, pins) + new_game + }) |> score() |> should.equal(Ok(correct_score)) } fn roll_and_last_roll_be_error(rolls: List(Int), last_roll: Int, error: Error) { rolls - |> list.fold( - Game([]), - fn(game, pins) { - let assert Ok(new_game) = roll(game, pins) - new_game - }, - ) + |> list.fold(Game([]), fn(game, pins) { + let assert Ok(new_game) = roll(game, pins) + new_game + }) |> roll(last_roll) |> should.equal(Error(error)) } fn roll_and_score_be_error(rolls: List(Int)) { rolls - |> list.fold( - Game([]), - fn(game, pins) { - let assert Ok(new_game) = roll(game, pins) - new_game - }, - ) + |> list.fold(Game([]), fn(game, pins) { + let assert Ok(new_game) = roll(game, pins) + new_game + }) |> score() |> should.equal(Error(GameNotComplete)) } diff --git a/exercises/practice/change/test/change_test.gleam b/exercises/practice/change/test/change_test.gleam index 49927609d..687df2c54 100644 --- a/exercises/practice/change/test/change_test.gleam +++ b/exercises/practice/change/test/change_test.gleam @@ -33,9 +33,9 @@ pub fn change_with_lower_elbonia_coins_test() { pub fn large_target_values_test() { change.find_fewest_coins([1, 2, 5, 10, 20, 50, 100], 999) - |> should.equal(Ok([ - 2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100, - ])) + |> should.equal( + Ok([2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100]), + ) } pub fn possible_change_without_unit_coins_available_test() { diff --git a/exercises/practice/clock/test/clock_test.gleam b/exercises/practice/clock/test/clock_test.gleam index 02bbb2cce..f0ed9640f 100644 --- a/exercises/practice/clock/test/clock_test.gleam +++ b/exercises/practice/clock/test/clock_test.gleam @@ -310,10 +310,8 @@ pub fn compare_two_clocks_for_equality_clocks_with_negative_hours_and_minutes_te pub fn compare_two_clocks_for_equality_clocks_with_negative_hours_and_minutes_that_wrap_test() { let assert True = - clock.create(hour: 18, minute: 7) == clock.create( - hour: -54, - minute: -11_513, - ) + clock.create(hour: 18, minute: 7) + == clock.create(hour: -54, minute: -11_513) } pub fn compare_two_clocks_for_equality_full_clock_and_zeroed_clock_test() { diff --git a/exercises/practice/etl/src/etl.gleam b/exercises/practice/etl/src/etl.gleam index d56723582..8dafa0adf 100644 --- a/exercises/practice/etl/src/etl.gleam +++ b/exercises/practice/etl/src/etl.gleam @@ -1,4 +1,4 @@ -import gleam/map.{type Map} +import gleam/dict.{type Dict} pub fn transform(legacy: Map(Int, List(String))) -> Map(String, Int) { todo diff --git a/exercises/practice/etl/test/etl_test.gleam b/exercises/practice/etl/test/etl_test.gleam index d7dd17c4d..c09897212 100644 --- a/exercises/practice/etl/test/etl_test.gleam +++ b/exercises/practice/etl/test/etl_test.gleam @@ -1,4 +1,4 @@ -import gleam/map +import gleam/dict import exercism/test_runner import exercism/should import etl @@ -8,62 +8,62 @@ pub fn main() { } pub fn single_letter_test() { - etl.transform(map.from_list([#(1, ["A"])])) - |> should.equal(map.from_list([#("a", 1)])) + etl.transform(dict.from_list([#(1, ["A"])])) + |> should.equal(dict.from_list([#("a", 1)])) } pub fn single_score_with_multiple_letters_test() { - etl.transform(map.from_list([#(1, ["A", "E", "I", "O", "U"])])) - |> should.equal(map.from_list([ - #("a", 1), - #("e", 1), - #("i", 1), - #("o", 1), - #("u", 1), - ])) + etl.transform(dict.from_list([#(1, ["A", "E", "I", "O", "U"])])) + |> should.equal( + dict.from_list([#("a", 1), #("e", 1), #("i", 1), #("o", 1), #("u", 1)]), + ) } pub fn multiple_scores_with_multiple_letters_test() { - etl.transform(map.from_list([#(1, ["A", "E"]), #(2, ["D", "G"])])) - |> should.equal(map.from_list([#("a", 1), #("d", 2), #("e", 1), #("g", 2)])) + etl.transform(dict.from_list([#(1, ["A", "E"]), #(2, ["D", "G"])])) + |> should.equal(dict.from_list([#("a", 1), #("d", 2), #("e", 1), #("g", 2)])) } pub fn multiple_scores_with_differing_numbers_of_letters_test() { - etl.transform(map.from_list([ - #(1, ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"]), - #(10, ["Q", "Z"]), - #(2, ["D", "G"]), - #(3, ["B", "C", "M", "P"]), - #(4, ["F", "H", "V", "W", "Y"]), - #(5, ["K"]), - #(8, ["J", "X"]), - ])) - |> should.equal(map.from_list([ - #("a", 1), - #("b", 3), - #("c", 3), - #("d", 2), - #("e", 1), - #("f", 4), - #("g", 2), - #("h", 4), - #("i", 1), - #("j", 8), - #("k", 5), - #("l", 1), - #("m", 3), - #("n", 1), - #("o", 1), - #("p", 3), - #("q", 10), - #("r", 1), - #("s", 1), - #("t", 1), - #("u", 1), - #("v", 4), - #("w", 4), - #("x", 8), - #("y", 4), - #("z", 10), - ])) + etl.transform( + dict.from_list([ + #(1, ["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"]), + #(10, ["Q", "Z"]), + #(2, ["D", "G"]), + #(3, ["B", "C", "M", "P"]), + #(4, ["F", "H", "V", "W", "Y"]), + #(5, ["K"]), + #(8, ["J", "X"]), + ]), + ) + |> should.equal( + dict.from_list([ + #("a", 1), + #("b", 3), + #("c", 3), + #("d", 2), + #("e", 1), + #("f", 4), + #("g", 2), + #("h", 4), + #("i", 1), + #("j", 8), + #("k", 5), + #("l", 1), + #("m", 3), + #("n", 1), + #("o", 1), + #("p", 3), + #("q", 10), + #("r", 1), + #("s", 1), + #("t", 1), + #("u", 1), + #("v", 4), + #("w", 4), + #("x", 8), + #("y", 4), + #("z", 10), + ]), + ) } diff --git a/exercises/practice/house/src/house.gleam b/exercises/practice/house/src/house.gleam index 954837cc9..04ec52640 100644 --- a/exercises/practice/house/src/house.gleam +++ b/exercises/practice/house/src/house.gleam @@ -1,3 +1,6 @@ -pub fn recite(start_verse start_verse: Int, end_verse end_verse: Int) -> String { +pub fn recite( + start_verse start_verse: Int, + end_verse end_verse: Int, +) -> String { todo } diff --git a/exercises/practice/nucleotide-count/src/nucleotide_count.gleam b/exercises/practice/nucleotide-count/src/nucleotide_count.gleam index 34e5e09dd..c3b7bb244 100644 --- a/exercises/practice/nucleotide-count/src/nucleotide_count.gleam +++ b/exercises/practice/nucleotide-count/src/nucleotide_count.gleam @@ -1,4 +1,4 @@ -import gleam/map.{type Map} +import gleam/dict.{type Dict} pub fn nucleotide_count(dna: String) -> Result(Map(String, Int), Nil) { todo diff --git a/exercises/practice/nucleotide-count/test/nucleotide_count_test.gleam b/exercises/practice/nucleotide-count/test/nucleotide_count_test.gleam index 3235bec81..d8edc8e89 100644 --- a/exercises/practice/nucleotide-count/test/nucleotide_count_test.gleam +++ b/exercises/practice/nucleotide-count/test/nucleotide_count_test.gleam @@ -1,4 +1,4 @@ -import gleam/map +import gleam/dict import exercism/test_runner import exercism/should import nucleotide_count @@ -11,7 +11,7 @@ pub fn empty_strand_test() { let strand = "" let expected = [#("A", 0), #("C", 0), #("G", 0), #("T", 0)] - |> map.from_list + |> dict.from_list |> Ok nucleotide_count.nucleotide_count(strand) |> should.equal(expected) @@ -21,7 +21,7 @@ pub fn can_count_one_nucleotide_in_single_character_input_test() { let strand = "G" let expected = [#("A", 0), #("C", 0), #("G", 1), #("T", 0)] - |> map.from_list + |> dict.from_list |> Ok nucleotide_count.nucleotide_count(strand) |> should.equal(expected) @@ -31,7 +31,7 @@ pub fn strand_with_repeated_nucleotide_test() { let strand = "GGGGGGG" let expected = [#("A", 0), #("C", 0), #("G", 7), #("T", 0)] - |> map.from_list + |> dict.from_list |> Ok nucleotide_count.nucleotide_count(strand) |> should.equal(expected) @@ -42,7 +42,7 @@ pub fn strand_with_multiple_nucleotides_test() { "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC" let expected = [#("A", 20), #("C", 12), #("G", 17), #("T", 21)] - |> map.from_list + |> dict.from_list |> Ok nucleotide_count.nucleotide_count(strand) |> should.equal(expected) diff --git a/exercises/practice/pov/test/pov_test.gleam b/exercises/practice/pov/test/pov_test.gleam index 58c48bd11..add8374a2 100644 --- a/exercises/practice/pov/test/pov_test.gleam +++ b/exercises/practice/pov/test/pov_test.gleam @@ -20,129 +20,117 @@ pub fn reroot_a_tree_so_that_its_root_is_the_specified_node_can_reroot_a_tree_wi "x", ) |> result.map(normalize) - |> should.equal(Ok(Tree( - label: "x", - children: [Tree(label: "parent", children: [Tree("sibling", [])])], - ))) + |> should.equal( + Ok( + Tree(label: "x", children: [ + Tree(label: "parent", children: [Tree("sibling", [])]), + ]), + ), + ) } pub fn reroot_a_tree_so_that_its_root_is_the_specified_node_can_reroot_a_tree_with_a_parent_and_many_siblings_test() { pov.from_pov( - Tree( - label: "parent", - children: [Tree("a", []), Tree("b", []), Tree("c", []), Tree("x", [])], - ), + Tree(label: "parent", children: [ + Tree("a", []), + Tree("b", []), + Tree("c", []), + Tree("x", []), + ]), "x", ) |> result.map(normalize) - |> should.equal(Ok(Tree( - label: "x", - children: [ - Tree( - label: "parent", - children: [Tree("a", []), Tree("b", []), Tree("c", [])], - ), - ], - ))) + |> should.equal( + Ok( + Tree(label: "x", children: [ + Tree(label: "parent", children: [ + Tree("a", []), + Tree("b", []), + Tree("c", []), + ]), + ]), + ), + ) } pub fn reroot_a_tree_so_that_its_root_is_the_specified_node_can_reroot_a_tree_with_new_root_deeply_nested_in_tree_test() { pov.from_pov( - Tree( - label: "level-0", - children: [ - Tree( - label: "level-1", - children: [ - Tree( - label: "level-2", - children: [Tree(label: "level-3", children: [Tree("x", [])])], - ), - ], - ), - ], - ), + Tree(label: "level-0", children: [ + Tree(label: "level-1", children: [ + Tree(label: "level-2", children: [ + Tree(label: "level-3", children: [Tree("x", [])]), + ]), + ]), + ]), "x", ) |> result.map(normalize) - |> should.equal(Ok(Tree( - label: "x", - children: [ - Tree( - label: "level-3", - children: [ - Tree( - label: "level-2", - children: [Tree(label: "level-1", children: [Tree("level-0", [])])], - ), - ], - ), - ], - ))) + |> should.equal( + Ok( + Tree(label: "x", children: [ + Tree(label: "level-3", children: [ + Tree(label: "level-2", children: [ + Tree(label: "level-1", children: [Tree("level-0", [])]), + ]), + ]), + ]), + ), + ) } pub fn reroot_a_tree_so_that_its_root_is_the_specified_node_moves_children_of_the_new_root_to_same_level_as_former_parent_test() { pov.from_pov( - Tree( - label: "parent", - children: [ - Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), - ], - ), + Tree(label: "parent", children: [ + Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), + ]), "x", ) |> result.map(normalize) - |> should.equal(Ok(Tree( - label: "x", - children: [Tree("kid-0", []), Tree("kid-1", []), Tree("parent", [])], - ))) + |> should.equal( + Ok( + Tree(label: "x", children: [ + Tree("kid-0", []), + Tree("kid-1", []), + Tree("parent", []), + ]), + ), + ) } pub fn reroot_a_tree_so_that_its_root_is_the_specified_node_can_reroot_a_complex_tree_with_cousins_test() { pov.from_pov( - Tree( - label: "grandparent", - children: [ - Tree( - label: "parent", - children: [ - Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), - Tree("sibling-0", []), - Tree("sibling-1", []), - ], - ), - Tree( - label: "uncle", - children: [Tree("cousin-0", []), Tree("cousin-1", [])], - ), - ], - ), + Tree(label: "grandparent", children: [ + Tree(label: "parent", children: [ + Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), + Tree("sibling-0", []), + Tree("sibling-1", []), + ]), + Tree(label: "uncle", children: [ + Tree("cousin-0", []), + Tree("cousin-1", []), + ]), + ]), "x", ) |> result.map(normalize) - |> should.equal(Ok(Tree( - label: "x", - children: [ - Tree("kid-0", []), - Tree("kid-1", []), - Tree( - label: "parent", - children: [ - Tree( - label: "grandparent", - children: [ - Tree( - label: "uncle", - children: [Tree("cousin-0", []), Tree("cousin-1", [])], - ), - ], - ), + |> should.equal( + Ok( + Tree(label: "x", children: [ + Tree("kid-0", []), + Tree("kid-1", []), + Tree(label: "parent", children: [ + Tree(label: "grandparent", children: [ + Tree(label: "uncle", children: [ + Tree("cousin-0", []), + Tree("cousin-1", []), + ]), + ]), Tree("sibling-0", []), Tree("sibling-1", []), - ], - ), - ], - ))) + ]), + ]), + ), + ) } pub fn reroot_a_tree_so_that_its_root_is_the_specified_node_errors_if_target_does_not_exist_in_a_singleton_tree_test() { @@ -152,14 +140,11 @@ pub fn reroot_a_tree_so_that_its_root_is_the_specified_node_errors_if_target_doe pub fn reroot_a_tree_so_that_its_root_is_the_specified_node_errors_if_target_does_not_exist_in_a_large_tree_test() { pov.from_pov( - Tree( - label: "parent", - children: [ - Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), - Tree("sibling-0", []), - Tree("sibling-1", []), - ], - ), + Tree(label: "parent", children: [ + Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), + Tree("sibling-0", []), + Tree("sibling-1", []), + ]), "nonexistent", ) |> should.equal(Error(Nil)) @@ -176,10 +161,12 @@ pub fn given_two_nodes_find_the_path_between_them_can_find_path_to_parent_test() pub fn given_two_nodes_find_the_path_between_them_can_find_path_to_sibling_test() { pov.path_to( - tree: Tree( - label: "parent", - children: [Tree("a", []), Tree("x", []), Tree("b", []), Tree("c", [])], - ), + tree: Tree(label: "parent", children: [ + Tree("a", []), + Tree("x", []), + Tree("b", []), + Tree("c", []), + ]), from: "x", to: "b", ) @@ -188,23 +175,17 @@ pub fn given_two_nodes_find_the_path_between_them_can_find_path_to_sibling_test( pub fn given_two_nodes_find_the_path_between_them_can_find_path_to_cousin_test() { pov.path_to( - tree: Tree( - label: "grandparent", - children: [ - Tree( - label: "parent", - children: [ - Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), - Tree("sibling-0", []), - Tree("sibling-1", []), - ], - ), - Tree( - label: "uncle", - children: [Tree("cousin-0", []), Tree("cousin-1", [])], - ), - ], - ), + tree: Tree(label: "grandparent", children: [ + Tree(label: "parent", children: [ + Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), + Tree("sibling-0", []), + Tree("sibling-1", []), + ]), + Tree(label: "uncle", children: [ + Tree("cousin-0", []), + Tree("cousin-1", []), + ]), + ]), from: "x", to: "cousin-1", ) @@ -213,19 +194,13 @@ pub fn given_two_nodes_find_the_path_between_them_can_find_path_to_cousin_test() pub fn given_two_nodes_find_the_path_between_them_can_find_path_not_involving_root_test() { pov.path_to( - tree: Tree( - label: "grandparent", - children: [ - Tree( - label: "parent", - children: [ - Tree("x", []), - Tree("sibling-0", []), - Tree("sibling-1", []), - ], - ), - ], - ), + tree: Tree(label: "grandparent", children: [ + Tree(label: "parent", children: [ + Tree("x", []), + Tree("sibling-0", []), + Tree("sibling-1", []), + ]), + ]), from: "x", to: "sibling-1", ) @@ -234,10 +209,12 @@ pub fn given_two_nodes_find_the_path_between_them_can_find_path_not_involving_ro pub fn given_two_nodes_find_the_path_between_them_can_find_path_from_nodes_other_than_x_test() { pov.path_to( - tree: Tree( - label: "parent", - children: [Tree("a", []), Tree("x", []), Tree("b", []), Tree("c", [])], - ), + tree: Tree(label: "parent", children: [ + Tree("a", []), + Tree("x", []), + Tree("b", []), + Tree("c", []), + ]), from: "a", to: "c", ) @@ -246,14 +223,11 @@ pub fn given_two_nodes_find_the_path_between_them_can_find_path_from_nodes_other pub fn given_two_nodes_find_the_path_between_them_errors_if_destination_does_not_exist_test() { pov.path_to( - tree: Tree( - label: "parent", - children: [ - Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), - Tree("sibling-0", []), - Tree("sibling-1", []), - ], - ), + tree: Tree(label: "parent", children: [ + Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), + Tree("sibling-0", []), + Tree("sibling-1", []), + ]), from: "x", to: "nonexistent", ) @@ -262,14 +236,11 @@ pub fn given_two_nodes_find_the_path_between_them_errors_if_destination_does_not pub fn given_two_nodes_find_the_path_between_them_errors_if_source_does_not_exist_test() { pov.path_to( - tree: Tree( - label: "parent", - children: [ - Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), - Tree("sibling-0", []), - Tree("sibling-1", []), - ], - ), + tree: Tree(label: "parent", children: [ + Tree(label: "x", children: [Tree("kid-0", []), Tree("kid-1", [])]), + Tree("sibling-0", []), + Tree("sibling-1", []), + ]), from: "nonexistent", to: "x", ) diff --git a/exercises/practice/satellite/test/satellite_test.gleam b/exercises/practice/satellite/test/satellite_test.gleam index 24e71ee7b..c3ad06e65 100644 --- a/exercises/practice/satellite/test/satellite_test.gleam +++ b/exercises/practice/satellite/test/satellite_test.gleam @@ -17,19 +17,20 @@ pub fn tree_with_one_item_test() { } pub fn tree_with_many_items_test() { - satellite.tree_from_traversals( - inorder: ["i", "a", "f", "x", "r"], - preorder: ["a", "i", "x", "f", "r"], + satellite.tree_from_traversals(inorder: ["i", "a", "f", "x", "r"], preorder: [ + "a", "i", "x", "f", "r", + ]) + |> should.equal( + Ok(Node( + value: "a", + left: Node(value: "i", left: Nil, right: Nil), + right: Node( + value: "x", + left: Node(value: "f", left: Nil, right: Nil), + right: Node(value: "r", left: Nil, right: Nil), + ), + )), ) - |> should.equal(Ok(Node( - value: "a", - left: Node(value: "i", left: Nil, right: Nil), - right: Node( - value: "x", - left: Node(value: "f", left: Nil, right: Nil), - right: Node(value: "r", left: Nil, right: Nil), - ), - ))) } pub fn reject_traversals_of_different_length_test() { @@ -38,17 +39,15 @@ pub fn reject_traversals_of_different_length_test() { } pub fn reject_inconsistent_traversals_of_same_length_test() { - satellite.tree_from_traversals( - inorder: ["a", "b", "c"], - preorder: ["x", "y", "z"], - ) + satellite.tree_from_traversals(inorder: ["a", "b", "c"], preorder: [ + "x", "y", "z", + ]) |> should.equal(Error(DifferentItems)) } pub fn reject_traversals_with_repeated_items_test() { - satellite.tree_from_traversals( - inorder: ["b", "a", "a"], - preorder: ["a", "b", "a"], - ) + satellite.tree_from_traversals(inorder: ["b", "a", "a"], preorder: [ + "a", "b", "a", + ]) |> should.equal(Error(NonUniqueItems)) } diff --git a/exercises/practice/series/test/series_test.gleam b/exercises/practice/series/test/series_test.gleam index 53dbc65e3..f4cf0861d 100644 --- a/exercises/practice/series/test/series_test.gleam +++ b/exercises/practice/series/test/series_test.gleam @@ -39,9 +39,9 @@ pub fn slices_can_include_duplicates_test() { pub fn slices_of_a_long_series_test() { "918493904243" |> series.slices(5) - |> should.equal(Ok([ - "91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243", - ])) + |> should.equal( + Ok(["91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243"]), + ) } pub fn slice_length_is_too_large_test() { diff --git a/exercises/practice/word-count/src/word_count.gleam b/exercises/practice/word-count/src/word_count.gleam index e2c84a78e..f033899d1 100644 --- a/exercises/practice/word-count/src/word_count.gleam +++ b/exercises/practice/word-count/src/word_count.gleam @@ -1,4 +1,4 @@ -import gleam/map.{type Map} +import gleam/dict.{type Dict} pub fn count_words(input: String) -> Map(String, Int) { todo diff --git a/exercises/practice/word-count/test/word_count_test.gleam b/exercises/practice/word-count/test/word_count_test.gleam index c4f254052..babc4fcd6 100644 --- a/exercises/practice/word-count/test/word_count_test.gleam +++ b/exercises/practice/word-count/test/word_count_test.gleam @@ -1,5 +1,5 @@ import word_count -import gleam/map +import gleam/dict import exercism/test_runner import exercism/should @@ -10,19 +10,19 @@ pub fn main() { pub fn count_one_word_test() { "word" |> word_count.count_words - |> should.equal(map.from_list([#("word", 1)])) + |> should.equal(dict.from_list([#("word", 1)])) } pub fn count_one_of_each_word_test() { "one of each" |> word_count.count_words - |> should.equal(map.from_list([#("one", 1), #("of", 1), #("each", 1)])) + |> should.equal(dict.from_list([#("one", 1), #("of", 1), #("each", 1)])) } pub fn multiple_occurrences_of_a_word_test() { "one fish two fish red fish blue fish" |> word_count.count_words - |> should.equal(map.from_list([ + |> should.equal(dict.from_list([ #("one", 1), #("fish", 4), #("two", 1), @@ -34,19 +34,19 @@ pub fn multiple_occurrences_of_a_word_test() { pub fn handles_cramped_lists_test() { "one,two,three" |> word_count.count_words - |> should.equal(map.from_list([#("one", 1), #("two", 1), #("three", 1)])) + |> should.equal(dict.from_list([#("one", 1), #("two", 1), #("three", 1)])) } pub fn handles_expanded_lists_test() { "one,\ntwo,\nthree" |> word_count.count_words - |> should.equal(map.from_list([#("one", 1), #("two", 1), #("three", 1)])) + |> should.equal(dict.from_list([#("one", 1), #("two", 1), #("three", 1)])) } pub fn ignore_punctuation_test() { "car: carpet as java: javascript!!&@$%^&" |> word_count.count_words - |> should.equal(map.from_list([ + |> should.equal(dict.from_list([ #("car", 1), #("carpet", 1), #("as", 1), @@ -58,19 +58,19 @@ pub fn ignore_punctuation_test() { pub fn include_numbers_test() { "testing, 1, 2 testing" |> word_count.count_words - |> should.equal(map.from_list([#("testing", 2), #("1", 1), #("2", 1)])) + |> should.equal(dict.from_list([#("testing", 2), #("1", 1), #("2", 1)])) } pub fn normalize_case_test() { "go Go GO Stop stop" |> word_count.count_words - |> should.equal(map.from_list([#("go", 3), #("stop", 2)])) + |> should.equal(dict.from_list([#("go", 3), #("stop", 2)])) } pub fn with_apostrophes_test() { "'First: don't laugh. Then: don't cry. You're getting it.'" |> word_count.count_words - |> should.equal(map.from_list([ + |> should.equal(dict.from_list([ #("first", 1), #("don't", 2), #("laugh", 1), @@ -85,7 +85,7 @@ pub fn with_apostrophes_test() { pub fn with_quotations_test() { "Joe can't tell between 'large' and large." |> word_count.count_words - |> should.equal(map.from_list([ + |> should.equal(dict.from_list([ #("joe", 1), #("can't", 1), #("tell", 1), @@ -98,7 +98,7 @@ pub fn with_quotations_test() { pub fn substrings_from_the_beginning_test() { "Joe can't tell between app, apple and a." |> word_count.count_words - |> should.equal(map.from_list([ + |> should.equal(dict.from_list([ #("joe", 1), #("can't", 1), #("tell", 1), @@ -113,17 +113,17 @@ pub fn substrings_from_the_beginning_test() { pub fn multiple_spaces_not_detected_as_a_word_test() { " multiple whitespaces" |> word_count.count_words - |> should.equal(map.from_list([#("multiple", 1), #("whitespaces", 1)])) + |> should.equal(dict.from_list([#("multiple", 1), #("whitespaces", 1)])) } pub fn alternating_word_separators_not_detected_as_a_word_test() { ",\n,one,\n ,two \n 'three'" |> word_count.count_words - |> should.equal(map.from_list([#("one", 1), #("two", 1), #("three", 1)])) + |> should.equal(dict.from_list([#("one", 1), #("two", 1), #("three", 1)])) } pub fn quotation_for_word_with_apostrophe_test() { "can, can't, 'can't'" |> word_count.count_words - |> should.equal(map.from_list([#("can", 1), #("can't", 2)])) + |> should.equal(dict.from_list([#("can", 1), #("can't", 2)])) }