Skip to content

ch3 tests #95

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

Merged
merged 1 commit into from
Apr 22, 2020
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
12 changes: 4 additions & 8 deletions exercises/chapter3/spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
70 changes: 65 additions & 5 deletions exercises/chapter3/test/Main.purs
Original file line number Diff line number Diff line change
@@ -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
-}
9 changes: 9 additions & 0 deletions exercises/chapter3/test/Solutions.purs
Original file line number Diff line number Diff line change
@@ -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