/
spellabc_test.go
40 lines (34 loc) · 951 Bytes
/
spellabc_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
// Copyright (c) 2012 Aaron Bull Schaefer
// This source code is provided under the terms of the MIT License
// that can be be found in the LICENSE file.
package spellabc
import (
"testing"
)
type testpair struct {
decoded, encoded string
}
var pairs = []testpair{
{"", ""},
{"h", "hotel"},
{"H", "HOTEL"},
{"He", "HOTEL echo"},
{"Hel", "HOTEL echo lima"},
{"Hell", "HOTEL echo lima lima"},
{"Hello", "HOTEL echo lima lima oscar"},
{"Hello World!", "HOTEL echo lima lima oscar Space WHISKEY oscar romeo lima delta Exclamation"},
{"ABC\ndef", "ALPHA BRAVO CHARLIE\ndelta echo foxtrot"},
}
func testEqual(t *testing.T, msg string, args ...interface{}) bool {
if args[len(args)-2] != args[len(args)-1] {
t.Errorf(msg, args...)
return false
}
return true
}
func TestEncode(t *testing.T) {
for _, p := range pairs {
got := NatoAlphabet.Encode(p.decoded)
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, got, p.encoded)
}
}