01 forAll <generator> $ \<pattern> -> <property>
|
quantified_properties.hs |
Codebeispiel 8
01 import QuickCheck 02 03 insertOrdered :: (Ord a) => a -> [a] -> [a] -> [a] 04 insertOrdered a [] ys = ys++[a] 05 insertOrdered a (x:xs) ys 06 | a <= x = ys ++ a:[x] ++ xs 07 | a > x = insertOrdered a xs (ys ++ [x]) 08 09 ordered :: (Ord a) => [a] -> Bool 10 ordered [] = True 11 ordered [x] = True 12 ordered (x1:x2:xs) 13 | x1 <= x2 = True && ordered (x2:xs) 14 | x1 > x2 = False 15 16 prop_InsertOrderedInt :: Integer -> Property 17 prop_InsertOrderedInt x = forAll orderedList $ \xs -> ordered (insertOrdered x xs []) 18 19 orderedList :: (Ord a, Arbitrary a) => Gen [a] 20 orderedList = 21 frequency [(1,return []), 22 (4,do xs <- orderedList 23 n <- arbitrary 24 return ((case xs of 25 [] -> n 26 x:_ -> n `min` x) 27 :xs))] |
complexProp3.hs |
Codebeispiel 9
01 classify <condition> <string>$ <property>
|
classify_properties.hs |
Codebeispiel 10
01 import QuickCheck 02 03 insertOrdered :: (Ord a) => a -> [a] -> [a] -> [a] 04 insertOrdered a [] ys = ys++[a] 05 insertOrdered a (x:xs) ys 06 | a <= x = ys ++ a:[x] ++ xs 07 | a > x = insertOrdered a xs (ys ++ [x]) 08 09 ordered :: (Ord a) => [a] -> Bool 10 ordered [] = True 11 ordered [x] = True 12 ordered (x1:x2:xs) 13 | x1 <= x2 = True && ordered (x2:xs) 14 | x1 > x2 = False 15 16 prop_InsertOrderedInt :: Integer -> [Integer] -> Property 17 prop_InsertOrderedInt x xs = ordered xs ==> 18 classify (ordered (x:xs)) "at-head"$ 19 classify (ordered (xs++[x])) "at-tail"$ 20 ordered (insertOrdered x xs []) 21 |
testQual2.hs |
Codebeispiel 11
01 <condition> `trivial` <property>
|
observing_test_cases.hs |
Codebeispiel 12
01 import QuickCheck 02 03 insertOrdered :: (Ord a) => a -> [a] -> [a] -> [a] 04 insertOrdered a [] ys = ys++[a] 05 insertOrdered a (x:xs) ys 06 | a <= x = ys ++ a:[x] ++ xs 07 | a > x = insertOrdered a xs (ys ++ [x]) 08 09 ordered :: (Ord a) => [a] -> Bool 10 ordered [] = True 11 ordered [x] = True 12 ordered (x1:x2:xs) 13 | x1 <= x2 = True && ordered (x2:xs) 14 | x1 > x2 = False 15 16 prop_InsertOrderedInt :: Integer -> [Integer] -> Property 17 prop_InsertOrderedInt x xs = ordered xs ==> 18 null xs `trivial` 19 ordered (insertOrdered x xs []) 20 21 orderedList :: (Ord a, Arbitrary a) => Gen [a] 22 orderedList = 23 frequency [(1,return []), 24 (4,do xs <- orderedList 25 n <- arbitrary 26 return ((case xs of 27 [] -> n 28 x:_ -> n `min` x) 29 :xs))] |
testQual3.hs |
Codebeispiel 13
01 collect <expression>$ <property>
|
collecting_data_values.hs |
Codebeispiel 14
01 import QuickCheck 02 03 insertOrdered :: (Ord a) => a -> [a] -> [a] -> [a] 04 insertOrdered a [] ys = ys++[a] 05 insertOrdered a (x:xs) ys 06 | a <= x = ys ++ a:[x] ++ xs 07 | a > x = insertOrdered a xs (ys ++ [x]) 08 09 ordered :: (Ord a) => [a] -> Bool 10 ordered [] = True 11 ordered [x] = True 12 ordered (x1:x2:xs) 13 | x1 <= x2 = True && ordered (x2:xs) 14 | x1 > x2 = False 15 16 17 prop_InsertOrderedInt :: Integer -> [Integer] -> Property 18 prop_InsertOrderedInt x xs = ordered xs ==> 19 collect (length xs)$ 20 ordered (insertOrdered x xs []) 21 22 prop_InsertOrderedInt2 :: Integer -> Property 23 prop_InsertOrderedInt2 x = forAll orderedList $ \ xs -> 24 collect (length xs)$ 25 ordered (insertOrdered x xs []) 26 27 orderedList :: (Ord a, Arbitrary a) => Gen [a] 28 orderedList = 29 frequency [(1,return []), 30 (4,do xs <- orderedList 31 n <- arbitrary 32 return ((case xs of 33 [] -> n 34 x:_ -> n `min` x) 35 :xs))] 36 37 |
testQual4.hs |
Codebeispiel 15
01 import QuickCheck 02 03 insertOrdered :: (Ord a) => a -> [a] -> [a] -> [a] 04 insertOrdered a [] ys = ys++[a] 05 insertOrdered a (x:xs) ys 06 | a <= x = ys ++ a:[x] ++ xs 07 | a > x = insertOrdered a xs (ys ++ [x]) 08 09 ordered :: (Ord a) => [a] -> Bool 10 ordered [] = True 11 ordered [x] = True 12 ordered (x1:x2:xs) 13 | x1 <= x2 = True && ordered (x2:xs) 14 | x1 > x2 = False 15 16 prop_InsertOrderedInt :: Integer -> [Integer] -> Property 17 prop_InsertOrderedInt x xs = ordered xs ==> 18 collect (length xs)$ 19 classify (ordered (x:xs)) "at-head"$ 20 classify (ordered (xs++[x])) "at-tail"$ 21 ordered (insertOrdered x xs []) 22 23 |
testQual5.hs |
Codebeispiel 16
Code generated with AusarbeitungGenerator Version 1.1, weblink