21
func TestLegal(t *testing.T) {
22
checker := newUniqChecker()
23
for i := 1; i <= 10; i++ {
24
if !checker.legalIn(uint64(i)) {
28
if checker.legalIn(1) {
29
t.Errorf("failed, %v", checker.op)
33
func TestOpQueue(t *testing.T) {
35
for i := uint64(0); i < 10000; i++ {
42
q.scan(func(op *uniqOp) bool {
44
t.Fatalf("op queue scan failed")
50
t.Fatalf("scan failed %v", cnt)
54
if op.uniqid != 4567 {
55
t.Fatalf("q.index 4567 failed")
61
if op.uniqid != 4568 {
62
t.Fatalf("q.index 4568 failed")
65
if q.len() != 10000-4567-1 {
66
t.Fatalf("op queue trancate failed")
69
q.scan(func(op *uniqOp) bool {
70
if op.uniqid != 4568 {
71
t.Fatalf("op queue trancate scan failed")
77
for i := uint64(10000); i < 20000; i++ {
78
q.append(&uniqOp{uniqid: i})
81
if q.len()-clone.len() != 10000 || q.index(1234).uniqid != clone.index(1234).uniqid {
82
t.Fatalf("op queue clone failed")
86
if q.len() != 0 || len(q.cur.s) != 0 || len(q.ss) != 1 {
87
t.Fatalf("op queue trancate failed")
91
func TestClone(t *testing.T) {
92
checker := newUniqChecker()
93
for i := 1; i <= 10000; i++ {
94
checker.legalIn(uint64(i))
97
checker1 := checker.clone()
98
if len(checker1.op) != 0 || checker.inQue.len() != checker1.inQue.len() {
103
checker.inQue.scan(func(op *uniqOp) bool {
104
if op.uniqid != checker1.inQue.index(i).uniqid || op.atime != checker1.inQue.index(i).atime {
113
func TestMarshal(t *testing.T) {
114
checker := newUniqChecker()
115
for i := 1; i <= 10000; i++ {
116
checker.legalIn(uint64(i))
119
bts, _, _ := checker.Marshal()
120
checker1 := newUniqChecker()
121
checker1.UnMarshal(bts)
123
if len(checker.op) != len(checker1.op) || checker.inQue.len() != checker1.inQue.len() {
128
checker.inQue.scan(func(v *uniqOp) bool {
129
if v.uniqid != checker1.inQue.index(i).uniqid || v.atime != checker1.inQue.index(i).atime {
130
t.Errorf("failed, id(%v, %v), atime(%v, %v)", v.uniqid, checker1.inQue.index(i).uniqid, v.atime, checker1.inQue.index(i).atime)
134
if _, ok := checker1.op[v.uniqid]; !ok {
135
t.Errorf("failed, %v, %v", checker.op[v.uniqid], checker1.op[v.uniqid])