-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorse_test.go
71 lines (63 loc) · 1.45 KB
/
morse_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package morse
import (
"testing"
)
func TestIcuTableE(t *testing.T) {
want := "."
got := icuTable['e']
if want != got {
t.Errorf("want %s but got %s\n", want, got)
}
}
func TestIcuTable7(t *testing.T) {
want := "--..."
got := icuTable['7']
if want != got {
t.Errorf("want %s but got %s\n", want, got)
}
}
func TestCodeSample1(t *testing.T) {
want := "- - - - - . - . . . . . - . - . " +
"- - - - . . ."
got := Code("morse code")
if want != got {
t.Errorf("want %s but got %s\n", want, got)
}
}
func TestCodeSample2(t *testing.T) {
want := ". . - . . - . . . . . . - . - - " +
". . - . - - - . - . - . . - - - . - - . . -" +
" . - . . . . ."
got := Code("FREIE ENZYKLOPAEDIE")
if want != got {
t.Errorf("want %s but got %s\n", want, got)
}
}
func TestSignalE(t *testing.T) {
want := "1"
got := Signal("e")
if want != got {
t.Errorf("want %s but got %s\n", want, got)
}
}
func TestSignalEe(t *testing.T) {
want := "1" + // e
"000" + // letter separator
"1" // e
got := Signal("ee")
if want != got {
t.Errorf("want %s but got %s\n", want, got)
}
}
func TestWikipediaNotation(t *testing.T) {
want := "===_===___===_===_===___=_===_=___=_=_=___=_______" +
"===_=_===_=___===_===_===___===_=_=___="
s := Signal("morse code")
var got string
for _, r := range s {
got += string(WikipediaNotation(r))
}
if want != got {
t.Errorf("\nwant: %s\ngot: %s\n", want, got)
}
}