]> Git — Sourcephile - haskell/interval.git/blob - Data/Interval/Test.hs
Remove redundant Ord constraints.
[haskell/interval.git] / Data / Interval / Test.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE ScopedTypeVariables #-}
3 module Test where
4
5 import Data.Function (($), (.))
6 import qualified Data.List as List
7 import Data.Maybe (Maybe(..), fromJust)
8 import Data.Monoid ((<>))
9 import Data.Ord (Ordering(..))
10 import Prelude (Integer)
11 import System.IO (IO)
12 import Test.Tasty
13 import Test.Tasty.HUnit
14 import Text.Show (Show(..))
15
16 import qualified Data.Interval as Interval
17 import qualified Sieve.Test as Sieve
18
19 main :: IO ()
20 main =
21 defaultMain $
22 testGroup "Interval"
23 [ testGroup "position" $
24 List.concatMap
25 (\(mi, mj, p) ->
26 let i = fromJust mi in
27 let j = fromJust mj in
28 let (le, ge) =
29 case p of
30 Interval.Equal -> (EQ, EQ)
31 _ -> (LT, GT) in
32 [ testCase ((show . Interval.Pretty) i <> " " <> (show . Interval.Pretty) j) $
33 Interval.position i j @?= (p, le)
34 , testCase ((show . Interval.Pretty) j <> " " <> (show . Interval.Pretty) i) $
35 Interval.position j i @?= (p, ge)
36 ]
37 )
38 [ ( (Interval.<..<) 0 (4::Integer)
39 , (Interval.<..<) 5 9
40 , Interval.Away )
41 , ( (Interval.<..<) 0 4
42 , (Interval.<=..<) 4 9
43 , Interval.Adjacent )
44 , ( (Interval.<..<) 0 5
45 , (Interval.<..<) 4 9
46 , Interval.Overlap )
47 , ( (Interval.<..<) 0 5
48 , (Interval.<..<) 0 9
49 , Interval.Prefix )
50 , ( (Interval.<..<) 0 9
51 , (Interval.<..<) 1 8
52 , Interval.Include )
53 , ( (Interval.<..<) 0 9
54 , (Interval.<..<) 5 9
55 , Interval.Suffixed )
56 , ( (Interval.<..<) 0 9
57 , (Interval.<..<) 0 9
58 , Interval.Equal )
59 , ( (Interval.<..<) 0 9
60 , (Interval.<..<=) 0 9
61 , Interval.Prefix )
62 , ( (Interval.<=..<) 0 9
63 , (Interval.<..<) 0 9
64 , Interval.Suffixed )
65 , ( (Interval.<=..<=) 0 9
66 , (Interval.<..<) 0 9
67 , Interval.Include )
68 ]
69 , testGroup "intersection" $
70 List.concatMap
71 (\(mi, mj, e) ->
72 let i = fromJust mi in
73 let j = fromJust mj in
74 [ testCase ((show . Interval.Pretty) i <> " " <> (show . Interval.Pretty) j) $
75 Interval.intersection i j @?= e
76 , testCase ((show . Interval.Pretty) j <> " " <> (show . Interval.Pretty) i) $
77 Interval.intersection j i @?= e
78 ]
79 )
80 [ ( (Interval.<..<) 0 (4::Integer)
81 , (Interval.<..<) 5 9
82 , Nothing )
83 , ( (Interval.<..<=) 0 5
84 , (Interval.<=..<) 5 9
85 , (Interval.<=..<=) 5 5 )
86 , ( (Interval.<..<) 0 6
87 , (Interval.<..<) 4 9
88 , (Interval.<..<) 4 6 )
89 , ( (Interval.<..<=) 0 6
90 , (Interval.<=..<) 4 9
91 , (Interval.<=..<=) 4 6 )
92 , ( (Interval.<..<) 0 6
93 , (Interval.<=..<) 4 9
94 , (Interval.<=..<) 4 6 )
95 , ( (Interval.<..<=) 0 6
96 , (Interval.<..<) 4 9
97 , (Interval.<..<=) 4 6 )
98 , ( (Interval.<..<) 0 9
99 , (Interval.<..<) 0 9
100 , (Interval.<..<) 0 9 )
101 , ( (Interval.<=..<) 0 9
102 , (Interval.<..<=) 0 9
103 , (Interval.<..<) 0 9 )
104 , ( (Interval.<..<=) 0 9
105 , (Interval.<=..<) 0 9
106 , (Interval.<..<) 0 9 )
107 , ( (Interval.<=..<=) 0 9
108 , (Interval.<=..<=) 0 9
109 , (Interval.<=..<=) 0 9 )
110 ]
111 , testGroup "union" $
112 List.concatMap
113 (\(mi, mj, e) ->
114 let i = fromJust mi in
115 let j = fromJust mj in
116 [ testCase ((show . Interval.Pretty) i <> " " <> (show . Interval.Pretty) j) $
117 Interval.union i j @?= e
118 , testCase ((show . Interval.Pretty) j <> " " <> (show . Interval.Pretty) i) $
119 Interval.union j i @?= e
120 ]
121 )
122 [ ( (Interval.<..<) 0 (4::Integer)
123 , (Interval.<..<) 5 9
124 , Nothing )
125 , ( (Interval.<..<=) 0 5
126 , (Interval.<..<) 5 9
127 , (Interval.<..<) 0 9 )
128 , ( (Interval.<..<) 0 5
129 , (Interval.<=..<) 5 9
130 , (Interval.<..<) 0 9 )
131 , ( (Interval.<..<=) 0 5
132 , (Interval.<=..<) 5 9
133 , (Interval.<..<) 0 9 )
134 , ( (Interval.<..<) 0 6
135 , (Interval.<..<) 4 9
136 , (Interval.<..<) 0 9 )
137 , ( (Interval.<..<) 0 9
138 , (Interval.<..<) 0 9
139 , (Interval.<..<) 0 9 )
140 , ( (Interval.<=..<) 0 9
141 , (Interval.<..<=) 0 9
142 , (Interval.<=..<=) 0 9 )
143 , ( (Interval.<..<=) 0 9
144 , (Interval.<=..<) 0 9
145 , (Interval.<=..<=) 0 9 )
146 , ( (Interval.<=..<=) 0 9
147 , (Interval.<=..<=) 0 9
148 , (Interval.<=..<=) 0 9 )
149 ]
150 , Sieve.tests
151 ]