-
Notifications
You must be signed in to change notification settings - Fork 10
/
element_test.go
66 lines (61 loc) · 1.48 KB
/
element_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
64
65
66
package rankdb_test
// Copyright 2019 Vivino. All rights reserved
//
// See LICENSE file for license details
import (
"testing"
"time"
"unsafe"
"github.com/Vivino/rankdb"
)
func TestElement_Size(t *testing.T) {
var info rankdb.Element
const infoSize = unsafe.Sizeof(info)
t.Log(infoSize)
}
func TestElement_Above(t *testing.T) {
testSet := []struct {
// a.Above(b)
a, b rankdb.Element
want bool
}{{
a: rankdb.Element{Score: 100},
b: rankdb.Element{Score: 50},
want: true,
}, {
a: rankdb.Element{Score: 50},
b: rankdb.Element{Score: 100},
want: false,
}, {
a: rankdb.Element{TieBreaker: 50},
b: rankdb.Element{TieBreaker: 100},
want: false,
}, {
a: rankdb.Element{TieBreaker: 100},
b: rankdb.Element{TieBreaker: 50},
want: true,
}, {
a: rankdb.Element{Updated: uint32(time.Now().Unix())},
b: rankdb.Element{Updated: uint32(time.Now().Add(-time.Hour).Unix())},
want: false,
}, {
a: rankdb.Element{Updated: uint32(time.Now().Add(-time.Hour).Unix())},
b: rankdb.Element{Updated: uint32(time.Now().Unix())},
want: true,
}, {
a: rankdb.Element{ID: 100},
b: rankdb.Element{ID: 10},
want: false,
}, {
a: rankdb.Element{ID: 10},
b: rankdb.Element{ID: 100},
want: true,
}}
for i, test := range testSet {
if got := test.a.Above(test.b); got != test.want {
t.Errorf("test %d, '%+v' Above '%+v'. Got %t, want %t", i, test.a, test.b, got, test.want)
} else {
t.Logf("test %d ok", i)
}
}
}