-
Notifications
You must be signed in to change notification settings - Fork 0
/
equal_test.go
88 lines (79 loc) · 3.15 KB
/
equal_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
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2023 thorstenrie
// All rights reserved. Use is governed with GNU Affero General Public License v3.0
// that can be found in the LICENSE file.
package lpstats_test
// Import package testing and tserr
import (
"testing" // testing
"github.com/thorstenrie/lpstats"
"github.com/thorstenrie/tserr" // tserr
)
// TestNEf tests NearEqual to return false for a difference of a and b greater than the
// provided maximum difference. It fails if NearEqual returns true.
func TestNEf(t *testing.T) {
if lpstats.NearEqual(0.01, 0.03, -0.01) {
t.Error(tserr.Return(&tserr.ReturnArgs{Op: "NearEqual", Actual: "true", Want: "false"}))
}
}
// TestNEe tests NearEqual to return true for a difference of a and b equal to the
// provided maximum difference. It fails if NearEqual returns false.
func TestNEe(t *testing.T) {
if !lpstats.NearEqual(0.01, 0.02, -0.01) {
t.Error(tserr.Return(&tserr.ReturnArgs{Op: "NearEqual", Actual: "false", Want: "true"}))
}
}
// TestNEt tests NearEqual to return true for a difference of a and b lower than the
// provided maximum difference. It fails if NearEqual returns false.
func TestNEt(t *testing.T) {
if !lpstats.NearEqual(0.01, 0.02, -0.02) {
t.Error(tserr.Return(&tserr.ReturnArgs{Op: "NearEqual", Actual: "false", Want: "true"}))
}
}
// TestESl tests EqualS for two slices of integers with different length.
// The test fails, if EqualS returns nil.
func TestESl(t *testing.T) {
// Allocate and initialize int slices y1 and y2 with different lengths sLen and sLen-1
y1, y2 := make([]int, sLen), make([]int, sLen-1)
// The test fails, if EqualS returns nil
if e := lpstats.EqualS(y1, y2); e == nil {
t.Error(tserr.NilFailed("EqualS"))
}
}
// TestESv tests EqualS for two slices of integers with different values.
// The test fails, if EqualS returns nil.
func TestESv(t *testing.T) {
// Allocate and initialize int slices y1 and y2 with length sLen
y1, y2 := make([]int, sLen), make([]int, sLen)
// Set y1 and y2 last value to different values 1 and 2
y1[sLen-1], y2[sLen-1] = 1, 2
// The test fails, if EqualS returns nil
if e := lpstats.EqualS(y1, y2); e == nil {
t.Error(tserr.NilFailed("EqualS"))
}
}
// TestESn tests EqualS for nil slices of integers.
// The test fails, if EqualS returns nil.
func TestESn(t *testing.T) {
// Allocate and initialize int slice y1 with length sLen and set int slice y2 to nil
var y1, y2 []int = make([]int, sLen), nil
// The test fails, if EqualS returns nil
if e := lpstats.EqualS(y1, y2); e == nil {
t.Error(tserr.NilFailed("EqualS"))
}
// The test fails, if EqualS returns nil
if e := lpstats.EqualS(y2, y1); e == nil {
t.Error(tserr.NilFailed("EqualS"))
}
}
// TestES tests EqualS for two slices of integers with same the length and the same values.
// The test fails, if EqualS returns an error.
func TestES(t *testing.T) {
// Allocate and initialize int slices y1 and y2 with length sLen
y1, y2 := make([]int, sLen), make([]int, sLen)
// Set y1 and y2 last value to the same value 1
y1[sLen-1], y2[sLen-1] = 1, 1
// The test fails, if EqualS returns an error
if e := lpstats.EqualS(y1, y2); e != nil {
t.Error(tserr.Op(&tserr.OpArgs{Op: "EqualS", Fn: "y1 and y2", Err: e}))
}
}