-
Notifications
You must be signed in to change notification settings - Fork 0
/
property_test.go
105 lines (89 loc) · 2.28 KB
/
property_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package sortprop_test
import (
"sort"
"strconv"
"testing"
"github.com/grimdork/sortprop"
)
func TestAppendSort(t *testing.T) {
list := sortprop.KeyProperties{}
var i int64
for i = 9; i >= 0; i-- {
k := strconv.FormatInt(i, 10)
v := "element " + k
list = append(list, sortprop.Property{k, v})
}
sort.Sort(list)
if list[0].Key != "0" || list[0].Value != "element 0" {
t.Fail()
}
t.Logf("%+v", list)
}
func TestAppendSortValue(t *testing.T) {
list := sortprop.ValueProperties{}
var i int64
for i = 9; i >= 0; i-- {
k := strconv.FormatInt(i, 10)
v := "element " + k
list = append(list, sortprop.Property{k, v})
}
sort.Sort(list)
if list[0].Key != "0" || list[0].Value != "element 0" {
t.Fail()
}
t.Logf("%+v", list)
}
func TestUniqueKeys(t *testing.T) {
kp := sortprop.KeyProperties{
sortprop.Property{"a", "this is a1"},
sortprop.Property{"a", "this is a2"},
sortprop.Property{"a", "this is a3"},
sortprop.Property{"b", "this is b1"},
sortprop.Property{"b", "this is b2"},
sortprop.Property{"c", "this is c1"},
sortprop.Property{"c", "this is c2"},
sortprop.Property{"c", "this is c3"},
sortprop.Property{"c", "this is c4"},
}
t.Log("Before:")
for _, p := range kp {
t.Logf("%s = %s", p.Key, p.Value)
}
list := sortprop.UniqueKeys(kp, false)
t.Log("After: (keep first)")
for _, p := range list {
t.Logf("%s = %s", p.Key, p.Value)
}
list = sortprop.UniqueKeys(kp, true)
t.Log("After: (keep last)")
for _, p := range list {
t.Logf("%s = %s", p.Key, p.Value)
}
}
func TestUniqueValues(t *testing.T) {
vp := sortprop.ValueProperties{
sortprop.Property{"a1", "this is a"},
sortprop.Property{"a2", "this is a"},
sortprop.Property{"a3", "this is a"},
sortprop.Property{"b1", "this is b"},
sortprop.Property{"b2", "this is b"},
sortprop.Property{"c1", "this is c"},
sortprop.Property{"c2", "this is c"},
sortprop.Property{"c3", "this is c"},
sortprop.Property{"c4", "this is c"},
}
t.Log("Before:")
for _, p := range vp {
t.Logf("%s = %s", p.Key, p.Value)
}
list := sortprop.UniqueValues(vp, false)
t.Log("After: (keep first)")
for _, p := range list {
t.Logf("%s = %s", p.Key, p.Value)
}
list = sortprop.UniqueValues(vp, true)
t.Log("After: (keep last)")
for _, p := range list {
t.Logf("%s = %s", p.Key, p.Value)
}
}