/
table_test.go
63 lines (57 loc) · 1.98 KB
/
table_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
// Copyright 2015 Michael Shields
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package saseat_test
import (
"math"
"reflect"
"testing"
"msrl.com/hacks/saseat"
)
func TestScoring(t *testing.T) {
table := saseat.NewTable(8)
table.Left[0] = saseat.Guest{"Abe", "male"}
table.Left[1] = saseat.Guest{"Mary", "female"}
table.Left[2] = saseat.Guest{"Jane", "female"}
table.Right[0] = saseat.Guest{"Alexander", "male"}
table.Right[1] = saseat.Guest{"Kang", ""}
table.Right[2] = saseat.Guest{"Mx. Jones", ""}
table.Right[3] = saseat.Guest{"Kong", "ape"}
expectedTableScore := saseat.CapacityPref*math.Expm1(1) + saseat.ImbalancePref*math.Expm1(1)
prefs := saseat.Prefs{}
prefs.Set("Abe", "Mary", 1000)
prefs.Set("Kang", "Jane", -80)
prefs.Set("Alexander", "Jane", 50)
expectedLeft := []float64{
1000 * saseat.AdjacentWeight,
1000*saseat.AdjacentWeight + saseat.SameGenderPref,
-80*saseat.DiagonalWeight + 50*saseat.SameTableWeight + saseat.SameGenderPref,
0,
}
expectedRight := []float64{
50 * saseat.SameTableWeight,
-80 * saseat.DiagonalWeight,
0,
0,
}
table.Rescore(prefs)
if table.TableScore != expectedTableScore {
t.Errorf("got table score %v, want %v", table.TableScore, expectedTableScore)
}
if !reflect.DeepEqual(table.LeftScores, expectedLeft) {
t.Errorf("got left prefs %v, want %v", table.LeftScores, expectedLeft)
}
if !reflect.DeepEqual(table.RightScores, expectedRight) {
t.Errorf("got right prefs %v, want %v", table.RightScores, expectedRight)
}
}