Skip to content

Commit

Permalink
Sync exercise tests
Browse files Browse the repository at this point in the history
We sync the following exercises:
- allergies
- anagram
- collatz-conjecture
- flatten-array
- matching-brackets
- pangram
- phone-number
- roman-numerals
- space-age

With space-age, we exclude the new test as the type system prevents
non-planets from being passed as planets.
  • Loading branch information
keiravillekode committed Dec 20, 2023
1 parent bcc6f8f commit 03688e5
Show file tree
Hide file tree
Showing 19 changed files with 268 additions and 61 deletions.
2 changes: 1 addition & 1 deletion exercises/practice/allergies/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Now, given just that score of 34, your program should be able to say:
- Whether Tom is allergic to any one of those allergens listed above.
- All the allergens Tom is allergic to.

Note: a given score may include allergens **not** listed above (i.e. allergens that score 256, 512, 1024, etc.).
Note: a given score may include allergens **not** listed above (i.e. allergens that score 256, 512, 1024, etc.).
Your program should ignore those components of the score.
For example, if the allergy score is 257, your program should only report the eggs (1) allergy.
3 changes: 3 additions & 0 deletions exercises/practice/allergies/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,6 @@ description = "list when: -> everything"

[12ce86de-b347-42a0-ab7c-2e0570f0c65b]
description = "list when: -> no allergen score parts"

[93c2df3e-4f55-4fed-8116-7513092819cd]
description = "list when: -> no allergen score parts without highest valid score"
7 changes: 5 additions & 2 deletions exercises/practice/allergies/test.sml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* version 1.0.0 *)
(* version 1.1.0 *)

use "testlib.sml";
use "allergies.sml";
Expand Down Expand Up @@ -61,7 +61,10 @@ val testsuite =
(fn _ => allergies (255) |> Expect.equalTo [Eggs, Peanuts, Shellfish, Strawberries, Tomatoes, Chocolate, Pollen, Cats]),

test "ignore non allergen score parts"
(fn _ => allergies (509) |> Expect.equalTo [Eggs, Shellfish, Strawberries, Tomatoes, Chocolate, Pollen, Cats])
(fn _ => allergies (509) |> Expect.equalTo [Eggs, Shellfish, Strawberries, Tomatoes, Chocolate, Pollen, Cats]),

test "no allergen score parts without highest valid score"
(fn _ => allergies (257) |> Expect.equalTo [Eggs])
]
]

Expand Down
24 changes: 24 additions & 0 deletions exercises/practice/anagram/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ description = "no matches"

[b3cca662-f50a-489e-ae10-ab8290a09bdc]
description = "detects two anagrams"
include = false

[03eb9bbe-8906-4ea0-84fa-ffe711b52c8b]
description = "detects two anagrams"
Expand Down Expand Up @@ -45,12 +46,35 @@ description = "detects anagrams using case-insensitive possible matches"

[7cc195ad-e3c7-44ee-9fd2-d3c344806a2c]
description = "does not detect an anagram if the original word is repeated"
include = false

[630abb71-a94e-4715-8395-179ec1df9f91]
description = "does not detect an anagram if the original word is repeated"
reimplements = "7cc195ad-e3c7-44ee-9fd2-d3c344806a2c"

[9878a1c9-d6ea-4235-ae51-3ea2befd6842]
description = "anagrams must use all letters exactly once"

[85757361-4535-45fd-ac0e-3810d40debc1]
description = "words are not anagrams of themselves (case-insensitive)"
include = false

[68934ed0-010b-4ef9-857a-20c9012d1ebf]
description = "words are not anagrams of themselves"
reimplements = "85757361-4535-45fd-ac0e-3810d40debc1"

[589384f3-4c8a-4e7d-9edc-51c3e5f0c90e]
description = "words are not anagrams of themselves even if letter case is partially different"
reimplements = "85757361-4535-45fd-ac0e-3810d40debc1"

[ba53e423-7e02-41ee-9ae2-71f91e6d18e6]
description = "words are not anagrams of themselves even if letter case is completely different"
reimplements = "85757361-4535-45fd-ac0e-3810d40debc1"

[a0705568-628c-4b55-9798-82e4acde51ca]
description = "words other than themselves can be anagrams"
include = false

