-
Notifications
You must be signed in to change notification settings - Fork 72
/
pivot_test.go
62 lines (57 loc) · 1.23 KB
/
pivot_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
// Copyright 2009 The GoMatrix Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package matrix
import "testing"
import "fmt"
func TestTimes_Pivot(t *testing.T) {
P1 := MakePivotMatrix([]int{2, 1, 0}, -1)
P2 := MakePivotMatrix([]int{2, 0, 1}, 1)
P, _ := P1.TimesPivot(P2)
if !Equals(P, Product(P1, P2)) {
if verbose {
fmt.Printf("%v\n%v\n%v\n", P1, P2, P)
}
t.Fail()
}
}
func TestRowPivot(t *testing.T) {
P := MakePivotMatrix([]int{2, 1, 0}, -1)
A := Normals(3, 4)
B, _ := P.RowPivotDense(A)
Btrue := Product(P, A)
if !Equals(B, Btrue) {
t.Fail()
}
A = Normals(4, 3)
_, err := P.RowPivotDense(A)
if err == nil {
t.Fail()
}
C := Normals(3, 4).SparseMatrix()
D, _ := P.RowPivotSparse(C)
Btrue = Product(P, C)
if !Equals(D, Btrue) {
t.Fail()
}
}
func TestColPivot(t *testing.T) {
P := MakePivotMatrix([]int{2, 1, 0}, -1)
A := Normals(4, 3)
B, _ := P.ColPivotDense(A)
Btrue := Product(A, P)
if !Equals(B, Btrue) {
t.Fail()
}
A = Normals(3, 4)
_, err := P.ColPivotDense(A)
if err == nil {
t.Fail()
}
C := Normals(4, 3).SparseMatrix()
D, _ := P.ColPivotSparse(C)
Btrue = Product(C, P)
if !Equals(D, Btrue) {
t.Fail()
}
}