~gioverse/chat

ref: c86e075f0df33cc01ac99f167a09f981997727d0 chat/list/element_test.go -rw-r--r-- 1.2 KiB
c86e075fChris Waldon debug: add function to easily log structures 10 months ago
                                                                                
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package list

import (
	"reflect"
	"strings"
)

type testElement struct {
	serial     string
	synthCount int
}

func (t testElement) Serial() Serial {
	return Serial(t.serial)
}

func testSynthesizer(previous, current, next Element) []Element {
	out := []Element{}
	for i := 0; i < current.(testElement).synthCount; i++ {
		out = append(out, current)
	}
	return out
}

func testComparator(a, b Element) bool {
	return strings.Compare(string(a.Serial()), string(b.Serial())) < 0
}

func elementsEqual(a, b []Element) bool {
	if len(a) != len(b) {
		return false
	}
	for i := range a {
		if !reflect.DeepEqual(a[i], b[i]) {
			return false
		}
	}
	return true
}

func serialsEqual(a, b []Serial) bool {
	if len(a) != len(b) {
		return false
	}
	for i := range a {
		if !reflect.DeepEqual(a[i], b[i]) {
			return false
		}
	}
	return true
}

var compactionList = []Element{
	testElement{
		serial:     "a",
		synthCount: 1,
	},
	testElement{
		serial:     "b",
		synthCount: 1,
	},
	testElement{
		serial:     "c",
		synthCount: 1,
	},
	testElement{
		serial:     "d",
		synthCount: 1,
	},
	testElement{
		serial:     "e",
		synthCount: 1,
	},
	testElement{
		serial:     "f",
		synthCount: 1,
	},
	testElement{
		serial:     "g",
		synthCount: 1,
	},
}