Run pre Elm 0.17 exercises through elm-format version 0.3.0-alpha

This commit is contained in:
Erik Simmler 2016-06-19 17:46:13 -04:00
parent 65db27e7e0
commit 91aaf056a1
49 changed files with 1178 additions and 1469 deletions

View file

@ -12,19 +12,14 @@ square x =
tests : Test
tests =
suite
"Accumulate"
[ test
"[]] Accumulate"
suite "Accumulate"
[ test "[]] Accumulate"
(assertEqual [] (accumulate square []))
, test
"square Accumulate"
, test "square Accumulate"
(assertEqual [ 1, 4, 9 ] (accumulate square [ 1, 2, 3 ]))
, test
"toUpper Accumulate"
, test "toUpper Accumulate"
(assertEqual [ "HELLO", "WORLD" ] (accumulate String.toUpper [ "hello", "world" ]))
, test
"reverse Accumulate"
, test "reverse Accumulate"
(assertEqual [ "olleh", "dlrow" ] (accumulate String.reverse [ "hello", "world" ]))
]

View file

@ -7,59 +7,40 @@ import List
tests : Test
tests =
suite
"Allergies"
[ suite
"isAllergicTo"
[ suite
"no allergies means not allergic"
[ test
"peanuts"
suite "Allergies"
[ suite "isAllergicTo"
[ suite "no allergies means not allergic"
[ test "peanuts"
(assert (not (isAllergicTo "peanuts" 0)))
, test
"cats"
, test "cats"
(assert (not (isAllergicTo "cats" 0)))
, test
"strawberries"
, test "strawberries"
(assert (not (isAllergicTo "strawberries" 0)))
]
, test
"is allergic to eggs"
, test "is allergic to eggs"
(assert (isAllergicTo "eggs" 1))
, suite
"has the right allergies"
[ test
"eggs"
, suite "has the right allergies"
[ test "eggs"
(assert (isAllergicTo "eggs" 5))
, test
"shellfish"
, test "shellfish"
(assert (isAllergicTo "shellfish" 5))
, test
"strawberries"
, test "strawberries"
(assert (not (isAllergicTo "strawberries" 5)))
]
]
, suite
"toList"
[ test
"no allergies at all"
, suite "toList"
[ test "no allergies at all"
(assertEqual [] (toList (0)))
, test
"allergic to just peanuts"
, test "allergic to just peanuts"
(assertEqual [ "peanuts" ] (toList (2)))
, test
"allergic to everything"
(assertEqual
(List.sort [ "eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats" ])
, test "allergic to everything"
(assertEqual (List.sort [ "eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats" ])
(255 |> toList |> List.sort)
)
, test
"ignore non allergen score parts"
, test "ignore non allergen score parts"
(assertEqual [ "eggs" ] (toList 257))
, test
"ignore non allergen score parts"
(assertEqual
(List.sort [ "eggs", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats" ])
, test "ignore non allergen score parts"
(assertEqual (List.sort [ "eggs", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats" ])
(509 |> toList |> List.sort)
)
]

View file

@ -6,126 +6,85 @@ import Anagram exposing (detect)
tests : Test
tests =
suite
"Anagram"
[ test
"no matches"
(assertEqual
[]
suite "Anagram"
[ test "no matches"
(assertEqual []
(detect "diaper" [ "hello", "world", "zombies", "pants" ])
)
, test
"detects simple anagram"
(assertEqual
[ "tan" ]
, test "detects simple anagram"
(assertEqual [ "tan" ]
(detect "ant" [ "tan", "stand", "at" ])
)
, test
"does not detect false positives"
(assertEqual
[]
, test "does not detect false positives"
(assertEqual []
(detect "galea" [ "eagle" ])
)
, test
"detects multiple anagrams"
(assertEqual
[ "stream", "maters" ]
, test "detects multiple anagrams"
(assertEqual [ "stream", "maters" ]
(detect "master" [ "stream", "pigeon", "maters" ])
)
, test
"does not detect anagram subsets"
(assertEqual
[]
, test "does not detect anagram subsets"
(assertEqual []
(detect "good" [ "dog", "goody" ])
)
, test
"detects anagram"
(assertEqual
[ "inlets" ]
, test "detects anagram"
(assertEqual [ "inlets" ]
(detect "listen" [ "enlists", "google", "inlets", "banana" ])
)
, test
"detects multiple anagrams"
(assertEqual
[ "gallery", "regally", "largely" ]
, test "detects multiple anagrams"
(assertEqual [ "gallery", "regally", "largely" ]
(detect "allergy" [ "gallery", "ballerina", "regally", "clergy", "largely", "leading" ])
)
, test
"does not detect indentical words"
(assertEqual
[ "cron" ]
, test "does not detect indentical words"
(assertEqual [ "cron" ]
(detect "corn" [ "corn", "dark", "Corn", "rank", "CORN", "cron", "park" ])
)
, test
"does not detect non-anagrams with identical checksum"
(assertEqual
[]
, test "does not detect non-anagrams with identical checksum"
(assertEqual []
(detect "mass" [ "last" ])
)
, test
"detects anagrams case-insensitively"
(assertEqual
[ "Carthorse" ]
, test "detects anagrams case-insensitively"
(assertEqual [ "Carthorse" ]
(detect "Orchestra" [ "cashregister", "Carthorse", "radishes" ])
)
, test
"detects anagrams using case-insensitive subject"
(assertEqual
[ "carthorse" ]
, test "detects anagrams using case-insensitive subject"
(assertEqual [ "carthorse" ]
(detect "Orchestra" [ "cashregister", "carthorse", "radishes" ])
)
, test
"detects anagrams using case-insensitve possible matches"
(assertEqual
[ "Carthorse" ]
, test "detects anagrams using case-insensitve possible matches"
(assertEqual [ "Carthorse" ]
(detect "orchestra" [ "cashregister", "Carthorse", "radishes" ])
)
, test
"does not detect a word as its own anagram"
(assertEqual
[]
, test "does not detect a word as its own anagram"
(assertEqual []
(detect "banana" [ "Banana" ])
)
, test
"does not detect a anagram if the original word is repeated"
(assertEqual
[]
, test "does not detect a anagram if the original word is repeated"
(assertEqual []
(detect "go" [ "go Go GO" ])
)
, test
"anagrams must use all letters exactly once"
(assertEqual
[]
, test "anagrams must use all letters exactly once"
(assertEqual []
(detect "tapper" [ "patter" ])
)
, test
"eliminates anagrams with the same checksum"
(assertEqual
[]
, test "eliminates anagrams with the same checksum"
(assertEqual []
(detect "mass" [ "last" ])
)
, test
"detects unicode anagrams"
(assertEqual
[ "ΒΓΑ", "γβα" ]
, test "detects unicode anagrams"
(assertEqual [ "ΒΓΑ", "γβα" ]
(detect "ΑΒΓ" [ "ΒΓΑ", "ΒΓΔ", "γβα" ])
)
, test
"eliminates misleading unicode anagrams"
(assertEqual
[]
, test "eliminates misleading unicode anagrams"
(assertEqual []
(detect "ΑΒΓ" [ "ABΓ" ])
)
, test
"capital word is not own anagram"
(assertEqual
[]
, test "capital word is not own anagram"
(assertEqual []
(detect "BANANA" [ "Banana" ])
)
, test
"anagrams must use all letters exactly once"
(assertEqual
[]
, test "anagrams must use all letters exactly once"
(assertEqual []
(detect "patter" [ "tapper" ])
)
]

View file

@ -9,8 +9,7 @@ import Bob
tests : Test
tests =
suite
"Bob"
suite "Bob"
[ test "stating something" (assertEqual "Whatever." (Bob.hey "Tom-ay-to, tom-aaaah-to."))
, test "shouting" (assertEqual "Whoa, chill out!" (Bob.hey "WATCH OUT!"))
, test "shouting gibberish" (assertEqual "Whoa, chill out!" (Bob.hey (uppercaseGibberish 10)))

View file

@ -6,22 +6,18 @@ import DifferenceOfSquares exposing (squareOfSum, sumOfSquares, difference)
tests : Test
tests =
suite
"DifferenceOfSquares"
[ suite
"square the sum of the numbers up to the given number"
suite "DifferenceOfSquares"
[ suite "square the sum of the numbers up to the given number"
[ test "square of sum 5" (assertEqual 225 (squareOfSum 5))
, test "square of sum 10" (assertEqual 3025 (squareOfSum 10))
, test "square of sum 100" (assertEqual 25502500 (squareOfSum 100))
]
, suite
"sum the squares of the numbers up to the given number"
, suite "sum the squares of the numbers up to the given number"
[ test "sum of squares 5" (assertEqual 55 (sumOfSquares 5))
, test "sum of squares 10" (assertEqual 385 (sumOfSquares 10))
, test "sum of squares 100" (assertEqual 338350 (sumOfSquares 100))
]
, suite
"subtract sum of squares from square of sums"
, suite "subtract sum of squares from square of sums"
[ test "difference of squares 0" (assertEqual 0 (difference 0))
, test "difference of squares 5" (assertEqual 170 (difference 5))
, test "difference of squares 10" (assertEqual 2640 (difference 10))

View file

@ -6,21 +6,16 @@ import GradeSchool exposing (addStudent, studentsInGrade, allStudents)
tests : Test
tests =
suite
"GradeSchool"
[ test
"add student"
(assertEqual
[ "Aimee" ]
suite "GradeSchool"
[ test "add student"
(assertEqual [ "Aimee" ]
(GradeSchool.empty
|> addStudent 2 "Aimee"
|> studentsInGrade 2
)
)
, test
"add more students in same class"
(assertEqual
[ "Blair", "James", "Paul" ]
, test "add more students in same class"
(assertEqual [ "Blair", "James", "Paul" ]
(GradeSchool.empty
|> addStudent 2 "James"
|> addStudent 2 "Blair"
@ -28,10 +23,8 @@ tests =
|> studentsInGrade 2
)
)
, test
"add students to different grades"
(assertEqual
[ [ "Chelsea" ], [ "Logan" ] ]
, test "add students to different grades"
(assertEqual [ [ "Chelsea" ], [ "Logan" ] ]
(let
school =
GradeSchool.empty
@ -41,10 +34,8 @@ tests =
[ studentsInGrade 3 school, studentsInGrade 7 school ]
)
)
, test
"get students in a grade"
(assertEqual
[ "Bradley", "Franklin" ]
, test "get students in a grade"
(assertEqual [ "Bradley", "Franklin" ]
(GradeSchool.empty
|> addStudent 5 "Franklin"
|> addStudent 5 "Bradley"
@ -52,10 +43,8 @@ tests =
|> studentsInGrade 5
)
)
, test
"get all students in the school"
(assertEqual
[ ( 3, [ "Kyle" ] ), ( 4, [ "Christopher", "Jennifer" ] ), ( 6, [ "Kareem" ] ) ]
, test "get all students in the school"
(assertEqual [ ( 3, [ "Kyle" ] ), ( 4, [ "Christopher", "Jennifer" ] ), ( 6, [ "Kareem" ] ) ]
(GradeSchool.empty
|> addStudent 4 "Jennifer"
|> addStudent 6 "Kareem"
@ -64,8 +53,7 @@ tests =
|> allStudents
)
)
, test
"get students in a non-existent grade"
, test "get students in a non-existent grade"
(assertEqual [] (studentsInGrade 1 GradeSchool.empty))
]

View file

@ -6,49 +6,34 @@ import Hamming exposing (distance)
tests : Test
tests =
suite
"Hamming"
[ test
"identical strands"
suite "Hamming"
[ test "identical strands"
(assertEqual (Just 0) (distance "A" "A"))
, test
"long identical strands"
, test "long identical strands"
(assertEqual (Just 0) (distance "GGACTGA" "GGACTGA"))
, test
"complete distance in single nucleotide strands"
, test "complete distance in single nucleotide strands"
(assertEqual (Just 1) (distance "A" "G"))
, test
"complete distance in small strands"
, test "complete distance in small strands"
(assertEqual (Just 2) (distance "AG" "CT"))
, test
"small distance in small strands"
, test "small distance in small strands"
(assertEqual (Just 1) (distance "AT" "CT"))
, test
"small distance"
, test "small distance"
(assertEqual (Just 1) (distance "GGACG" "GGTCG"))
, test
"small distance in long strands"
, test "small distance in long strands"
(assertEqual (Just 2) (distance "ACCAGGG" "ACTATGG"))
, test
"non-unique character in first strand"
, test "non-unique character in first strand"
(assertEqual (Just 1) (distance "AGA" "AGG"))
, test
"non-unique character in second strand"
, test "non-unique character in second strand"
(assertEqual (Just 1) (distance "AGG" "AGA"))
, test
"large distance"
, test "large distance"
(assertEqual (Just 4) (distance "GATACA" "GCATAA"))
, test
"large distance in off-by-one strand"
, test "large distance in off-by-one strand"
(assertEqual (Just 9) (distance "GGACGGATTCTG" "AGGACGGATTCT"))
, test
"empty strands"
, test "empty strands"
(assertEqual (Just 0) (distance "" ""))
, test
"disallow first strand longer"
, test "disallow first strand longer"
(assertEqual Nothing (distance "AATG" "AAA"))
, test
"disallow second strand longer"
, test "disallow second strand longer"
(assertEqual Nothing (distance "ATA" "AGTG"))
]

View file

@ -6,8 +6,7 @@ import HelloWorld exposing (helloWorld)
tests : Test
tests =
suite
"Hello, World!"
suite "Hello, World!"
[ test "Hello with no name" (assertEqual "Hello, World!" (helloWorld Nothing))
, test "Hello to a sample name" (assertEqual "Hello, Alice!" (helloWorld (Just "Alice")))
, test "Hello to another sample name" (assertEqual "Hello, Bob!" (helloWorld (Just "Bob")))

View file

@ -6,8 +6,7 @@ import Leap
tests : Test
tests =
suite
"Leap"
suite "Leap"
[ test "leap year" (assertEqual True (Leap.isLeapYear 1996))
, test "non-leap year" (assertEqual False (Leap.isLeapYear 1997))
, test "non-leap even year" (assertEqual False (Leap.isLeapYear 1998))

View file

@ -6,56 +6,43 @@ import ListOps exposing (..)
tests : Test
tests =
suite
"List Ops"
[ suite
"length"
suite "List Ops"
[ suite "length"
[ test "empty list" (assertEqual 0 (length []))
, test "non-empty list" (assertEqual 4 (length [1..4]))
]
, suite
"reverse"
, suite "reverse"
[ test "empty list" (assertEqual [] (reverse []))
, test "non-empty list" (assertEqual [ 4, 3, 2, 1 ] (reverse [1..4]))
]
, suite
"map"
, suite "map"
[ test "empty list" (assertEqual [] (map ((+) 1) []))
, test "non-empty list" (assertEqual [2..5] (map ((+) 1) [1..4]))
]
, suite
"filter"
, suite "filter"
[ test "empty list" (assertEqual [] (filter (\_ -> True) []))
, test
"non-empty list"
, test "non-empty list"
(assertEqual [ 2, 4 ] (filter (\x -> x % 2 == 0) [1..4]))
]
, suite
"foldl"
, suite "foldl"
[ test "empty list" (assertEqual 0 (foldl (+) 0 []))
, test "non-empty list" (assertEqual 10 (foldl (+) 0 [1..4]))
]
, suite
"foldr"
, suite "foldr"
[ test "empty list" (assertEqual 0 (foldr (+) 0 []))
, test "non-empty list" (assertEqual 10 (foldr (+) 0 [1..4]))
]
, suite
"append"
, suite "append"
[ test "empty lists" (assertEqual [] (append [] []))
, test
"empty and non-empty lists"
, test "empty and non-empty lists"
(assertEqual [1..4] (append [] [1..4]))
, test
"non-empty and empty lists"
, test "non-empty and empty lists"
(assertEqual [1..4] (append [1..4] []))
, test "non-empty lists" (assertEqual [1..8] (append [1..4] [5..8]))
]
, suite
"concat"
, suite "concat"
[ test "empty list" (assertEqual [] (concat []))
, test
"list of lists"
, test "list of lists"
(assertEqual [1..10] (concat [ [1..3], [], [4..7], [8..10] ]))
]
]

View file

@ -6,27 +6,19 @@ import NucleotideCount exposing (nucleotideCounts, version)
tests : Test
tests =
suite
"NucleotideCount"
[ test
"the solution is for the correct version of the test"
suite "NucleotideCount"
[ test "the solution is for the correct version of the test"
(assertEqual 2 version)
, test
"empty dna strand has no nucleotides"
(assertEqual
{ a = 0, t = 0, c = 0, g = 0 }
, test "empty dna strand has no nucleotides"
(assertEqual { a = 0, t = 0, c = 0, g = 0 }
(nucleotideCounts "")
)
, test
"repetitive-sequence-has-only-guanosine"
(assertEqual
{ a = 0, t = 0, c = 0, g = 8 }
, test "repetitive-sequence-has-only-guanosine"
(assertEqual { a = 0, t = 0, c = 0, g = 8 }
(nucleotideCounts "GGGGGGGG")
)
, test
"counts all nucleotides"
(assertEqual
{ a = 20, t = 21, c = 12, g = 17 }
, test "counts all nucleotides"
(assertEqual { a = 20, t = 21, c = 12, g = 17 }
(nucleotideCounts "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC")
)
]

View file

@ -6,60 +6,41 @@ import Pangram exposing (isPangram)
tests : Test
tests =
suite
"Pangram"
[ test
"sentence empty"
(assertEqual
False
suite "Pangram"
[ test "sentence empty"
(assertEqual False
(isPangram "")
)
, test
"pangram with only lower case"
(assertEqual
True
, test "pangram with only lower case"
(assertEqual True
(isPangram "the quick brown fox jumps over the lazy dog")
)
, test
"missing character 'x'"
(assertEqual
False
, test "missing character 'x'"
(assertEqual False
(isPangram "a quick movement of the enemy will jeopardize five gunboats")
)
, test
"another missing character 'x'"
(assertEqual
False
, test "another missing character 'x'"
(assertEqual False
(isPangram "the quick brown fish jumps over the lazy dog")
)
, test
"pangram with underscores"
(assertEqual
True
, test "pangram with underscores"
(assertEqual True
(isPangram "the_quick_brown_fox_jumps_over_the_lazy_dog")
)
, test
"pangram with numbers"
(assertEqual
True
, test "pangram with numbers"
(assertEqual True
(isPangram "the 1 quick brown fox jumps over the 2 lazy dogs")
)
, test
"missing letters replaced by numbers"
(assertEqual
False
, test "missing letters replaced by numbers"
(assertEqual False
(isPangram "7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")
)
, test
"pangram with mixed case and punctuation"
(assertEqual
True
, test "pangram with mixed case and punctuation"
(assertEqual True
(isPangram "\"Five quacking Zephyrs jolt my wax bed.\"")
)
, test
"pangram with non ascii characters"
(assertEqual
True
, test "pangram with non ascii characters"
(assertEqual True
(isPangram "Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.")
)
]

View file

@ -6,43 +6,30 @@ import PhoneNumber exposing (getNumber, prettyPrint)
tests : Test
tests =
suite
"PhoneNumber"
[ test
"cleans number"
suite "PhoneNumber"
[ test "cleans number"
(assertEqual (Just "1234567890") (getNumber "(123) 456-7890"))
, test
"cleans number with dots"
, test "cleans number with dots"
(assertEqual (Just "1234567890") (getNumber "123.456.7890"))
, test
"valid when 11 digits and first is 1"
, test "valid when 11 digits and first is 1"
(assertEqual (Just "1234567890") (getNumber "11234567890"))
, test
"invalid when 11 digits"
, test "invalid when 11 digits"
(assertEqual Nothing (getNumber "21234567890"))
, test
"invalid when 9 digits"
, test "invalid when 9 digits"
(assertEqual Nothing (getNumber "123456789"))
, test
"invalid when 12 digits"
, test "invalid when 12 digits"
(assertEqual Nothing (getNumber "123456789012"))
, test
"invalid when empty"
, test "invalid when empty"
(assertEqual Nothing (getNumber ""))
, test
"invalid when no digits present"
, test "invalid when no digits present"
(assertEqual Nothing (getNumber " (-) "))
, test
"valid with leading characters"
, test "valid with leading characters"
(assertEqual (Just "1234567890") (getNumber "my number is 123 456 7890"))
, test
"valid with trailing characters"
, test "valid with trailing characters"
(assertEqual (Just "1234567890") (getNumber "123 456 7890 - bob"))
, test
"pretty print"
, test "pretty print"
(assertEqual (Just "(123) 456-7890") (prettyPrint "1234567890"))
, test
"pretty print with full us phone number"
, test "pretty print with full us phone number"
(assertEqual (Just "(123) 456-7890") (prettyPrint "11234567890"))
]

View file

@ -6,8 +6,7 @@ import Raindrops exposing (raindrops)
tests : Test
tests =
suite
"Raindrops"
suite "Raindrops"
[ test "1" (assertEqual "1" (raindrops 1))
, test "3" (assertEqual "Pling" (raindrops 3))
, test "5" (assertEqual "Plang" (raindrops 5))

View file

@ -6,28 +6,20 @@ import RNATranscription exposing (toRNA)
tests : Test
tests =
suite
"RNATranscription"
[ test
"complement of cytosine is guanine"
suite "RNATranscription"
[ test "complement of cytosine is guanine"
(assertEqual (Ok "G") (toRNA "C"))
, test
"complement of guanine is cytosine"
, test "complement of guanine is cytosine"
(assertEqual (Ok "C") (toRNA "G"))
, test
"complement of thymine is adenine"
, test "complement of thymine is adenine"
(assertEqual (Ok "A") (toRNA "T"))
, test
"complement of adenine is uracil"
, test "complement of adenine is uracil"
(assertEqual (Ok "U") (toRNA "A"))
, test
"complement"
, test "complement"
(assertEqual (Ok "UGCACCAGAAUU") (toRNA "ACGTGGTCTTAA"))
, test
"correctly handles completely invalid input"
, test "correctly handles completely invalid input"
(assertEqual (Err 'X') (toRNA "XXX"))
, test
"correctly handles partially invalid input"
, test "correctly handles partially invalid input"
(assertEqual (Err 'U') (toRNA "UGAAXXXGACAUG"))
]

View file

@ -6,10 +6,8 @@ import RobotSimulator exposing (defaultRobot, Robot, Bearing(North, East, West,
tests : Test
tests =
suite
"RobotSimulator"
[ suite
"init"
suite "RobotSimulator"
[ suite "init"
(let
robot =
defaultRobot
@ -18,8 +16,7 @@ tests =
, test "bearing" (assertEqual North robot.bearing)
]
)
, suite
"setup"
, suite "setup"
(let
robot =
Robot South { x = -1, y = 1 }
@ -28,24 +25,21 @@ tests =
, test "bearing" (assertEqual South robot.bearing)
]
)
, suite
"turn right"
, suite "turn right"
([1..3]
|> List.scanl (\_ r -> turnRight r) defaultRobot
|> List.map .bearing
|> assertionList [ North, East, South, West ]
|> List.map defaultTest
)
, suite
"turn left"
, suite "turn left"
([1..3]
|> List.scanl (\_ r -> turnLeft r) defaultRobot
|> List.map .bearing
|> assertionList [ North, West, South, East ]
|> List.map defaultTest
)
, suite
"advance positive north"
, suite "advance positive north"
(let
robot =
Robot North { x = 0, y = 0 }
@ -55,8 +49,7 @@ tests =
, test "bearing" (assertEqual North robot.bearing)
]
)
, suite
"advance positive east"
, suite "advance positive east"
(let
robot =
Robot East { x = 0, y = 0 }
@ -66,8 +59,7 @@ tests =
, test "bearing" (assertEqual East robot.bearing)
]
)
, suite
"advance negative south"
, suite "advance negative south"
(let
robot =
Robot South { x = 0, y = 0 }
@ -77,8 +69,7 @@ tests =
, test "bearing" (assertEqual South robot.bearing)
]
)
, suite
"advance positive west"
, suite "advance positive west"
(let
robot =
Robot West { x = 0, y = 0 }
@ -88,8 +79,7 @@ tests =
, test "bearing" (assertEqual West robot.bearing)
]
)
, suite
"simulate prog 1"
, suite "simulate prog 1"
(let
robot =
Robot North { x = 0, y = 0 }
@ -99,8 +89,7 @@ tests =
, test "bearing" (assertEqual West robot.bearing)
]
)
, suite
"simulate prog 2"
, suite "simulate prog 2"
(let
robot =
Robot East { x = 2, y = -7 }
@ -110,8 +99,7 @@ tests =
, test "bearing" (assertEqual South robot.bearing)
]
)
, suite
"simulate prog 3"
, suite "simulate prog 3"
(let
robot =
Robot South { x = 8, y = 4 }

View file

@ -7,8 +7,8 @@ import Regex
{-
To the unaware: this was written by a very green elmer, so don't consider
it an idiomatic exemplar to emulate.
To the unaware: this was written by a very green elmer, so don't consider
it an idiomatic exemplar to emulate.
-}

View file

@ -10,23 +10,21 @@ import Char
{-
Currently disabled until elm-check is updated to support Elm 0.17
Currently disabled until elm-check is updated to support Elm 0.17
Welcome! This is a property based test which will generate a bunch of random
test cases in an attempt to find edge cases in your solution. If all goes well,
any code that passes the regular tests should be fine here as well. If it goes
less well, this should hopefully narrow the failure down to a useful test case.
Welcome! This is a property based test which will generate a bunch of random
test cases in an attempt to find edge cases in your solution. If all goes well,
any code that passes the regular tests should be fine here as well. If it goes
less well, this should hopefully narrow the failure down to a useful test case.
Good luck!
Good luck!
-}
claims : Check.Claim
claims =
suite
"List Reverse"
[ claim
"Encoding and decoding yields the original string"
suite "List Reverse"
[ claim "Encoding and decoding yields the original string"
`that` (\input -> decode (encode (S.concat input)))
`is` S.concat
`for` inputProducer
@ -36,8 +34,7 @@ claims =
inputProducer : P.Producer (List String)
inputProducer =
P.tuple ( P.rangeInt 0 1001, upperCaseLetter )
|> P.convert
(\( n, c ) -> S.repeat n (S.fromChar c))
|> P.convert (\( n, c ) -> S.repeat n (S.fromChar c))
(\s ->
( S.length s
, S.toList s |> List.head |> crashIfNothing

View file

@ -6,46 +6,32 @@ import RunLengthEncoding exposing (version, decode, encode)
tests : Test
tests =
suite
"RunLengthEncoding"
[ test
"the solution is for the correct version of the test"
suite "RunLengthEncoding"
[ test "the solution is for the correct version of the test"
(assertEqual 2 version)
, test
"encode simple"
, test "encode simple"
(assertEqual "2A3B4C" (encode "AABBBCCCC"))
, test
"decode simple"
, test "decode simple"
(assertEqual "AABBBCCCC" (decode "2A3B4C"))
, test
"encode with single values"
(assertEqual
"12WB12W3B24WB"
, test "encode with single values"
(assertEqual "12WB12W3B24WB"
(encode "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB")
)
, test
"decode with single values"
(assertEqual
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"
, test "decode with single values"
(assertEqual "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"
(decode "12WB12W3B24WB")
)
, test
"(decode (encode (...)) combination"
(assertEqual
"zzz ZZ zZ"
, test "(decode (encode (...)) combination"
(assertEqual "zzz ZZ zZ"
(decode (encode "zzz ZZ zZ"))
)
, test
"decode with a x10 value"
(assertEqual
"WWWWWWWWWW"
, test "decode with a x10 value"
(assertEqual "WWWWWWWWWW"
(decode "10W")
)
, test
"encode unicode"
, test "encode unicode"
(assertEqual "32" (encode ""))
, test
"decode unicode"
, test "decode unicode"
(assertEqual "" (decode "32"))
]

View file

@ -6,54 +6,37 @@ import Series exposing (slices)
tests : Test
tests =
suite
"Series"
[ test
"slices of one"
(assertEqual
(Ok [ [ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ] ])
suite "Series"
[ test "slices of one"
(assertEqual (Ok [ [ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ] ])
(slices 1 "01234")
)
, test
"slices of two"
(assertEqual
(Ok [ [ 9, 7 ], [ 7, 8 ], [ 8, 6 ], [ 6, 7 ], [ 7, 5 ], [ 5, 6 ], [ 6, 4 ] ])
, test "slices of two"
(assertEqual (Ok [ [ 9, 7 ], [ 7, 8 ], [ 8, 6 ], [ 6, 7 ], [ 7, 5 ], [ 5, 6 ], [ 6, 4 ] ])
(slices 2 "97867564")
)
, test
"slices of three"
(assertEqual
(Ok [ [ 9, 7, 8 ], [ 7, 8, 6 ], [ 8, 6, 7 ], [ 6, 7, 5 ], [ 7, 5, 6 ], [ 5, 6, 4 ] ])
, test "slices of three"
(assertEqual (Ok [ [ 9, 7, 8 ], [ 7, 8, 6 ], [ 8, 6, 7 ], [ 6, 7, 5 ], [ 7, 5, 6 ], [ 5, 6, 4 ] ])
(slices 3 "97867564")
)
, test
"slices of four"
(assertEqual
(Ok [ [ 0, 1, 2, 3 ], [ 1, 2, 3, 4 ] ])
, test "slices of four"
(assertEqual (Ok [ [ 0, 1, 2, 3 ], [ 1, 2, 3, 4 ] ])
(slices 4 "01234")
)
, test
"slices of five"
(assertEqual
(Ok [ [ 0, 1, 2, 3, 4 ] ])
, test "slices of five"
(assertEqual (Ok [ [ 0, 1, 2, 3, 4 ] ])
(slices 5 "01234")
)
, test
"overly long slice"
(assertEqual
(Ok [])
, test "overly long slice"
(assertEqual (Ok [])
(slices 4 "012")
)
, test
"overly short slice"
(assertEqual
(Err ("Invalid size: 0"))
, test "overly short slice"
(assertEqual (Err ("Invalid size: 0"))
(slices 0 "01234")
)
, test
"input has non numbers"
(assertEqual
(Err "could not convert string 'a' to an Int")
, test "input has non numbers"
(assertEqual (Err "could not convert string 'a' to an Int")
(slices 2 "0123abc")
)
]

View file

@ -6,31 +6,22 @@ import SpaceAge exposing (Planet(..), ageOn)
tests : Test
tests =
suite
"SpaceAge"
[ test
"age in earth years"
suite "SpaceAge"
[ test "age in earth years"
(assertEqual 32 (round (ageOn Earth 1000000000)))
, test
"age in mercury years"
, test "age in mercury years"
(assertEqual 281 (round (ageOn Mercury 2134835688)))
, test
"age in venus years"
, test "age in venus years"
(assertEqual 10 (round (ageOn Venus 189839836)))
, test
"age on mars"
, test "age on mars"
(assertEqual 39 (round (ageOn Mars 2329871239)))
, test
"age on jupiter"
, test "age on jupiter"
(assertEqual 2 (round (ageOn Jupiter 901876382)))
, test
"age on saturn"
, test "age on saturn"
(assertEqual 3 (round (ageOn Saturn 3000000000)))
, test
"age on uranus"
, test "age on uranus"
(assertEqual 1 (round (ageOn Uranus 3210123456)))
, test
"age on neptune"
, test "age on neptune"
(assertEqual 2 (round (ageOn Neptune 8210123456)))
]

View file

@ -27,78 +27,53 @@ lessThanTen num =
tests : Test
tests =
suite
"Strain"
[ test
"empty keep"
(assertEqual
[]
suite "Strain"
[ test "empty keep"
(assertEqual []
(keep lessThanTen [])
)
, test
"keep everything"
(assertEqual
[ 1, 2, 3 ]
, test "keep everything"
(assertEqual [ 1, 2, 3 ]
(keep lessThanTen [ 1, 2, 3 ])
)
, test
"keep first and last"
(assertEqual
[ 1, 3 ]
, test "keep first and last"
(assertEqual [ 1, 3 ]
(keep odd [ 1, 2, 3 ])
)
, test
"keep nothing"
(assertEqual
[]
, test "keep nothing"
(assertEqual []
(keep even [ 1, 3, 5, 7 ])
)
, test
"keep neither first nor last"
(assertEqual
[ 2 ]
, test "keep neither first nor last"
(assertEqual [ 2 ]
(keep even [ 1, 2, 3 ])
)
, test
"keep strings"
(assertEqual
[ "zebra", "zombies", "zealot" ]
, test "keep strings"
(assertEqual [ "zebra", "zombies", "zealot" ]
(keep (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ])
)
, test
"empty discard"
(assertEqual
[]
, test "empty discard"
(assertEqual []
(discard lessThanTen [])
)
, test
"discard everything"
(assertEqual
[]
, test "discard everything"
(assertEqual []
(discard lessThanTen [ 1, 2, 3 ])
)
, test
"discard first and last"
(assertEqual
[ 2 ]
, test "discard first and last"
(assertEqual [ 2 ]
(discard odd [ 1, 2, 3 ])
)
, test
"discard nothing"
(assertEqual
[ 1, 3, 5, 7 ]
, test "discard nothing"
(assertEqual [ 1, 3, 5, 7 ]
(discard even [ 1, 3, 5, 7 ])
)
, test
"discard neither first nor last"
(assertEqual
[ 1, 3 ]
, test "discard neither first nor last"
(assertEqual [ 1, 3 ]
(discard even [ 1, 2, 3 ])
)
, test
"discard strings"
(assertEqual
[ "apple", "banana", "cherimoya" ]
, test "discard strings"
(assertEqual [ "apple", "banana", "cherimoya" ]
(discard (isFirstLetter "z") [ "apple", "zebra", "banana", "zombies", "cherimoya", "zealot" ])
)
]

View file

@ -6,64 +6,44 @@ import Sublist exposing (version, sublist, ListComparison(..))
tests : Test
tests =
suite
"Sublist"
[ test
"the solution is for the correct version of the test"
suite "Sublist"
[ test "the solution is for the correct version of the test"
(assertEqual 2 version)
, test
"empty equals empty"
, test "empty equals empty"
(assertEqual Equal (sublist [] []))
, test
"empty is a sublist of anything"
, test "empty is a sublist of anything"
(assertEqual Sublist (sublist [] [ 1, 2 ]))
, test
"anything is a superlist of empty"
, test "anything is a superlist of empty"
(assertEqual Superlist (sublist [ 1, 2 ] []))
, test
"1 is not 2"
, test "1 is not 2"
(assertEqual Unequal (sublist [ 1 ] [ 2 ]))
, test
"compare larger equal lists"
, test "compare larger equal lists"
(assertEqual Equal (sublist [ 1, 1, 1 ] [ 1, 1, 1 ]))
, test
"sublist at start"
, test "sublist at start"
(assertEqual Sublist (sublist [ 1, 2, 3 ] [ 1, 2, 3, 4, 5 ]))
, test
"sublist in the middle"
, test "sublist in the middle"
(assertEqual Sublist (sublist [ 4, 3, 2 ] [ 5, 4, 3, 2, 1 ]))
, test
"sublist at end"
, test "sublist at end"
(assertEqual Sublist (sublist [ 3, 4, 5 ] [ 1, 2, 3, 4, 5 ]))
, test
"partially matching sublist at start"
, test "partially matching sublist at start"
(assertEqual Sublist (sublist [ 1, 1, 2 ] [ 1, 1, 1, 2 ]))
, test
"sublist early in huge list"
, test "sublist early in huge list"
(assertEqual Sublist (sublist [ 3, 4, 5 ] [1..100000]))
, test
"huge sublist not in list"
, test "huge sublist not in list"
(assertEqual Unequal (sublist [10..5001] [1..5000]))
, test
"superlist at start"
, test "superlist at start"
(assertEqual Superlist (sublist [ 1, 2, 3, 4, 5 ] [ 1, 2, 3 ]))
, test
"superlist in middle"
, test "superlist in middle"
(assertEqual Superlist (sublist [ 5, 4, 3, 2, 1 ] [ 4, 3, 2 ]))
, test
"superlist at end"
, test "superlist at end"
(assertEqual Superlist (sublist [ 1, 2, 3, 4, 5 ] [ 3, 4, 5 ]))
, test
"partially matching superlist at start"
, test "partially matching superlist at start"
(assertEqual Superlist (sublist [ 1, 1, 1, 2 ] [ 1, 1, 2 ]))
, test
"superlist early in huge list"
, test "superlist early in huge list"
(assertEqual Superlist (sublist [1..100000] [ 3, 4, 5 ]))
, test
"recurring values sublist"
, test "recurring values sublist"
(assertEqual Sublist (sublist [ 1, 2, 1, 2, 3 ] [ 1, 2, 3, 1, 2, 1, 2, 3, 2, 1 ]))
, test
"recurring values unequal"
, test "recurring values unequal"
(assertEqual Unequal (sublist [ 1, 2, 1, 2, 3 ] [ 1, 2, 3, 1, 2, 3, 2, 3, 2, 1 ]))
]

View file

@ -6,8 +6,7 @@ import SumOfMultiples exposing (sumOfMultiples)
tests : Test
tests =
suite
"Sum Of Multiples"
suite "Sum Of Multiples"
[ test "[3, 5] 15" (assertEqual 45 (sumOfMultiples [ 3, 5 ] 15))
, test "[7, 13, 17] 20" (assertEqual 51 (sumOfMultiples [ 7, 13, 17 ] 20))
, test "[4, 6] 15" (assertEqual 30 (sumOfMultiples [ 4, 6 ] 15))

View file

@ -6,52 +6,36 @@ import Triangle exposing (triangleKind)
tests : Test
tests =
suite
"triangleKind"
[ test
"equilateral triangles have equal sides"
suite "triangleKind"
[ test "equilateral triangles have equal sides"
(assertEqual (Ok "equilateral") (triangleKind 2 2 2))
, test
"larger equilateral triangles also have equal sides"
, test "larger equilateral triangles also have equal sides"
(assertEqual (Ok "equilateral") (triangleKind 10 10 10))
, test
"isosceles triangles have last two sides equal"
, test "isosceles triangles have last two sides equal"
(assertEqual (Ok "isosceles") (triangleKind 3 4 4))
, test
"isosceles triangles have first and last sides equal"
, test "isosceles triangles have first and last sides equal"
(assertEqual (Ok "isosceles") (triangleKind 4 3 4))
, test
"isosceles triangles have two first sides equal"
, test "isosceles triangles have two first sides equal"
(assertEqual (Ok "isosceles") (triangleKind 4 4 3))
, test
"isosceles triangles have in fact exactly two sides equal"
, test "isosceles triangles have in fact exactly two sides equal"
(assertEqual (Ok "isosceles") (triangleKind 10 10 2))
, test
"scalene triangles have no equal sides"
, test "scalene triangles have no equal sides"
(assertEqual (Ok "scalene") (triangleKind 3 4 5))
, test
"scalene triangles have no equal sides at a larger scale too"
, test "scalene triangles have no equal sides at a larger scale too"
(assertEqual (Ok "scalene") (triangleKind 10 11 12))
, test
"scalene triangles have no equal sides at a larger scale too 2"
, test "scalene triangles have no equal sides at a larger scale too 2"
(assertEqual (Ok "scalene") (triangleKind 5 4 2))
, test
"very small triangles are legal"
, test "very small triangles are legal"
(assertEqual (Ok "scalene") (triangleKind 0.4 0.6 0.3))
, test
"triangles with no size are illegal"
, test "triangles with no size are illegal"
(assertEqual (Err "Invalid lengths") (triangleKind 0 0 0))
, test
"triangles with negative sides are illegal"
, test "triangles with negative sides are illegal"
(assertEqual (Err "Invalid lengths") (triangleKind 3 4 -5))
, test
"triangles violating triangle inequality are illegal 1"
, test "triangles violating triangle inequality are illegal 1"
(assertEqual (Err "Violates inequality") (triangleKind 1 1 3))
, test
"triangles violating triangle inequality are illegal 2"
, test "triangles violating triangle inequality are illegal 2"
(assertEqual (Err "Violates inequality") (triangleKind 2 4 2))
, test
"triangles violating triangle inequality are illegal 3"
, test "triangles violating triangle inequality are illegal 3"
(assertEqual (Err "Violates inequality") (triangleKind 7 3 2))
]

View file

@ -7,42 +7,29 @@ import WordCount exposing (wordCount)
tests : Test
tests =
suite
"Word Count"
[ test
"count one word"
(assertEqual
[ ( "word", 1 ) ]
suite "Word Count"
[ test "count one word"
(assertEqual [ ( "word", 1 ) ]
(wordCount "word" |> Dict.toList)
)
, test
"count one of each word"
(assertEqual
[ ( "each", 1 ), ( "of", 1 ), ( "one", 1 ) ]
, test "count one of each word"
(assertEqual [ ( "each", 1 ), ( "of", 1 ), ( "one", 1 ) ]
(wordCount "one of each" |> Dict.toList)
)
, test
"multiple occurrences of a word"
(assertEqual
[ ( "blue", 1 ), ( "fish", 4 ), ( "one", 1 ), ( "red", 1 ), ( "two", 1 ) ]
, test "multiple occurrences of a word"
(assertEqual [ ( "blue", 1 ), ( "fish", 4 ), ( "one", 1 ), ( "red", 1 ), ( "two", 1 ) ]
(wordCount "one fish two fish red fish blue fish" |> Dict.toList)
)
, test
"ignore punctuation"
(assertEqual
[ ( "as", 1 ), ( "car", 1 ), ( "carpet", 1 ), ( "java", 1 ), ( "javascript", 1 ) ]
, test "ignore punctuation"
(assertEqual [ ( "as", 1 ), ( "car", 1 ), ( "carpet", 1 ), ( "java", 1 ), ( "javascript", 1 ) ]
(wordCount "car : carpet as java : javascript!!&@$%^&" |> Dict.toList)
)
, test
"include numbers"
(assertEqual
[ ( "1", 1 ), ( "2", 1 ), ( "testing", 2 ) ]
, test "include numbers"
(assertEqual [ ( "1", 1 ), ( "2", 1 ), ( "testing", 2 ) ]
(wordCount "testing, 1, 2 testing" |> Dict.toList)
)
, test
"normalize case"
(assertEqual
[ ( "go", 3 ), ( "stop", 2 ) ]
, test "normalize case"
(assertEqual [ ( "go", 3 ), ( "stop", 2 ) ]
(wordCount "go Go GO Stop stop" |> Dict.toList)
)
]