-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweighted-sum_test.go
38 lines (35 loc) · 998 Bytes
/
weighted-sum_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
package weighted_sum
import (
"github.com/Azbesciak/RealDecisionMaker/lib/model"
"github.com/Azbesciak/RealDecisionMaker/lib/utils"
"testing"
)
func TestValidFunc(t *testing.T) {
criteria := model.WeightedCriteria{{
model.Criterion{Id: "Cost", Type: model.Cost}, 1,
}, {
model.Criterion{Id: "Color", Type: model.Gain}, 2,
}}
alternative := model.AlternativeWithCriteria{
Id: "Ferrari",
Criteria: model.Weights{
"Cost": 200,
"Color": 10,
},
}
res := WeightedSum(alternative, criteria)
if !utils.FloatsAreEqual(-190.0, res.Value(), 0.01) {
t.Error("invalid result", res.Value())
}
}
func TestMissingCriterion(t *testing.T) {
criteria := model.WeightedCriteria{{model.Criterion{Id: "Color", Type: model.Gain}, 1}}
var alternative = model.AlternativeWithCriteria{
Id: "Ferrari",
Criteria: model.Weights{
"Cost": 200,
},
}
defer utils.ExpectError(t, "alternative 'Ferrari' does not have value for criterion 'Color'")()
WeightedSum(alternative, criteria)
}