-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalue_test.go
50 lines (44 loc) · 1.22 KB
/
value_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
// Copyright 2019 GRAIL, Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package diviner_test
import (
"testing"
"github.com/grailbio/diviner"
)
func TestValue(t *testing.T) {
if diviner.Int(1) != diviner.Int(1) {
t.Error("integers not comparable")
}
if diviner.Float(12.3) != diviner.Float(12.3) {
t.Error("floats not comparable")
}
if diviner.String("xyz") != diviner.String("xyz") {
t.Error("strings not comparable")
}
}
func TestList(t *testing.T) {
l1 := diviner.List{diviner.Int(10), diviner.Int(20)}
l2 := diviner.List{diviner.Int(5), diviner.Int(20)}
if l1.Less(l1) {
t.Error("l1.Less(l1)")
}
if !l2.Less(l1) {
t.Error("expected l2.Less(l1)")
}
}
func TestHash(t *testing.T) {
for i, test := range []struct {
val diviner.Value
hash uint64
}{
{diviner.List{diviner.Int(10), diviner.Int(20)}, 1283048665539793019},
{diviner.Int(10), 16038372209008516879},
{diviner.Float(0.3), 4912920084111300745},
{diviner.String("okay"), 3625577695725878441},
} {
if got, want := diviner.Hash(test.val), test.hash; got != want {
t.Errorf("test %d: wrong hash for value %s: got %v, want %v", i, test.val, got, want)
}
}
}