mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-11-19 21:03:43 +00:00
44 lines
893 B
Go
44 lines
893 B
Go
// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
|
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
|
|
//!+test
|
|
package word
|
|
|
|
import "testing"
|
|
|
|
func TestPalindrome(t *testing.T) {
|
|
if !IsPalindrome("detartrated") {
|
|
t.Error(`IsPalindrome("detartrated") = false`)
|
|
}
|
|
if !IsPalindrome("kayak") {
|
|
t.Error(`IsPalindrome("kayak") = false`)
|
|
}
|
|
}
|
|
|
|
func TestNonPalindrome(t *testing.T) {
|
|
if IsPalindrome("palindrome") {
|
|
t.Error(`IsPalindrome("palindrome") = true`)
|
|
}
|
|
}
|
|
|
|
//!-test
|
|
|
|
// The tests below are expected to fail.
|
|
// See package gopl.io/ch11/word2 for the fix.
|
|
|
|
//!+more
|
|
func TestFrenchPalindrome(t *testing.T) {
|
|
if !IsPalindrome("été") {
|
|
t.Error(`IsPalindrome("été") = false`)
|
|
}
|
|
}
|
|
|
|
func TestCanalPalindrome(t *testing.T) {
|
|
input := "A man, a plan, a canal: Panama"
|
|
if !IsPalindrome(input) {
|
|
t.Errorf(`IsPalindrome(%q) = false`, input)
|
|
}
|
|
}
|
|
|
|
//!-more
|