Skip to content

Commit 6094001

Browse files
dmjioclaude
andcommitted
test: use shouldBeApprox for floating-point comparisons in StatisticsSpec
CUDA backend produces sub-epsilon rounding in weighted-mean, varWeighted, stdev, and corrCoef — switch those four tests to approximate equality. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0b90635 commit 6094001

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

‎test/ArrayFire/StatisticsSpec.hs‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,22 @@ spec =
2020
`shouldBe`
2121
5.5
2222
it "Should find the weighted-mean" $ do
23-
listToMaybe (toList (meanWeighted (vector @Double 10 [1..]) (vector @Double 10 [1..]) 0))
24-
`shouldBe`
25-
(Just 7.0)
23+
case listToMaybe (toList (meanWeighted (vector @Double 10 [1..]) (vector @Double 10 [1..]) 0)) of
24+
Nothing -> expectationFailure "expected Just 7.0, got Nothing"
25+
Just v -> v `shouldBeApprox` 7.0
2626
it "Should find the variance" $ do
2727
var (vector @Double 8 [1..8]) Population 0
2828
`shouldBe`
2929
5.25
3030
it "Should find the weighted variance (equal weights)" $ do
31-
varWeighted (vector @Double 8 [1..]) (vector @Double 8 (repeat 1)) 0
32-
`shouldBe`
33-
5.25
31+
head (toList (varWeighted (vector @Double 8 [1..]) (vector @Double 8 (repeat 1)) 0))
32+
`shouldBeApprox` 5.25
3433
it "Should find the weighted variance (increasing weights)" $ do
3534
head (toList (varWeighted (vector @Double 10 [1..]) (vector @Double 10 [1..]) 0))
3635
`shouldBeApprox` (21/11 :: Double)
3736
it "Should find the standard deviation" $ do
38-
stdev (vector @Double 10 (cycle [1,-1])) 0
39-
`shouldBe`
40-
1.0
37+
head (toList (stdev (vector @Double 10 (cycle [1,-1])) 0))
38+
`shouldBeApprox` 1.0
4139
it "Should find the covariance" $ do
4240
cov (vector @Double 10 (repeat 1)) (vector @Double 10 (repeat 1)) False
4341
`shouldBe`
@@ -66,7 +64,7 @@ spec =
6664
`shouldBe` 5.5
6765
it "Should find the correlation coefficient" $ do
6866
corrCoef (vector @Int 10 [1..]) (vector @Int 10 [10,9..])
69-
`shouldBe` (-1.0)
67+
`shouldBeApprox` (-1.0)
7068
it "Should find the top k elements" $ do
7169
let (vals,indexes) = topk ( vector @Double 10 [1..] ) 3 TopKDefault
7270
vals `shouldBe` vector @Double 3 [10,9,8]

0 commit comments

Comments
 (0)