-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcel_test.go
More file actions
151 lines (129 loc) · 3.71 KB
/
Copy pathexcel_test.go
File metadata and controls
151 lines (129 loc) · 3.71 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package g
import "testing"
// TestRank tests the Rank function.
func TestRank(t *testing.T) {
rank := Rank(7, []int{1, 5, 2, 3, 7, 8})
if rank != 1 {
t.Errorf("Expected rank 1, but got %d", rank)
}
rank = Rank(7, []int{1, 5, 2, 3, 7, 8}, true)
if rank != 4 {
t.Errorf("Expected rank 4, but got %d", rank)
}
rank = Rank(9, []int{1, 5, 2, 3, 7, 8})
if rank != -1 {
t.Errorf("Expected rank -1, but got %d", rank)
}
rank = Rank(7, []int{1, 7, 7, 3, 7, 8})
if rank != 1 {
t.Errorf("Expected rank 1, but got %d", rank)
}
rank = Rank(7, []int{1, 7, 7, 3, 7, 8}, true)
if rank != 2 {
t.Errorf("Expected rank 2, but got %d", rank)
}
rank = Rank(4.5, []float64{1.2, 3.1, 4.5, 2.8, 4.5, 6.7})
if rank != 1 {
t.Errorf("Expected rank 1, but got %d", rank)
}
rank = Rank(4.5, []float64{1.2, 3.1, 4.5, 2.8, 4.5, 6.7}, true)
if rank != 3 {
t.Errorf("Expected rank 3, but got %d", rank)
}
rank = Rank("Banana", []string{
"Apple", "Banana", "Cherry",
"Banana", "Dragonfruit", "Elderberry",
})
if rank != 3 {
t.Errorf("Expected rank 3, but got %d", rank)
}
rank = Rank("Banana", []string{
"Apple", "Banana", "Cherry",
"Banana", "Dragonfruit", "Elderberry",
}, true)
if rank != 1 {
t.Errorf("Expected rank 1, but got %d", rank)
}
}
// TestHLookup tests the HLookup function.
func TestHLookup(t *testing.T) {
lookup := []string{"A", "B", "C"}
result := []int{1, 2, 3}
// Test case 1: Lookup value exists in the table.
val := HLookup("B", lookup, result, -1)
expected := 2
if val != expected {
t.Errorf("HLookup test case 1 failed: expected %d, got %d",
expected, val)
}
// Test case 2: Lookup value does not exist in the table.
val = HLookup("D", lookup, result, -1)
expected = -1
if val != expected {
t.Errorf("HLookup test case 2 failed: expected %d, got %d",
expected, val)
}
// Test case 3: Lookup value is the first element in the table.
val = HLookup("A", lookup, result, -1)
expected = 1
if val != expected {
t.Errorf("HLookup test case 3 failed: expected %d, got %d",
expected, val)
}
// Test case 4: Lookup value is the last element in the table.
val = HLookup("C", lookup, result, -1)
expected = 3
if val != expected {
t.Errorf("HLookup test case 4 failed: expected %d, got %d",
expected, val)
}
// Test case 5: Lookup value is not found,
// with a non-default default value.
val = HLookup("E", lookup, result, 0)
expected = 0
if val != expected {
t.Errorf("HLookup test case 5 failed: expected %d, got %d",
expected, val)
}
}
// TestVLookup tests the VLookup function.
func TestVLookup(t *testing.T) {
lookup := []string{"A", "B", "C"}
result := []int{1, 2, 3}
// Test case 1: Lookup value exists in the table.
val := VLookup("B", lookup, result, -1)
expected := 2
if val != expected {
t.Errorf("VLookup test case 1 failed: expected %d, got %d",
expected, val)
}
// Test case 2: Lookup value does not exist in the table.
val = VLookup("D", lookup, result, -1)
expected = -1
if val != expected {
t.Errorf("VLookup test case 2 failed: expected %d, got %d",
expected, val)
}
// Test case 3: Lookup value is the first element in the table.
val = VLookup("A", lookup, result, -1)
expected = 1
if val != expected {
t.Errorf("VLookup test case 3 failed: expected %d, got %d",
expected, val)
}
// Test case 4: Lookup value is the last element in the table.
val = VLookup("C", lookup, result, -1)
expected = 3
if val != expected {
t.Errorf("VLookup test case 4 failed: expected %d, got %d",
expected, val)
}
// Test case 5: Lookup value is not found,
// with a non-default default value.
val = VLookup("E", lookup, result, 0)
expected = 0
if val != expected {
t.Errorf("VLookup test case 5 failed: expected %d, got %d",
expected, val)
}
}