-
Notifications
You must be signed in to change notification settings - Fork 0
/
sortstring_test.go
46 lines (40 loc) · 976 Bytes
/
sortstring_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
package sortstring
import (
"testing"
)
var results = []string{"132", "213", "231", "312", "321", "123"}
func TestReverse(t *testing.T) {
a := NewSortString("racecar")
a.Reverse(0, a.Len())
if a.String() != "racecar" {
t.Errorf("Failed palindrome test: %s is not %s\n", "racecar", a.String())
}
}
func TestReverse2(t *testing.T) {
a := NewSortString("abcdef")
a.Reverse(0, a.Len())
if a.String() != "fedcba" {
t.Error("TestReverse2 failed")
}
}
func TestBasicNextPermTest(t *testing.T) {
a := NewSortString("abcdef")
if !a.NextPermutation(0, a.Len()) {
t.Errorf("NextPermutation should have returned true! : %s\n", a)
}
}
func TestSortStringPerms(t *testing.T) {
a := NewSortString("123")
i := 0
for a.NextPermutation(0, a.Len()) == true {
t.Logf("Is %s == %s\n", a.String(), results[i])
if results[i] != a.String() {
t.FailNow()
}
i++
}
t.Logf("Is %s == %s\n", a.String(), results[i])
if results[i] != a.String() {
t.FailNow()
}
}