Advertisement
ttaaa

BTreeTest

Jan 16th, 2022
860
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module BTreeSpec (spec) where
  2.  
  3. import BinomialTree as BTree
  4.  
  5. import Test.HUnit
  6.  
  7. key :: Int
  8. key = 5
  9. rank :: Int
  10. rank = 2
  11. testTreeCreationTree :: BTree.BinTree Int
  12. testTreeCreationTree = BTree.createTree BTreeSpec.key BTreeSpec.rank []
  13.  
  14. testTreeCreationKey = TestCase $ assertEqual ("Key of createTree " ++ show BTreeSpec.key ++ " _ _") BTreeSpec.key (BTree.key testTreeCreationTree)
  15. testTreeCreationRank = TestCase $ assertEqual ("Rank of createTree " ++ show BTreeSpec.rank ++ " _ _") BTreeSpec.rank (BTree.rank testTreeCreationTree)
  16.  
  17.  
  18. key1 :: Int
  19. key1 = 5
  20. key2 :: Int
  21. key2 = 10
  22. testTreeMerge1Tree :: BTree.BinTree Int
  23. testTreeMerge1Tree = BTree.createTree key1 1 []
  24. testTreeMerge2Tree :: BTree.BinTree Int
  25. testTreeMerge2Tree = BTree.createTree key2 1 []
  26.  
  27. testTreeMergeKey1 = TestCase $ assertEqual "Key of root after merge" key1 (BTree.key (BTree.mergeTrees testTreeMerge1Tree testTreeMerge2Tree))
  28. testTreeMergeKey2 = TestCase $ assertEqual "Key of root after merge" key1 (BTree.key (BTree.mergeTrees testTreeMerge2Tree testTreeMerge1Tree))
  29. testTreeMergeRank = TestCase $ assertEqual "Key of root after merge" 2 (BTree.rank (BTree.mergeTrees testTreeMerge2Tree testTreeMerge1Tree))
  30. testTreeMergeChildren = TestCase $ assertEqual "Key of root after merge" [testTreeMerge2Tree] (BTree.children (BTree.mergeTrees testTreeMerge2Tree testTreeMerge1Tree))
  31.  
  32. testlist = TestList [TestLabel "testTreeCreation" testTreeCreationKey,
  33.                      TestLabel "testTreeCreation" testTreeCreationRank,
  34.                      TestLabel "testTreeMerge" testTreeMergeKey1,
  35.                      TestLabel "testTreeMerge" testTreeMergeKey2,
  36.                      TestLabel "testTreeMerge" testTreeMergeRank,
  37.                      TestLabel "testTreeMerge" testTreeMergeChildren]
  38.                    
  39. spec :: IO ()
  40. spec = do
  41.     runTestTT testlist
  42.     return ()
  43.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement