1 import HackageBenchmark
2 import Statistics
.Types
(mkPValue
)
3 import Test
.Tasty
(TestTree
, defaultMain
, testGroup
)
4 import Test
.Tasty
.HUnit
(assertBool
, testCase
, (@?
=))
7 main
= defaultMain tests
10 tests
= testGroup
"unit tests" [
12 testGroup
"isSignificantTimeDifference" [
14 testCase
"detect increase in distribution" $ assertBool
"" $
15 isSignificantTimeDifference
(mkPValue
0.05) [1,2..7] [4,5..10]
17 , testCase
"detect decrease in distribution" $ assertBool
"" $
18 isSignificantTimeDifference
(mkPValue
0.05) [1,2..7] [-2,-1..4]
20 , testCase
"ignore same data" $ assertBool
"" $
21 not $ isSignificantTimeDifference
(mkPValue
0.05) [1,2..10] [1,2..10]
23 , testCase
"same data with high p-value is significant" $ assertBool
"" $
24 isSignificantTimeDifference
(mkPValue
0.9) [1,2..10] [1,2..10]
26 , testCase
"ignore outlier" $ assertBool
"" $
27 not $ isSignificantTimeDifference
(mkPValue
0.05) [1, 2, 1, 1, 1] [2, 1, 50, 1, 1]
30 , testGroup
"combineTrialResults" [
32 testCase
"convert unexpected difference to Unknown" $
33 combineTrialResults
[NoInstallPlan
, BackjumpLimit
] @?
= Unknown
35 , testCase
"return one of identical errors" $
36 combineTrialResults
[NoInstallPlan
, NoInstallPlan
] @?
= NoInstallPlan
38 , testCase
"return one of identical successes" $
39 combineTrialResults
[Solution
, Solution
] @?
= Solution
41 , testCase
"timeout overrides other results" $
42 combineTrialResults
[Solution
, Timeout
, Solution
] @?
= Timeout
44 , testCase
"convert unexpected difference to Unknown, even with timeout" $
45 combineTrialResults
[Solution
, Timeout
, NoInstallPlan
] @?
= Unknown
48 , testGroup
"isSignificantResult" [
50 testCase
"different results are significant" $ assertBool
"" $
51 isSignificantResult NoInstallPlan BackjumpLimit
53 , testCase
"unknown result is significant" $ assertBool
"" $
54 isSignificantResult Unknown Unknown
56 , testCase
"PkgNotFound is significant" $ assertBool
"" $
57 isSignificantResult PkgNotFound PkgNotFound
59 , testCase
"same expected error is not significant" $ assertBool
"" $
60 not $ isSignificantResult NoInstallPlan NoInstallPlan
62 , testCase
"success is not significant" $ assertBool
"" $
63 not $ isSignificantResult Solution Solution
66 , testGroup
"shouldContinueAfterFirstTrial" [
68 testCase
"rerun when min difference is zero" $ assertBool
"" $
69 shouldContinueAfterFirstTrial
0 1.0 1.0 Solution Solution
71 , testCase
"rerun when min difference is zero, even with timeout" $
73 shouldContinueAfterFirstTrial
0 1.0 1.0 Timeout Timeout
75 , testCase
"treat timeouts as the same time" $ assertBool
"" $
76 not $ shouldContinueAfterFirstTrial
0.000001 89.9 92.0 Timeout Timeout
78 , testCase
"skip when times are too close - 1" $ assertBool
"" $
79 not $ shouldContinueAfterFirstTrial
10 1.0 0.91 Solution Solution
81 , testCase
"skip when times are too close - 2" $ assertBool
"" $
82 not $ shouldContinueAfterFirstTrial
10 1.0 1.09 Solution Solution
84 , testCase
"rerun when times aren't too close - 1" $ assertBool
"" $
85 shouldContinueAfterFirstTrial
10 1.0 0.905 Solution Solution
87 , testCase
"rerun when times aren't too close - 2" $ assertBool
"" $
88 shouldContinueAfterFirstTrial
10 1.0 1.1 Solution Solution