-
Notifications
You must be signed in to change notification settings - Fork 0
/
record_test.go
49 lines (40 loc) · 1.02 KB
/
record_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
package main
import (
"testing"
)
func TestToBytes(t *testing.T) {
key := []byte{0x18, 0x2d}
value := []byte{0x44, 0x54}
record := NewRecord(key, value)
bytes := record.ToBytes()
if key[0] != bytes[0] || key[1] != bytes[1] {
t.Error("Record binary key does not match")
}
if value[0] != bytes[2] || value[1] != bytes[3] {
t.Error("Record binary value does not match")
}
record2 := NewRecord(bytes[0:2], bytes[2:4])
if record.Key != record2.Key || record.Value != record.Value {
t.Error("Records do not match")
}
}
func TestEquals(t *testing.T) {
key := []byte{0x18, 0x2d}
value := []byte{0x44, 0x54}
record1 := NewRecord(key, value)
record2 := NewRecord(key, value)
if !record1.Equals(record2) {
t.Error("Equals failed")
}
}
func TestNotEquals(t *testing.T) {
key := []byte{0x18, 0x2d}
value := []byte{0x44, 0x54}
key2 := []byte{0x18, 0x20}
value2 := []byte{0x44, 0x40}
record1 := NewRecord(key, value)
record2 := NewRecord(key2, value2)
if record1.Equals(record2) {
t.Error("Equals failed")
}
}