[33d3f67e-fbb9-49d3-a90e-0beb00861da7]
description = "words other than themselves can be anagrams"
reimplements = "a0705568-628c-4b55-9798-82e4acde51ca"
31 changes: 17 additions & 14 deletions exercises/practice/anagram/test.sml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* version 1.4.0 *)
(* version 1.5.0 *)

use "testlib.sml";
use "anagram.sml";
Expand All @@ -11,14 +11,8 @@ val testsuite =
test "no matches"
(fn _ => anagramsFor "diaper" ["hello", "world", "zombies", "pants"] |> Expect.equalTo []),

test "detects simple anagram"
(fn _ => anagramsFor "ant" ["tan", "stand", "at"] |> Expect.equalTo ["tan"]),

test "does not detect false positives"
(fn _ => anagramsFor "galea" ["eagle"] |> Expect.equalTo []),

test "detects two anagrams"
(fn _ => anagramsFor "master" ["stream", "pigeon", "maters"] |> Expect.equalTo ["stream", "maters"]),
(fn _ => anagramsFor "solemn" ["lemons", "cherry", "melons"] |> Expect.equalTo ["lemons", "melons"]),

test "does not detect anagram subsets"
(fn _ => anagramsFor "good" ["dog", "goody"] |> Expect.equalTo []),
Expand All @@ -29,8 +23,8 @@ val testsuite =
test "detects three anagrams"
(fn _ => anagramsFor "allergy" ["gallery", "ballerina", "regally", "clergy", "largely", "leading"] |> Expect.equalTo ["gallery", "regally", "largely"]),

test "does not detect identical words"
(fn _ => anagramsFor "corn" ["corn", "dark", "Corn", "rank", "CORN", "cron", "park"] |> Expect.equalTo ["cron"]),
test "detects multiple anagrams with different case"
(fn _ => anagramsFor "nose" ["Eons", "ONES"] |> Expect.equalTo ["Eons", "ONES"]),

test "does not detect non-anagrams with identical checksum"
(fn _ => anagramsFor "mass" ["last"] |> Expect.equalTo []),
Expand All @@ -44,14 +38,23 @@ val testsuite =
test "detects anagrams using case-insensitive possible matches"
(fn _ => anagramsFor "orchestra" ["cashregister", "Carthorse", "radishes"] |> Expect.equalTo ["Carthorse"]),

test "does not detect a anagram if the original word is repeated"
(fn _ => anagramsFor "go" ["go Go GO"] |> Expect.equalTo []),
test "does not detect an anagram if the original word is repeated"
(fn _ => anagramsFor "go" ["goGoGO"] |> Expect.equalTo []),

test "anagrams must use all letters exactly once"
(fn _ => anagramsFor "tapper" ["patter"] |> Expect.equalTo []),

test "words are not anagrams of themselves (case-insensitive)"
(fn _ => anagramsFor "BANANA" ["BANANA", "Banana", "banana"] |> Expect.equalTo [])
test "words are not anagrams of themselves"
(fn _ => anagramsFor "BANANA" ["BANANA"] |> Expect.equalTo []),

test "words are not anagrams of themselves even if letter case is partially different"
(fn _ => anagramsFor "BANANA" ["Banana"] |> Expect.equalTo []),

test "words are not anagrams of themselves even if letter case is completely different"
(fn _ => anagramsFor "BANANA" ["banana"] |> Expect.equalTo []),

test "words other than themselves can be anagrams"
(fn _ => anagramsFor "LISTEN" ["LISTEN", "Silent"] |> Expect.equalTo ["Silent"])
]

val _ = Test.run testsuite
10 changes: 10 additions & 0 deletions exercises/practice/collatz-conjecture/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ description = "large number of even and odd steps"

[7d4750e6-def9-4b86-aec7-9f7eb44f95a3]
description = "zero is an error"
include = false

[2187673d-77d6-4543-975e-66df6c50e2da]
description = "zero is an error"
reimplements = "7d4750e6-def9-4b86-aec7-9f7eb44f95a3"

[c6c795bf-a288-45e9-86a1-841359ad426d]
description = "negative value is an error"
include = false

[ec11f479-56bc-47fd-a434-bcd7a31a7a2e]
description = "negative value is an error"
reimplements = "c6c795bf-a288-45e9-86a1-841359ad426d"
15 changes: 15 additions & 0 deletions exercises/practice/flatten-array/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[8c71dabd-da60-422d-a290-4a571471fb14]
description = "empty"

