forked from mrekucci/epi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalindrom_test.go
46 lines (40 loc) · 1.15 KB
/
palindrom_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
// Copyright (c) 2015, Peter Mrekaj. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.txt file.
package htables
import (
"math/rand"
"testing"
"github.com/mrekucci/epi/internal/epiutil"
)
func TestCanFormPalindrome(t *testing.T) {
for _, test := range []struct {
in string
want bool
}{
{"", true},
{"ab", false},
{"aa", true},
{"aab", true},
{"aaab", false},
{"aaabccc", false},
{"aaabcc", false},
{"edified", true},
{"界☺世", false},
{"世世☺", true},
} {
if got := CanFormPalindrome(test.in); got != test.want {
t.Errorf("CanFormPalindrome(%q) = %t; want %t", test.in, got, test.want)
}
}
}
func benchCanFormPalindrome(b *testing.B, size int) {
s := epiutil.RandStr(size, "abcdefghijklmnopqrstuvwxyz", rand.NewSource(int64(size)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
CanFormPalindrome(s)
}
}
func BenchmarkCanFormPalindrome1e2(b *testing.B) { benchCanFormPalindrome(b, 1e2) }
func BenchmarkCanFormPalindrome1e4(b *testing.B) { benchCanFormPalindrome(b, 1e4) }
func BenchmarkCanFormPalindrome1e6(b *testing.B) { benchCanFormPalindrome(b, 1e6) }