-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransformer_symbol_test.go
79 lines (73 loc) · 1.54 KB
/
transformer_symbol_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
67
68
69
70
71
72
73
74
75
76
77
78
79
package sinoname
import (
"context"
"testing"
)
// TODO: refactor
func TestSymbol(t *testing.T) {
t.Run("All_Possible_Values", func(t *testing.T) {
vals := []string{
".ABC",
"A.BC",
"AB.C",
"ABC.",
".A.BC",
".AB.C",
".ABC.",
"A.B.C",
"A.BC.",
"AB.C.",
".A.B.C",
".A.BC.",
".AB.C.",
"A.B.C.",
}
src := newStaticSource()
cfg := &Config{
MaxBytes: testConfig.MaxBytes,
MaxVals: testConfig.MaxVals,
Source: src,
}
tr, _ := SymbolTransformer('.', 3)(cfg)
for _, vWant := range vals {
vGot, err := tr.Transform(context.Background(), MessagePacket{"ABC", 0, 0})
if err != nil {
t.Fatal(err)
}
if vGot.Message != vWant {
t.Fatal("got:", vGot, "but want:", vWant)
}
src.addValue(vGot.Message)
}
v, err := tr.Transform(context.Background(), MessagePacket{"ABC", 0, 0})
if err != nil {
t.Fatal(err)
}
if v.Message != "ABC" {
t.Fatal("last iteration wasnt set to initiall value")
}
})
t.Run("Max_Symbols", func(t *testing.T) {
src := newStaticSource(
".ABC",
"A.BC",
"AB.C",
"ABC.",
)
cfg := &Config{
MaxBytes: testConfig.MaxBytes,
MaxVals: testConfig.MaxVals,
Source: src,
}
// last itteration should roll to initiall value because no more points can be generated
// even if possible.
tr, _ := SymbolTransformer('.', 1)(cfg)
v, err := tr.Transform(context.Background(), MessagePacket{"ABC", 0, 0})
if err != nil {
t.Fatal(err)
}
if v.Message != "ABC" {
t.Fatal("last iteration wasnt set to initiall value")
}
})
}