Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allergies: add missing tests from problem spec #671

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exercises/practice/allergies/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
],
"contributors": [
"edgerunner",
"kahgoh",
"nathanielknight",
"parkerl",
"tuxagon"
Expand Down
303 changes: 263 additions & 40 deletions exercises/practice/allergies/tests/Tests.elm
Original file line number Diff line number Diff line change
@@ -1,60 +1,283 @@
module Tests exposing (tests)

import Allergies exposing (Allergy(..), isAllergicTo, toList)
import Allergies exposing (Allergy(..))
import Expect
import List
import Test exposing (..)
import Test exposing (Test, describe, skip, test)


tests : Test
tests =
describe "Allergies"
[ describe "isAllergicTo"
[ describe "no allergies means not allergic"
[ test "peanuts" <|
\() -> Expect.equal False (isAllergicTo Peanuts 0)
, skip <|
test "cats" <|
\() -> Expect.equal False (isAllergicTo Cats 0)
, skip <|
test "strawberries" <|
\() -> Expect.equal False (isAllergicTo Strawberries 0)
]
, skip <|
test "is allergic to eggs" <|
\() -> Expect.equal True (isAllergicTo Eggs 1)
, describe "has the right allergies"
[ skip <|
test "eggs" <|
\() -> Expect.equal True (isAllergicTo Eggs 5)
, skip <|
test "shellfish" <|
\() -> Expect.equal True (isAllergicTo Shellfish 5)
, skip <|
test "strawberries" <|
\() -> Expect.equal False (isAllergicTo Strawberries 5)
]
[ describe "testing for eggs allergy"
[ test "not allergic to anything" <|
\() ->
Allergies.isAllergicTo Eggs 0
|> Expect.equal False
, skip <|
test "allergic only to eggs" <|
\() ->
Allergies.isAllergicTo Eggs 1
|> Expect.equal True
, skip <|
test "allergic to eggs and something else" <|
\() ->
Allergies.isAllergicTo Eggs 3
|> Expect.equal True
, skip <|
test "allergic to something, but not eggs" <|
\() ->
Allergies.isAllergicTo Eggs 2
|> Expect.equal False
, skip <|
test "allergic to everything" <|
\() ->
Allergies.isAllergicTo Eggs 255
|> Expect.equal True
]
, describe "toList"
, describe "testing for peanuts allergy"
[ skip <|
test "no allergies at all" <|
\() -> Expect.equal [] (toList 0)
test "not allergic to anything" <|
\() ->
Allergies.isAllergicTo Peanuts 0
|> Expect.equal False
, skip <|
test "allergic to just peanuts" <|
\() -> Expect.equal [ Peanuts ] (toList 2)
test "allergic only to peanuts" <|
\() ->
Allergies.isAllergicTo Peanuts 2
|> Expect.equal True
, skip <|
test "allergic to peanuts and something else" <|
\() ->
Allergies.isAllergicTo Peanuts 7
|> Expect.equal True
, skip <|
test "allergic to something, but not peanuts" <|
\() ->
Allergies.isAllergicTo Peanuts 5
|> Expect.equal False
, skip <|
test "allergic to everything" <|
\() ->
Expect.equal (allergySort [ Eggs, Peanuts, Shellfish, Strawberries, Tomatoes, Chocolate, Pollen, Cats ])
(255 |> toList |> allergySort)
Allergies.isAllergicTo Peanuts 255
|> Expect.equal True
]
, describe "testing for shellfish allergy"
[ skip <|
test "not allergic to anything" <|
\() ->
Allergies.isAllergicTo Shellfish 0
|> Expect.equal False
, skip <|
test "ignore non allergen score parts" <|
\() -> Expect.equal [ Eggs ] (toList 257)
test "allergic only to shellfish" <|
\() ->
Allergies.isAllergicTo Shellfish 4
|> Expect.equal True
, skip <|
test "allergic to shellfish and something else" <|
\() ->
Allergies.isAllergicTo Shellfish 14
|> Expect.equal True
, skip <|
test "allergic to something, but not shellfish" <|
\() ->
Allergies.isAllergicTo Shellfish 10
|> Expect.equal False
, skip <|
test "allergic to everything" <|
\() ->
Allergies.isAllergicTo Shellfish 255
|> Expect.equal True
]
, describe "testing for strawberries allergy"
[ skip <|
test "not allergic to anything" <|
\() ->
Allergies.isAllergicTo Strawberries 0
|> Expect.equal False
, skip <|
test "allergic only to strawberries" <|
\() ->
Allergies.isAllergicTo Strawberries 8
|> Expect.equal True
, skip <|
test "allergic to strawberries and something else" <|
\() ->
Allergies.isAllergicTo Strawberries 28
|> Expect.equal True
, skip <|
test "allergic to something, but not strawberries" <|
\() ->
Allergies.isAllergicTo Strawberries 20
|> Expect.equal False
, skip <|
test "allergic to everything" <|
\() ->
Allergies.isAllergicTo Strawberries 255
|> Expect.equal True
]
, describe "testing for tomatoes allergy"
[ skip <|
test "not allergic to anything" <|
\() ->
Allergies.isAllergicTo Tomatoes 0
|> Expect.equal False
, skip <|
test "allergic only to tomatoes" <|
\() ->
Allergies.isAllergicTo Tomatoes 16
|> Expect.equal True
, skip <|
test "allergic to tomatoes and something else" <|
\() ->
Allergies.isAllergicTo Tomatoes 56
|> Expect.equal True
, skip <|
test "allergic to something, but not tomatoes" <|
\() ->
Allergies.isAllergicTo Tomatoes 40
|> Expect.equal False
, skip <|
test "allergic to everything" <|
\() ->
Allergies.isAllergicTo Tomatoes 255
|> Expect.equal True
]
, describe "testing for chocolate allergy"
[ skip <|
test "not allergic to anything" <|
\() ->
Allergies.isAllergicTo Chocolate 0
|> Expect.equal False
, skip <|
test "allergic only to chocolate" <|
\() ->
Allergies.isAllergicTo Chocolate 32
|> Expect.equal True
, skip <|
test "allergic to chocolate and something else" <|
\() ->
Allergies.isAllergicTo Chocolate 112
|> Expect.equal True
, skip <|
test "allergic to something, but not chocolate" <|
\() ->
Allergies.isAllergicTo Chocolate 80
|> Expect.equal False
, skip <|
test "allergic to everything" <|
\() ->
Allergies.isAllergicTo Chocolate 255
|> Expect.equal True
]
, describe "testing for pollen allergy"
[ skip <|
test "not allergic to anything" <|
\() ->
Allergies.isAllergicTo Pollen 0
|> Expect.equal False
, skip <|
test "allergic only to pollen" <|
\() ->
Allergies.isAllergicTo Pollen 64
|> Expect.equal True
, skip <|
test "allergic to pollen and something else" <|
\() ->
Allergies.isAllergicTo Pollen 224
|> Expect.equal True
, skip <|
test "allergic to something, but not pollen" <|
\() ->
Allergies.isAllergicTo Pollen 160
|> Expect.equal False
, skip <|
test "allergic to everything" <|
\() ->
Allergies.isAllergicTo Pollen 255
|> Expect.equal True
]
, describe "testing for cats allergy"
[ skip <|
test "not allergic to anything" <|
\() ->
Allergies.isAllergicTo Cats 0
|> Expect.equal False
, skip <|
test "allergic only to cats" <|
\() ->
Allergies.isAllergicTo Cats 128
|> Expect.equal True
, skip <|
test "allergic to cats and something else" <|
\() ->
Allergies.isAllergicTo Cats 192
|> Expect.equal True
, skip <|
test "allergic to something, but not cats" <|
\() ->
Allergies.isAllergicTo Cats 64
|> Expect.equal False
, skip <|
test "allergic to everything" <|
\() ->
Allergies.isAllergicTo Cats 255
|> Expect.equal True
]
, describe "list when:"
[ skip <|
test "no allergies" <|
\() ->
Allergies.toList 0
|> Expect.equal []
, skip <|
test "just eggs" <|
\() ->
Allergies.toList 1
|> Expect.equal [ Eggs ]
, skip <|
test "just peanuts" <|
\() ->
Allergies.toList 2
|> Expect.equal [ Peanuts ]
, skip <|
test "just strawberries" <|
\() ->
Allergies.toList 8
|> Expect.equal [ Strawberries ]
, skip <|
test "eggs and peanuts" <|
\() ->
Allergies.toList 3
|> allergySort
|> Expect.equal (allergySort [ Eggs, Peanuts ])
, skip <|
test "more than eggs but not peanuts" <|
\() ->
Allergies.toList 5
|> allergySort
|> Expect.equal (allergySort [ Eggs, Shellfish ])
, skip <|
test "lots of stuff" <|
\() ->
Allergies.toList 248
|> allergySort
|> Expect.equal (allergySort [ Strawberries, Tomatoes, Chocolate, Pollen, Cats ])
, skip <|
test "everything" <|
\() ->
Allergies.toList 255
|> allergySort
|> Expect.equal (allergySort [ Eggs, Peanuts, Shellfish, Strawberries, Tomatoes, Chocolate, Pollen, Cats ])
, skip <|
test "no allergen score parts" <|
\() ->
Allergies.toList 509
|> Expect.equal [ Eggs, Shellfish, Strawberries, Tomatoes, Chocolate, Pollen, Cats ]
, skip <|
test "ignore all non allergen score parts" <|
test "no allergen score parts without highest valid score" <|
\() ->
Expect.equal (allergySort [ Eggs, Shellfish, Strawberries, Tomatoes, Chocolate, Pollen, Cats ])
(509 |> toList |> allergySort)
Allergies.toList 257
|> Expect.equal [ Eggs ]
]
]

Expand Down