-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimplex_test.go
57 lines (43 loc) · 1.23 KB
/
simplex_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
package simplex
import (
"testing"
"gonum.org/v1/gonum/mat"
)
func TestSimplex1(t *testing.T) {
// create new example matrix
maximize := mat.NewVecDense(3, []float64{5, 4, 3})
constraints := mat.NewDense(3, 4, []float64{
2, 3, 1, 5,
4, 1, 2, 11,
3, 4, 2, 8})
actualResult := Solve(maximize, constraints)
var expectedResult float64 = 13
if actualResult != expectedResult {
t.Fatalf("Expected %f but got %f", expectedResult, actualResult)
}
}
func TestSimplex2(t *testing.T) {
// create new example matrix
maximize := mat.NewVecDense(4, []float64{6, -9, 1, -11})
constraints := mat.NewDense(2, 5, []float64{
2, -3, -1, -7, 1,
2, 1, 1, 3, 3})
actualResult := Solve(maximize, constraints)
var expectedResult float64 = 7
if actualResult != expectedResult {
t.Fatalf("Expected %f but got %f", expectedResult, actualResult)
}
}
func TestSimplex3(t *testing.T) {
// create new example matrix
maximize := mat.NewVecDense(3, []float64{2, 3, 2})
constraints := mat.NewDense(3, 4, []float64{
1, 1, 0, 8,
0, 1, 2, 12,
0, 1, 1, 7})
actualResult := Solve(maximize, constraints)
var expectedResult float64 = 28
if actualResult != expectedResult {
t.Fatalf("Expected %f but got %f", expectedResult, actualResult)
}
}