-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathchallenge6_test.go
84 lines (74 loc) · 1.57 KB
/
challenge6_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
package challenge6
import (
"strings"
"testing"
)
// Call challenge6.FindRanges() on _ints_ and concatenate the ranges into a
// single string for comparison testing.
func FR(ints []int) string {
return strings.Join(FindRanges(ints).ToStrings(), " ")
}
func TestEmpty(t *testing.T) {
ex := ""
r := FR([]int{})
if r != ex {
t.Error("Mismatch, expected:", ex, "received:", r)
}
}
func TestSingleton(t *testing.T) {
ex := ""
r := FR([]int{1})
if r != ex {
t.Error("Mismatch, expected:", ex, "received:", r)
}
}
func TestSimpleRange(t *testing.T) {
ex := "1->2"
r := FR([]int{1, 2})
if r != ex {
t.Error("Mismatch, expected:", ex, "received:", r)
}
}
func TestNegativeRange(t *testing.T) {
ex := "-2->-1"
r := FR([]int{-2, -1})
if r != ex {
t.Error("Mismatch, expected:", ex, "received:", r)
}
}
func TestLongRange(t *testing.T) {
ex := "1->20000"
c := 20000
ints := make([]int, 0, c)
for i := 1; i <= c; i++ {
ints = append(ints, i)
}
r := FR(ints)
if r != ex {
t.Error("Mismatch, expected:", ex, "received:", r)
}
}
// TestTwoRanges
func TestRR(t *testing.T) {
ex := "10->12 14->16"
r := FR([]int{10, 11, 12, 14, 15, 16})
if r != ex {
t.Error("Mismatch, expected:", ex, "received:", r)
}
}
// TestSingletonRangeSingleton
func TestSRS(t *testing.T) {
ex := "4->6"
r := FR([]int{2, 4, 5, 6, 8})
if r != ex {
t.Error("Mismatch, expected:", ex, "received:", r)
}
}
// TestRangeSingletonRange
func TestRSR(t *testing.T) {
ex := "1->3 7->9"
r := FR([]int{1, 2, 3, 5, 7, 8, 9})
if r != ex {
t.Error("Mismatch, expected:", ex, "received:", r)
}
}