Advertisement
ttaaa

BHeapTest

Jan 16th, 2022
833
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module BHeapSpec (spec) where
  2.  
  3. import BinomialHeap as BHeap
  4. import Data.List as List
  5. import Test.HUnit
  6. import Test.QuickCheck
  7.  
  8. testBHeapSortList :: [Int]
  9. testBHeapSortList = [4, 5, 2, 1, 3, 6, 3, 4]
  10.  
  11. testBHeapSort = TestCase $ assertEqual "List after sort" (List.sort testBHeapSortList) (BHeap.binHeapSort testBHeapSortList)
  12.  
  13. testlist = TestList [TestLabel "testBHeapSort" testBHeapSort]
  14.  
  15.  
  16. prop_elem :: Int -> [Int] -> Bool
  17. prop_elem x xs = elem x (BHeap.binHeapSort xs) == elem x xs
  18.  
  19. prop_ordered :: [Int] -> Bool
  20. prop_ordered xs = ordered (BHeap.binHeapSort xs)
  21.     where
  22.     ordered (x:y:xs) = x <= y && ordered (y:xs)
  23.     ordered _ = True
  24.  
  25. prop_length :: [Int] -> Bool
  26. prop_length xs = length (BHeap.binHeapSort xs) == length xs
  27.  
  28.  
  29.  
  30. spec :: IO ()
  31. spec = do
  32.     quickCheck (withMaxSuccess 1000 prop_length)
  33.     quickCheck (withMaxSuccess 1000 prop_ordered)
  34.     quickCheck (withMaxSuccess 100000 prop_elem)
  35.     runTestTT testlist
  36.     return ()
  37.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement