-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenigma_test.go
50 lines (40 loc) · 1.05 KB
/
enigma_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
package benigma
import (
"testing"
"github.com/emedvedev/enigma"
)
func TestEncode(t *testing.T) {
type singleTest struct {
Model string
Keyboard string
Lights string
}
tests := []singleTest{
{"I", "THISISATEST", "ZPJJSVSPGBW"},
{"M3", "THISISATEST", "ZPJJSVSPGBW"},
{"M4", "THISISATEST", "ZPJJSVSPGBW"},
}
for i, test_case := range tests {
machine := builtinModels[test_case.Model]
encoded := machine.EncodeString(test_case.Keyboard)
if encoded != test_case.Lights {
t.Errorf("Run %d: Expected %s but got %s", i, test_case.Keyboard, encoded)
}
}
}
func TestSanitize(t *testing.T) {
type sanitizeTest struct {
Raw string
Sanitized string
}
tests := []sanitizeTest{
{"Hello World", "HELLOXWORLD"},
{"guillaume@paralint.com", "GUILLAUMEPARALINTCOM"},
}
for i, test_case := range tests {
sanitized := enigma.SanitizePlaintext(test_case.Raw)
if test_case.Sanitized != sanitized {
t.Errorf("Run %d: Sanitization of %s should yield %s but got %s", i, test_case.Raw, test_case.Sanitized, sanitized)
}
}
}