-
Notifications
You must be signed in to change notification settings - Fork 2
/
determinant_test.go
127 lines (116 loc) · 2.04 KB
/
determinant_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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package matrix_test
import (
"testing"
"github.com/EclesioMeloJunior/matrix"
"github.com/stretchr/testify/assert"
)
func TestDeterminantsOfManyMatrix(t *testing.T) {
testCases := []struct {
m matrix.Matrix
exepected int64
}{
{
m: matrix.Matrix([][]int64{
{8, 14},
{6, 13},
}),
exepected: 20,
},
{
m: matrix.Matrix([][]int64{
{2, 1, 2},
{3, 4, 5},
{6, 7, 4},
}),
exepected: -26,
},
{
m: matrix.Matrix([][]int64{
{2, 1, 2, 4},
{3, 4, 1, 1},
{6, 7, 4, 2},
{1, 1, 2, 4},
}),
exepected: 32,
},
}
for _, tcase := range testCases {
v, err := tcase.m.Determinant()
assert.NoError(t, err)
assert.Equal(t, tcase.exepected, v)
}
}
func TestGetDeterminant3x3Subset(t *testing.T) {
m := matrix.Matrix([][]int64{
{1, 2, 4},
{3, 8, 14},
{2, 6, 13},
})
s := matrix.GetDeterminantSubset(&m, 0)
expected := matrix.Matrix([][]int64{
{8, 14},
{6, 13},
})
assert.Equal(t, &expected, s)
s = matrix.GetDeterminantSubset(&m, 1)
expected = matrix.Matrix([][]int64{
{3, 14},
{2, 13},
})
assert.Equal(t, &expected, s)
s = matrix.GetDeterminantSubset(&m, 2)
expected = matrix.Matrix([][]int64{
{3, 8},
{2, 6},
})
assert.Equal(t, &expected, s)
}
func TestGetDeterminant4x4Subset(t *testing.T) {
m := matrix.Matrix([][]int64{
{1, 2, 4, 5},
{3, 8, 14, 6},
{2, 6, 13, 0},
{2, 90, 53, 10},
})
testCases := []struct {
column int
expected matrix.Matrix
}{
{
column: 0,
expected: matrix.Matrix([][]int64{
{8, 14, 6},
{6, 13, 0},
{90, 53, 10},
}),
},
{
column: 1,
expected: matrix.Matrix([][]int64{
{3, 14, 6},
{2, 13, 0},
{2, 53, 10},
}),
},
{
column: 2,
expected: matrix.Matrix([][]int64{
{3, 8, 6},
{2, 6, 0},
{2, 90, 10},
}),
},
{
column: 3,
expected: matrix.Matrix([][]int64{
{3, 8, 14},
{2, 6, 13},
{2, 90, 53},
}),
},
}
for _, tcase := range testCases {
s := matrix.GetDeterminantSubset(&m, tcase.column)
assert.Equal(t, &tcase.expected, s)
}
}