-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRealVector_test.go
100 lines (86 loc) · 2.27 KB
/
RealVector_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
89
90
91
92
93
94
95
96
97
98
99
100
package LinearAlgebra
import (
"fmt"
"testing"
)
func TestPrint(t *testing.T) {
var tests = []struct {
a *RealVector
}{
{&RealVector{[]float64{0,0,0}}},
{&RealVector{[]float64{1,-1,0}}},
{&RealVector{[]float64{0.5, 4.2, 5.5}}},
}
for _, tt := range tests {
testname := fmt.Sprintf("%s", tt.a)
t.Run(testname, func(t *testing.T) {
t.Logf("%s", tt.a)
})
}
}
func TestEqual(t *testing.T) {
var tests = []struct {
a *RealVector
b *RealVector
c bool
}{
{&RealVector{[]float64{0,0,0}},&RealVector{[]float64{0,0,0}}, true},
{&RealVector{[]float64{1,-1,0}},&RealVector{[]float64{1,1,0}}, false},
{&RealVector{[]float64{0.5, 4.2, 5.5}},&RealVector{[]float64{0.5,4.2,5.5}}, true},
}
for _, tt := range tests {
testname := fmt.Sprintf("%s, %s", tt.a, tt.b)
t.Run(testname, func(t *testing.T) {
eql := tt.a.Equal(tt.b)
if eql != tt.c {
t.Errorf("got %t, want %t", eql, tt.c)
}
})
}
}
func TestAdd(t *testing.T) {
var tests = []struct {
a *RealVector
b *RealVector
c *RealVector
}{
{&RealVector{[]float64{0,0,0}},&RealVector{[]float64{0,0,0}},&RealVector{[]float64{0,0,0}}},
{&RealVector{[]float64{1,1,0}},&RealVector{[]float64{0,0,1}},&RealVector{[]float64{1,1,1}}},
{&RealVector{[]float64{0.5,20,500}},&RealVector{[]float64{0.7,0.6,70}},&RealVector{[]float64{1.2,20.6,570}}},
}
for _, tt := range tests {
testname := fmt.Sprintf("%s,%s", tt.a, tt.b)
t.Run(testname, func(t *testing.T) {
ans,err := tt.a.Add(tt.b)
if err != nil {
t.Errorf("ans is nil")
}
if !ans.Equal(tt.c) {
t.Errorf("got %s, want %s", ans, tt.c)
}
})
}
}
func TestMinus(t *testing.T) {
var tests = []struct {
a *RealVector
b *RealVector
c *RealVector
}{
{&RealVector{[]float64{0,0,0}},&RealVector{[]float64{0,0,0}},&RealVector{[]float64{0,0,0}}},
{&RealVector{[]float64{1,1,0}},&RealVector{[]float64{1,0,1}},&RealVector{[]float64{0,1,-1}}},
{&RealVector{[]float64{0.5,20,500}},&RealVector{[]float64{0.7,0.6,70}},&RealVector{[]float64{-0.2,19.4,430}}},
}
for _, tt := range tests {
testname := fmt.Sprintf("%s,%s", tt.a, tt.b)
t.Run(testname, func(t *testing.T) {
ans,err := tt.a.Minus(tt.b)
if err != nil {
t.Errorf("ans is nil")
}
if !ans.Equal(tt.c) {
t.Errorf("got %s, want %s", ans, tt.c)
}
})
}
}