-
Notifications
You must be signed in to change notification settings - Fork 0
/
char_formatter_test.go
60 lines (51 loc) · 1.72 KB
/
char_formatter_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
package profaneword
import (
"math/big"
"reflect"
"testing"
)
func TestL337CharFormatter_FormatRune(t *testing.T) {
abFormatter := L337CharFormatter{map[rune][]rune{'a': {'b'}}}
got := abFormatter.FormatRune('a')
if len(got) != 1 && got[0] != 'b' {
t.Errorf("L337CharFormatter misformatted, expected: {'b'} got: %v", got)
}
got = abFormatter.FormatRune('d')
if len(got) != 1 && got[0] != 'd' {
t.Errorf("L337CharFormatter misformatted, expected: {'d'} got: %v", got)
}
}
type zeroRandomDevice int
func (z zeroRandomDevice) Rand() *big.Rat {
return big.NewRat(int64(z), 1)
}
func (zeroRandomDevice) RandMax(_ int) int {
return 0
}
var _ RandomDevice = zeroRandomDevice(0)
func TestFastFingerCharFormatter_FormatRune(t *testing.T) {
ff := FastFingerCharFormatter{zeroRandomDevice(2)}
if got := ff.FormatRune('a'); len(got) != 1 && got[0] != 'a' {
t.Errorf("FastFingerCharFormatter did return unit-slice as expected")
}
ff.RandomDevice = zeroRandomDevice(0)
if got := ff.FormatRune('a'); len(got) != 0 {
t.Errorf("FastFingerCharFormatter did return empty slice, as expected")
}
}
func TestFatFingerCharFormatter_FormatRune(t *testing.T) {
fatf := FatFingerCharFormatter{zeroRandomDevice(0)}
if got := fatf.FormatRune('a'); len(got) != 1 && got[0] != 'a' {
t.Errorf("FatFingerCharFormatter did return unit-slice as expected, got: %v", got)
}
fatf.RandomDevice = zeroRandomDevice(0)
if got := fatf.FormatRune('a'); len(got) != 4 && reflect.DeepEqual([]rune{'a', 'q', 'q', 'a'}, got) {
t.Errorf("FatFingerCharFormatter did return aqqa, as expected, got: %v", got)
}
}
func TestL337Formatter(t *testing.T) {
l := L337Formatter()
if l.Format("asd") != "45d" {
t.Errorf("L337formatter did not format as expected")
}
}