diff --git a/exercises/chapter3/spago.dhall b/exercises/chapter3/spago.dhall index dceff8756..f2cb8311a 100644 --- a/exercises/chapter3/spago.dhall +++ b/exercises/chapter3/spago.dhall @@ -2,12 +2,8 @@ Welcome to a Spago project! You can edit this file as you like. -} -{ name = - "my-project" -, dependencies = - [ "console", "effect", "lists", "psci-support" ] -, packages = - ./packages.dhall -, sources = - [ "src/**/*.purs", "test/**/*.purs" ] +{ name = "my-project" +, dependencies = [ "console", "effect", "lists", "psci-support", "test-unit" ] +, packages = ./packages.dhall +, sources = [ "src/**/*.purs", "test/**/*.purs" ] } diff --git a/exercises/chapter3/test/Main.purs b/exercises/chapter3/test/Main.purs index f91f98c1e..d85e82dfd 100644 --- a/exercises/chapter3/test/Main.purs +++ b/exercises/chapter3/test/Main.purs @@ -1,11 +1,71 @@ module Test.Main where import Prelude - +import Data.AddressBook (emptyBook, findEntry, insertEntry) +import Data.Maybe (Maybe(..)) import Effect (Effect) -import Effect.Class.Console (log) +import Test.Solutions (findEntryByStreet) +import Test.Unit (suite, test) +import Test.Unit.Assert as Assert +import Test.Unit.Main (runTest) main :: Effect Unit -main = do - log "🍝" - log "You should add some tests." +main = + runTest do + suite "Exercise Group 1" do + let + john = + { firstName: "John" + , lastName: "Smith" + , address: + { street: "123 Fake St.", city: "Faketown", state: "CA" } + } + + peggy = + { firstName: "Peggy" + , lastName: "Hill" + , address: + { street: "84 Rainey St.", city: "Arlen", state: "TX" } + } + + ned = + { firstName: "Ned" + , lastName: "Flanders" + , address: + { street: "740 Evergreen Terrace", city: "Springfield", state: "USA" } + } + + book = + insertEntry john + $ insertEntry peggy + $ insertEntry ned + emptyBook + + bookWithDuplicate = insertEntry john book + -- Exercise 0 is already completed + suite "Exercise 0 - Name lookup" do + test "Lookup existing" + $ Assert.equal (Just ned) + $ findEntry ned.firstName ned.lastName book + test "Lookup missing" + $ Assert.equal Nothing + $ findEntry "unknown" "person" book + suite "Exercise 2 - Street lookup" do + test "Lookup existing" + $ Assert.equal (Just john) + $ findEntryByStreet john.address.street book + {- Move this block comment starting point to enable more tests + test "Lookup missing" + $ Assert.equal Nothing + $ findEntryByStreet "456 Nothing St." book + suite "Exercise 3 - Name check" do + test "Check existing" + $ Assert.equal true + $ isInBook ned.firstName ned.lastName book + test "Check missing" + $ Assert.equal false + $ isInBook "unknown" "person" book + test "Exercise 4 - Remove duplicates" do + Assert.equal book + $ removeDuplicates john.firstName john.lastName bookWithDuplicate +-} \ No newline at end of file diff --git a/exercises/chapter3/test/Solutions.purs b/exercises/chapter3/test/Solutions.purs new file mode 100644 index 000000000..d312cb1c4 --- /dev/null +++ b/exercises/chapter3/test/Solutions.purs @@ -0,0 +1,9 @@ +module Test.Solutions where + +import Prelude +import Data.AddressBook (AddressBook, Entry) +import Data.Maybe (Maybe(..)) + +-- Todo, fix this function +findEntryByStreet :: String -> AddressBook -> Maybe Entry +findEntryByStreet streetName book = Nothing