Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 108 lines (98 sloc) 2.919 kb
25566e0 init
E.B authored
1 #!/usr/bin/env ruby
2 require("gsl")
3 include GSL
4
5 module GSL
6 module Test
7 Verbose = true
8 $tests = 0
9 $passed = 0
10 $failed = 0
11
12 # PASS if status == 0, FAIL otherwise
13 def test(status, desc)
14 $tests += 1
15 if status == 0
16 $passed += 1
17 printf("PASS: #{desc}\n")
18 else
19 $failed += 1
20 printf("FAIL: #{desc}\n")
21 end
22 end
23
24 # PASS if status == true, FAIL otherwise
25 def test2(status, desc)
26 if status == true
27 printf("PASS: #{desc}\n")
28 else
29 printf("FAIL: #{desc}\n")
30 end
31 end
32
33 def test_factor(result, expected, factor, desc)
34 status = nil
35 if result == expected
36 status = 0
37 elsif expected == 0.0
38 status = (result > expected or result < expected) ? 1 : 0
39 else
40 u = result/expected
41 status = (u > factor or u < 1.0/factor) ? 1 : 0
42 end
43 $tests += 1
44 if status == 0
45 $passed += 1
46 printf("PASS: #{desc} (%g observed vs %g expected)\n", result, expected)
47 else
48 $failed += 1
49 printf("FAIL: #{desc} (%.18g observed vs %.18g expected)\n", result, expected)
50 end
51 end
52
53 def test_rel(result, expected, relerr, desc)
54 status = nil
55 if isnan?(result) or isnan?(expected)
56 status = isnan?(result) != isnan?(expected) ? 1 : 0
57 elsif isinf?(result) or isinf?(expected)
58 status = isinf?(result) != isinf?(expected) ? 1 : 0
59 elsif expected.to_f != 0.0
60 status = (result - expected).abs/expected.abs > relerr ? 1 : 0
61 else
62 status = result.abs > relerr ? 1 : 0
63 end
64 $tests += 1
65 if status == 0
66 $passed += 1
67 printf("PASS: #{desc} (%g observed vs %g expected)\n", result, expected)
68 else
69 $failed += 1
70 printf("FAIL: #{desc} (%.18g observed vs %.18g expected)\n", result, expected)
71 end
72 end
73
74 def test_abs(result, expected, abserr, desc)
75 status = nil
76 if isnan?(result) or isnan?(expected)
77 status = isnan?(result) != isnan?(expected) ? 1 : 0
78 elsif isinf?(result) or isinf?(expected)
79 status = isinf?(result) != isinf?(expected) ? 1 : 0
80 else
81 status = (result - expected).abs > abserr ? 1 : 0
82 end
83 $tests += 1
84 if status == 0
85 $passed += 1
86 printf("PASS: #{desc} (%g observed vs %g expected)\n", result, expected)
87 else
88 $failed += 1
89 printf("FAIL: #{desc} (%.18g observed vs %.18g expected)\n", result, expected)
90 end
91 end
92
93 def test_int(result, expected, desc)
94 status = (result != expected) ? 1 : 0
95 $tests += 1
96 if status == 0
97 $passed += 1
98 printf("PASS: #{desc} (%d observed vs %d expected)\n", result, expected)
99 else
100 $failed += 1
101 printf("FAIL: #{desc} (%d observed vs %d expected)\n", result, expected)
102 end
103 end
104
105 end
106 end
107
Something went wrong with that request. Please try again.