forked from drewwells/stat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
77 lines (64 loc) · 1.97 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package stat
/* main_test.go
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Jim Davies, Brian Gough
* Copyright (C) 2012, 2013 G.vd.Schoot
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import (
"fmt"
"math"
"os"
"testing"
)
func gsl_test(status bool, test_description string, a ...interface{}) {
if status == true {
s := fmt.Sprintf(test_description, a...)
fmt.Printf("FAIL: %s\n", s)
os.Exit(1)
}
}
func gsl_test_rel(result, expected, relative_error float64, test_description string, a ...interface{}) {
var status bool
// Check for NaN vs inf vs number
if math.IsNaN(result) || math.IsNaN(expected) {
status = math.IsNaN(result) != math.IsNaN(expected)
} else if math.IsInf(result, 0) || math.IsInf(expected, 0) {
status = math.IsInf(result, 0) != math.IsInf(expected, 0)
} else if expected != 0 {
status = math.Abs(result-expected)/math.Abs(expected) > relative_error
} else {
status = math.Abs(result) > relative_error
}
if status == true {
s := fmt.Sprintf(test_description, a...)
fmt.Printf("FAIL: %s (%f observed vs %g expected)\n",
s, result, expected)
os.Exit(1)
}
}
// Main test routine
func TestMain(t *testing.T) {
for s1 := 1; s1 < 4; s1++ {
s2 := 1
if s1 >= 3 {
s2 = s1 - 1
}
testFloat64Slice(t, s1, s2)
testIntSlice(t, s1, s2)
}
testNist()
}