Skip to content
This repository
Browse code

better test coverage, including the newly discovered [x..] bug

  • Loading branch information...
commit f838e5f4e4d74d68e86fb0be474faa4bb02bc6b4 1 parent 130dbd6
Barak A. Pearlmutter authored April 16, 2009

Showing 2 changed files with 60 additions and 4 deletions. Show diff stats Hide diff stats

  1. 13  Numeric/FAD.hs
  2. 51  Test.hs
13  Numeric/FAD.hs
@@ -97,6 +97,7 @@ import Data.Function (on)
97 97
 --  Add pointers into literature
98 98
 --  Fix complex number issues (requires changes to standard prelude)
99 99
 --  Optimize for efficiency
  100
+--  Address [x..] bug, see below
100 101
 
101 102
 -- Notes:
102 103
 
@@ -462,6 +463,18 @@ instance (Eq a, Num a) => Eq (Tower tag a) where
462 463
 instance (Ord a, Num a) => Ord (Tower tag a) where
463 464
     compare	= liftA2disc compare
464 465
 
  466
+
  467
+
  468
+{-
  469
+  The [x..] bug:
  470
+
  471
+  > diff (\x->[x]   !! 0) 7
  472
+  1                                   -- Correct
  473
+
  474
+  > diff (\x->[x..] !! 0) 7
  475
+  0                                   -- Incorrect!
  476
+-}
  477
+
465 478
 instance (Enum a, Num a) => Enum (Tower tag a) where
466 479
     succ	= liftA1 succ (const 1)
467 480
     pred	= liftA1 pred (const 1)
51  Test.hs
@@ -131,6 +131,8 @@ taylor2_accurate f nx ny x y dx dy =
131 131
             &&
132 132
       f2 (x+dx) (y+dy) ~= s2 !! nx !! ny
133 133
 
  134
+id_c c x = if x==c then c else x
  135
+
134 136
 -- Test all properties.
135 137
 main = do
136 138
   quickCheck prop_is1
@@ -143,28 +145,69 @@ main = do
143 145
   onceCheck  prop_zeroNewton_1
144 146
   onceCheck  prop_zeroNewton_2
145 147
   onceCheck  prop_inverseNewton
146  
-  quickCheck prop_atan2_shouldBeOne
147  
-  onceCheck  $ prop_atan2_shouldBeOne (pi/2)
148 148
   onceCheck prop_diffs_1
149 149
   onceCheck prop_diffs_2
150 150
   onceCheck prop_diffs_3
151 151
   onceCheck prop_diffs_4
152 152
   onceCheck  $ prop_diffs_5 1024
  153
+  -- (+)
153 154
   quickCheck $ \x -> taylor_accurate_p (+(lift x))         1 (-1e9) 1e9
154 155
   quickCheck $ \x -> taylor_accurate_p ((lift x)+)         1 (-1e9) 1e9
  156
+  -- (-)
155 157
   quickCheck $ \x -> taylor_accurate_p (flip (-) (lift x)) 1 (-1e9) 1e9
156 158
   quickCheck $ \x -> taylor_accurate_p ((lift x)-)         1 (-1e9) 1e9
  159
+  -- (*)
157 160
   quickCheck $ \x -> taylor_accurate_p (*(lift x))         1 (-1e9) 1e9
158 161
   quickCheck $ \x -> taylor_accurate_p ((lift x)*)         1 (-1e9) 1e9
  162
+  -- abs
159 163
   quickCheck $ taylor_accurate_p abs 1 (-1) 1e9 1
160 164
   quickCheck $ taylor_accurate_p abs 1 (-1e9) 1 (-1)
  165
+  -- recip
161 166
   quickCheck $ taylor_accurate_p recip 12 (-50) 50 200
162 167
   quickCheck $ taylor_accurate_p recip 12 (-50) 50 (-200)
  168
+  -- negate
163 169
   quickCheck $ taylor_accurate_p negate 1 (-1e9) 1e9
  170
+  -- pi
  171
+  onceCheck  $ diffs (const pi) 17 == [pi]
  172
+  -- exp
164 173
   quickCheck $ taylor_accurate_p exp 40 (-4) 4
165  
-  onceCheck  $ taylor_accurate   sin 40 0 (2*pi)
166  
-  quickCheck $ taylor_accurate_p sin 40 (-2.5*pi) (2.5*pi)
  174
+  -- sqrt
167 175
   quickCheck $ taylor_accurate_p sqrt 10 (-1) 1 10
  176
+  -- log
168 177
   quickCheck $ taylor_accurate_p log 10 (-1) 1 (exp 2)
  178
+  -- (**)
169 179
   quickCheck $ taylor_accurate_p (**2.5) 12 (-0.5) 1 3
170 180
   quickCheck $ taylor_accurate_p (2.5**) 12 (-0.5) 1 3
  181
+  -- sin
  182
+  onceCheck  $ taylor_accurate   sin 40 0 (2*pi)
  183
+  quickCheck $ taylor_accurate_p sin 40 (-2.5*pi) (2.5*pi)
  184
+  -- cos
  185
+  onceCheck  $ taylor_accurate   cos 40 0 (2*pi)
  186
+  quickCheck $ taylor_accurate_p cos 40 (-2.5*pi) (2.5*pi)
  187
+  -- asin
  188
+  quickCheck $ taylor_accurate_p (asin . sin) 10 (-0.9) (0.9) 0.1
  189
+  -- acos
  190
+  quickCheck $ taylor_accurate_p (acos . cos) 10 (-1) 1 (pi/3)
  191
+  -- atan
  192
+  quickCheck $ taylor_accurate_p (atan . tan) 10 (-1) 1 0.1
  193
+  -- sinh
  194
+  quickCheck $ taylor_accurate_p sinh 40 (-5) 5 0.1
  195
+  -- cosh
  196
+  quickCheck $ taylor_accurate_p cosh 40 (-5) 5 0.1
  197
+  -- tanh ?
  198
+  -- asinh
  199
+  onceCheck  $ taylor_accurate asinh 15 0.1 0.3
  200
+  -- acosh
  201
+  onceCheck  $ taylor_accurate acosh 15 2 0.2
  202
+  -- atanh
  203
+  onceCheck  $ taylor_accurate atanh 15 0.1 0.2
  204
+  -- atan2
  205
+  quickCheck prop_atan2_shouldBeOne
  206
+  onceCheck  $ prop_atan2_shouldBeOne (pi/2)
  207
+  -- (==)
  208
+  onceCheck  $ diffs (id_c 7) 3 == [3,1]
  209
+  onceCheck  $ diffs (id_c 7) 7 == [7]
  210
+  -- The [x..] bug:
  211
+  onceCheck          $ diff (\x->[x]   !! 0) 7 == 1
  212
+  --BUG-- onceCheck  $ diff (\x->[x..] !! 0) 7 == 1     -- actually returns 0
  213
+  --BUG-- onceCheck  $ diff (\x->[0,x..] !! 2) 13 == 26 -- actually returns 0

0 notes on commit f838e5f

Please sign in to comment.
Something went wrong with that request. Please try again.