[d268b919-963c-442d-9f07-82b93f1b518c]
description = "no nesting"

[3f15bede-c856-479e-bb71-1684b20c6a30]
description = "flattens a nested array"

[c84440cc-bb3a-48a6-862c-94cf23f2815d]
description = "flattens array with just integers present"

Expand All @@ -21,6 +27,15 @@ description = "5 level nesting"
[d572bdba-c127-43ed-bdcd-6222ac83d9f7]
description = "6 level nesting"

[0705a8e5-dc86-4cec-8909-150c5e54fa9c]
description = "null values are omitted from the final result"

[c6cf26de-8ccd-4410-84bd-b9efd88fd2bc]
description = "consecutive null values at the front of the list are omitted from the final result"

[382c5242-587e-4577-b8ce-a5fb51e385a1]
description = "consecutive null values in the middle of the list are omitted from the final result"

[ef1d4790-1b1e-4939-a179-51ace0829dbd]
description = "6 level nest list with null values"

Expand Down
37 changes: 36 additions & 1 deletion exercises/practice/flatten-array/test.sml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* version 1.1.0 *)
(* version 1.2.0 *)

use "testlib.sml";
use "flatten-array.sml";
Expand All @@ -8,13 +8,27 @@ fun x |> f = f x

val testsuite =
describe "flatten-array" [
test "empty"
(fn _ => let
val nested = List []
in
flatten nested |> Expect.equalTo []
end),

test "no nesting"
(fn _ => let
val nested = List [Elem 0, Elem 1, Elem 2]
in
flatten nested |> Expect.equalTo [0, 1, 2]
end),

test "flattens a nested array"
(fn _ => let
val nested = List [List [List []]]
in
flatten nested |> Expect.equalTo []
end),

test "flattens array with just integers present"
(fn _ => let
val nested = List [Elem 1,
Expand Down Expand Up @@ -51,6 +65,27 @@ val testsuite =
flatten nested |> Expect.equalTo [1, 2, 3, 4, 5, 6, 7, 8]
end),

test "Empty values are omitted from the final result"
(fn _ => let
val nested = List [Elem 1, Elem 2, Empty]
in
flatten nested |> Expect.equalTo [1, 2]
end),

test "consecutive Empty values at the front of the list are omitted from the final result"
(fn _ => let
val nested = List [Empty, Empty, Elem 3]
in
flatten nested |> Expect.equalTo [3]
end),

test "consecutive Empty values in the middle of the list are omitted from the final result"
(fn _ => let
val nested = List [Elem 1, Empty, Empty, Elem 4]
in
flatten nested |> Expect.equalTo [1, 4]
end),

test "6 level nest list with Empty values"
(fn _ => let
val nested = List [Elem 0,
Expand Down
9 changes: 9 additions & 0 deletions exercises/practice/matching-brackets/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ description = "unpaired and nested brackets"
[a0205e34-c2ac-49e6-a88a-899508d7d68e]
description = "paired and wrong nested brackets"

[1d5c093f-fc84-41fb-8c2a-e052f9581602]
description = "paired and wrong nested brackets but innermost are correct"

[ef47c21b-bcfd-4998-844c-7ad5daad90a8]
description = "paired and incomplete brackets"

[a4675a40-a8be-4fc2-bc47-2a282ce6edbe]
description = "too many closing brackets"

[a345a753-d889-4b7e-99ae-34ac85910d1a]
description = "early unexpected brackets"

[21f81d61-1608-465a-b850-baa44c5def83]
description = "early mismatched brackets"

[99255f93-261b-4435-a352-02bdecc9bdf2]
description = "math expression"

Expand Down
10 changes: 9 additions & 1 deletion exercises/practice/matching-brackets/test.sml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* version 1.4.0 *)
(* version 1.5.0 *)

use "testlib.sml";
use "matching-brackets.sml";
Expand Down Expand Up @@ -34,8 +34,16 @@ val testsuite =
(fn _ => isBalanced "([{])" |> Expect.falsy),
test "paired and wrong nested brackets"
(fn _ => isBalanced "[({]})" |> Expect.falsy),
test "paired and wrong nested brackets but innermost are correct"
(fn _ => isBalanced "[({}])" |> Expect.falsy),
test "paired and incomplete brackets"
(fn _ => isBalanced "{}[" |> Expect.falsy),
test "too many closing brackets"
(fn _ => isBalanced "[]]" |> Expect.falsy),
test "early unexpected brackets"
(fn _ => isBalanced ")()" |> Expect.falsy),
test "early mismatched brackets"
(fn _ => isBalanced "{)()" |> Expect.falsy),
test "math expression"
(fn _ => isBalanced "(((185 + 223.85) * 15) - 543)/2" |> Expect.truthy),
test "complex latex expression"
Expand Down
5 changes: 5 additions & 0 deletions exercises/practice/pangram/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ description = "mixed case and punctuation"

[2577bf54-83c8-402d-a64b-a2c0f7bb213a]
description = "case insensitive"
include = false

[7138e389-83e4-4c6e-8413-1e40a0076951]
description = "a-m and A-M are 26 different characters but not a pangram"
reimplements = "2577bf54-83c8-402d-a64b-a2c0f7bb213a"
25 changes: 14 additions & 11 deletions exercises/practice/pangram/test.sml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* version 1.1.0 *)
(* version 1.2.0 *)

use "pangram.sml";
use "testlib.sml";
Expand All @@ -9,32 +9,35 @@ fun x |> f = f x
val testsuite =
describe "pangram" [
describe "Check if the given string is an pangram" [
test "sentence empty"
test "empty sentence"
(fn _ => isPangram ("") |> Expect.falsy),

test "pangram with only lower case"
test "perfect lower case"
(fn _ => isPangram ("abcdefghijklmnopqrstuvwxyz") |> Expect.truthy),

test "only lower case"
(fn _ => isPangram ("the quick brown fox jumps over the lazy dog") |> Expect.truthy),

test "missing character 'x'"
test "missing the letter 'x'"
(fn _ => isPangram ("a quick movement of the enemy will jeopardize five gunboats") |> Expect.falsy),

test "another missing character 'x'"
(fn _ => isPangram ("the quick brown fish jumps over the lazy dog") |> Expect.falsy),
test "missing the letter 'h'"
(fn _ => isPangram ("five boxing wizards jump quickly at it") |> Expect.falsy),

test "pangram with underscores"
test "with underscores"
(fn _ => isPangram ("the_quick_brown_fox_jumps_over_the_lazy_dog") |> Expect.truthy),

test "pangram with numbers"
test "with numbers"
(fn _ => isPangram ("the 1 quick brown fox jumps over the 2 lazy dogs") |> Expect.truthy),

test "missing letters replaced by numbers"
(fn _ => isPangram ("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog") |> Expect.falsy),

test "pangram with mixed case and punctuation"
test "mixed case and punctuation"
(fn _ => isPangram ("\"Five quacking Zephyrs jolt my wax bed.\"") |> Expect.truthy),

test "upper and lower case versions of the same character should not be counted separately"
(fn _ => isPangram ("the quick brown fox jumps over with lazy FX") |> Expect.falsy)
test "a-m and A-M are 26 different characters but not a pangram"
(fn _ => isPangram ("abcdefghijklm ABCDEFGHIJKLM") |> Expect.falsy)
]
]

Expand Down
10 changes: 6 additions & 4 deletions exercises/practice/phone-number/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ Clean up user-entered phone numbers so that they can be sent SMS messages.
The **North American Numbering Plan (NANP)** is a telephone numbering system used by many countries in North America like the United States, Canada or Bermuda.
All NANP-countries share the same international country code: `1`.

NANP numbers are ten-digit numbers consisting of a three-digit Numbering Plan Area code, commonly known as *area code*, followed by a seven-digit local number.
The first three digits of the local number represent the *exchange code*, followed by the unique four-digit number which is the *subscriber number*.
NANP numbers are ten-digit numbers consisting of a three-digit Numbering Plan Area code, commonly known as _area code_, followed by a seven-digit local number.
The first three digits of the local number represent the _exchange code_, followed by the unique four-digit number which is the _subscriber number_.

The format is usually represented as

```text
(NXX)-NXX-XXXX
NXX NXX-XXXX
```

where `N` is any digit from 2 through 9 and `X` is any digit from 0 through 9.

Your task is to clean up differently formatted telephone numbers by removing punctuation and the country code (1) if present.
Sometimes they also have the country code (represented as `1` or `+1`) prefixed.

Your task is to clean up differently formatted telephone numbers by removing punctuation and the country code if present.

For example, the inputs

Expand Down
Loading

0 comments on commit 03688e5

Please sign in to comment.