Initialise
This commit is contained in:
parent
3ff7f9b0b9
commit
0941f68e91
700 changed files with 27489 additions and 0 deletions
47
reverse-string/reverse_string_test.go
Normal file
47
reverse-string/reverse_string_test.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package reverse
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"testing/quick"
|
||||
)
|
||||
|
||||
func TestReverse(t *testing.T) {
|
||||
for _, testCase := range append(testCases, multiByteCases...) {
|
||||
if res := Reverse(testCase.input); res != testCase.expected {
|
||||
t.Fatalf("FAIL: %s(%s)\nExpected: %q\nActual: %q",
|
||||
testCase.description, testCase.input, testCase.expected, res)
|
||||
}
|
||||
t.Logf("PASS: %s", testCase.description)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReverseOfReverse(t *testing.T) {
|
||||
assertion := func(s string) bool {
|
||||
return s == Reverse(Reverse(s))
|
||||
}
|
||||
if err := quick.Check(assertion, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkReverse(b *testing.B) {
|
||||
if testing.Short() {
|
||||
b.Skip("skipping benchmark in short mode.")
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, test := range testCases {
|
||||
Reverse(test.input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// mutiByteCases adds UTF-8 multi-byte case,
|
||||
// since the canonical-data.json (generator data source for cases_test.go)
|
||||
// doesn't have any such cases.
|
||||
var multiByteCases = []reverseTestCase{
|
||||
{
|
||||
description: "a multi-byte test case",
|
||||
input: "Hello, 世界",
|
||||
expected: "界世 ,olleH",
|
||||
},
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue