Skip to content
Open
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
60 changes: 57 additions & 3 deletions assignments/week3/hw/tests/BinarySearchTreesTest.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module BinarySearchTreesTest where
module BinarySearchTreesTest where

import Test.Tasty (defaultMain, testGroup)
import Test.Tasty.HUnit (assertEqual, assertBool, testCase)
Expand All @@ -8,5 +8,59 @@ import BinarySearchTrees
unitTests =
testGroup
"DataProblems"
[]

[testSize,
testMember,
testNotMember,
testInsert,
testToList,
testEquals,
testMin,
testDeleteMin,
testDelete]

-- tree used for tests
-- 10
-- 6 15
-- 4 7 11
-- 2

testTree = Node (Node (Node (Node Null 2 Null) 4 Null) 6 (Node Null 7 Null)) 10 (Node (Node Null 11 Null) 15 Null)

-- test size

testSize = testCase "size of test tree" $ assertEqual [] 7 (size testTree)

-- test member

testMember = testCase "11 in tree" $ assertBool [] (member 11 testTree)
testNotMember = testCase "1 not in tree" $ assertBool [] (not (member 1 testTree))

-- test insert

testInsert = testCase "insert 13 in correct place" $ assertBool [] (eq (insert 13 testTree)
(Node (Node (Node (Node Null 2 Null) 4 Null) 6 (Node Null 7 Null)) 10 (Node (Node Null 11 (Node Null 13 Null)) 15 Null))
)

-- test toList

testToList = testCase "turn test tree to list" $ assertEqual [] [2, 4, 6, 7, 10, 11, 15] (toList testTree)

-- test eq

testTree2 = Node (Node (Node (Node Null 2 Null) 4 Null) 6 (Node Null 7 Null)) 10 (Node (Node Null 11 Null) 15 Null)
testEquals = testCase "testing equality" $ assertBool [] (eq testTree testTree2)

-- test treeMin

testMin = testCase "testing min" $ assertEqual [] (Just 2) (treeMin testTree)

-- test deleteMin

testTreeDeletedMin = Node (Node (Node Null 4 Null) 6 (Node Null 7 Null)) 10 (Node (Node Null 11 Null) 15 Null)
testDeleteMin = testCase "delete min out of test tree" $ assertBool [] (eq (deleteMin testTree) testTreeDeletedMin)

-- test delete

testTreeDeletedRoot = Node (Node (Node (Node Null 2 Null) 4 Null) 6 (Node Null 7 Null)) 11 (Node Null 15 Null)
testDelete = testCase "delete 10 (root) out of test tree" $ assertBool [] (eq (delete 10 testTree) testTreeDeletedRoot)

32 changes: 29 additions & 3 deletions assignments/week3/hw/tests/OutsideTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,37 @@ import Test.Tasty (defaultMain, testGroup)
import Test.Tasty.HUnit (assertEqual, assertBool, testCase)

import Outside(exampleSet, eqSet, exampleBst, onlyHasEven)
import Set
import BinarySearchTrees

unitTests =
testGroup
"Outside"
[]
[testIsEq,
testIsNotEq,
testOnlyHasEven,
testNotOnlyHasEven]

-- test eq set

set1 :: Set
set1 = [1, 2, 3, 4]

set2 :: Set
set2 = [1, 2, 3, 4]

set3 :: Set
set3 = [5, 6, 7]

testIsEq = testCase "set1 and set2 are equal" $ assertBool [] (eqSet set1 set2)
testIsNotEq = testCase "set1 and set3 are not equal" $ assertBool [] (not (eqSet set1 set3))


-- test onlyHasEven

tree1 = Node (Node (Node Null 2 Null) 4 (Node Null 8 Null)) 16 (Node Null 32 (Node Null 64 Null))
tree2 = Node (Node (Node Null 1 Null) 4 (Node Null 8 Null)) 16 (Node Null 32 (Node Null 65 Null))

testOnlyHasEven = testCase "tree1 returns true for onlyHasEven" $ assertBool [] (onlyHasEven tree1)
testNotOnlyHasEven = testCase "tree2 returns false for onlyHasEven" $ assertBool [] (not (onlyHasEven tree2))



56 changes: 51 additions & 5 deletions assignments/week3/hw/tests/SetTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,55 @@ import Set
unitTests =
testGroup
"Set"
[emptySetNot9]
[testContains,
testNotContains,
testInsert,
testIsPrefix,
testIsNotPrefix,
testIsSubset,
testIsNotSubset,
testUnion,
testIntersection]

-- test sets
set1 :: Set
set1 = [1, 3, 5, 7, 9]

set2 :: Set
set2 = [1, 2, 3, 4, 5, 6]

-- test contains

testContains = testCase "set1 contains 5" $ assertBool [] (contains set1 5)
testNotContains = testCase "set1 does not contain 6" $ assertBool [] (contains set2 6)

-- test insert

testInsert = testCase "insert 6 into set1" $ assertEqual [] [1, 3, 5, 6, 7, 9] (insert 6 set1)

-- test isPrefix

testPrefix :: Set
testPrefix = [1, 3]
testIsPrefix = testCase "[1, 3] is a prefix of set1" $ assertBool [] (isPrefix testPrefix set1)
testIsNotPrefix = testCase "[1, 3] is not a prefix of set2" $ assertBool [] (not (isPrefix testPrefix set2))

-- test isSubset

testSubset :: Set
testSubset = [3, 7]
testIsSubset = testCase "[3, 7] is a subset of set1" $ assertBool [] (isSubSet testSubset set1)
testIsNotSubset = testCase "[3, 7] is not a subset of set2" $ assertBool [] (not (isSubSet testSubset set2))

-- test union

correctUnion :: Set
correctUnion = [1, 2, 3, 4, 5, 6, 7, 9]
testUnion = testCase "union of set1 and set2" $ assertEqual [] correctUnion (union set1 set2)

-- test intersection

correctIntersection :: Set
correctIntersection = [1, 3, 5]
testIntersection = testCase "intersection of set1 and set2" $ assertEqual [] correctIntersection (intersection set1 set2)



emptySetNot9 =
testCase "empty set doesn't contain 9" $ assertBool [] (not (contains empty 9))