Skip to content

Commit dc646b5

Browse files
committed
Changed how ObjSense is represented to make it easier to print
1 parent c1650df commit dc646b5

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

problem/objective_sense.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package problem
22

3-
import "github.com/MatProGo-dev/MatProInterface.go/optim"
3+
import (
4+
"github.com/MatProGo-dev/MatProInterface.go/optim"
5+
)
46

57
// ObjSense represents whether an optimization objective is to be maximized or
68
// minimized. This implementation conforms to the Gurobi encoding
7-
type ObjSense int
9+
type ObjSense string
810

911
// Objective senses (minimize and maximize) encoding using Gurobi's standard
1012
const (
11-
SenseMinimize ObjSense = 1
12-
SenseMaximize = -1
13-
SenseFind ObjSense = 0
13+
SenseMinimize ObjSense = "Minimize"
14+
SenseMaximize = "Maximize"
15+
SenseFind ObjSense = "Find"
1416
)
1517

1618
/*

testing/problem/objective_sense_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package problem_test
22

33
import (
4+
"fmt"
5+
"testing"
6+
47
"github.com/MatProGo-dev/MatProInterface.go/optim"
58
"github.com/MatProGo-dev/MatProInterface.go/problem"
6-
"testing"
79
)
810

911
/*
@@ -52,3 +54,39 @@ func TestObjectiveSense_ToObjSense2(t *testing.T) {
5254
problem.SenseMaximize, objSense)
5355
}
5456
}
57+
58+
/*
59+
TestObjectiveSense_String1
60+
Description:
61+
62+
Tests that we can extract strings from the three normal ObjSense values
63+
(Minimize, Maximize, Find).
64+
*/
65+
func TestObjectiveSense_String1(t *testing.T) {
66+
// Test Minimize
67+
minSense := problem.SenseMinimize
68+
if fmt.Sprintf("%v", minSense) != "Minimize" {
69+
t.Errorf(
70+
"minSense's string is \"%v\"; expected \"Minimize\"",
71+
minSense,
72+
)
73+
}
74+
75+
// Test Maximize
76+
maxSense := problem.SenseMaximize
77+
if fmt.Sprintf("%v", maxSense) != "Maximize" {
78+
t.Errorf(
79+
"maxSense's string is \"%v\"; expected \"Maximize\"",
80+
maxSense,
81+
)
82+
}
83+
84+
// Test Find
85+
findSense := problem.SenseFind
86+
if fmt.Sprintf("%v", findSense) != "Find" {
87+
t.Errorf(
88+
"findSense's string is \"%v\"; expected \"Find\"",
89+
findSense,
90+
)
91+
}
92+
}

0 commit comments

Comments
 (0)