Created
June 7, 2015 19:47
-
-
Save dmcardle/85bf4d15c0f0a7619957 to your computer and use it in GitHub Desktop.
CSE305 Homework 2 Scaffolding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data BinaryTree a = Empty | |
| Node a (BinaryTree a) (BinaryTree a) | |
deriving (Show, Read, Eq) | |
-------------------------------------------------------------------------------- | |
-- Define Your Functions Here | |
-- | |
-- Define each of your answers and helper functions here. The line I have | |
-- written for each of the functions is not going to be part of your solution. | |
-------------------------------------------------------------------------------- | |
searchBST q t = False | |
checkBST t = False | |
treeMap f t = Empty | |
-------------------------------------------------------------------------------- | |
-- Tests | |
-- | |
-- Just call "runTests" function from GHCI. If you see "*** FAILURE ***" | |
-- printed out, look at the definition of "runTests" function to figure out | |
-- which one caused it to fail. | |
-------------------------------------------------------------------------------- | |
tree1 = (Node 1 | |
(Node 2 | |
Empty | |
(Node 3 Empty Empty)) | |
(Node 4 Empty Empty)) | |
tree1' = (Node 2 | |
(Node 3 | |
Empty | |
(Node 4 Empty Empty)) | |
(Node 5 Empty Empty)) | |
tree2 = (Node "walk" | |
(Node "runn" Empty Empty) | |
(Node "jogg" | |
(Node "drumm" Empty Empty) | |
Empty)) | |
tree2' = (Node "walker" | |
(Node "runner" Empty Empty) | |
(Node "jogger" | |
(Node "drummer" Empty Empty) | |
Empty)) | |
bst1 = (Node 5 | |
(Node 4 | |
(Node 3 Empty Empty) | |
Empty) | |
(Node 6 Empty Empty)) | |
bst2 = (Node "d" | |
(Node "cde" Empty Empty) | |
(Node "fgh" | |
(Node "efg" Empty Empty) | |
Empty)) | |
test :: Bool -> IO () | |
test False = putStrLn "*** FAILURE ***" | |
test True = putStrLn "passed" | |
runTests = do | |
putStrLn "-------- Testing searchBST -------- " | |
test (searchBST 5 bst1) | |
test (searchBST 6 bst1) | |
test (not (searchBST 7 bst1)) | |
test (searchBST "efg" bst2) | |
putStrLn "-------- Testing checkBST -------- " | |
test (checkBST bst1) | |
test (checkBST bst2) | |
test (not (checkBST tree1)) | |
test (not (checkBST tree2)) | |
putStrLn "-------- Testing treeMap -------- " | |
test (treeMap (+1) tree1 == tree1') | |
test (treeMap (++"er") tree2 == tree2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment