-
Notifications
You must be signed in to change notification settings - Fork 0
/
functionality_test.go
80 lines (64 loc) · 2.08 KB
/
functionality_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
72
73
74
75
76
77
78
79
80
package strenco
import (
"testing"
"github.com/julyskies/strenco/utilities"
)
const LARGE_STRING = `
This is a pretty large string, it is used in the tests.
The length of this string is bigger than the length of the alphabet used for encoding!
123 321 123
345 543 321
098 980 890
000 000 000
And some special symbols: $%^:[]@()_ !,.=+
Encoding should ignore all of the symbols that are not in the alphabet:
\
Ê
µ
That's it, should be fine...
`
const SMALL_STRING = "This is a small string, it is used in the tests..."
func TestFunctionalityLargeString(t *testing.T) {
encoded, encodingError := Encode(LARGE_STRING)
if encoded == "" {
t.Error("Expected to return an encoded string when encoding a valid short string!")
}
if encodingError != nil {
t.Error("Expected to return a nil error when encoding a valid short string!")
}
runes := []rune(encoded)
endSymbols := string(runes[:2])
startSymbols := string(runes[len(runes)-2:])
if endSymbols != utilities.WRAP || startSymbols != utilities.WRAP {
t.Error("Expected returned encoded string to be wrapped!")
}
decoded, decodingError := Decode(encoded)
if decoded == "" {
t.Error("Expected to return a decoded string when decoding a valid short string!")
}
if decodingError != nil {
t.Error("Expected to return a nil error when decoding a valid short string!")
}
if decoded != LARGE_STRING {
t.Error("Expected decoded string to be equal to the original!")
}
}
func TestFunctionalityShortString(t *testing.T) {
encoded, encodingError := Encode(SHORT_STRING)
if encoded == "" {
t.Error("Expected to return an encoded string when encoding a valid short string!")
}
if encodingError != nil {
t.Error("Expected to return a nil error when encoding a valid short string!")
}
decoded, decodingError := Decode(encoded)
if decoded == "" {
t.Error("Expected to return a decoded string when decoding a valid short string!")
}
if decodingError != nil {
t.Error("Expected to return a nil error when decoding a valid short string!")
}
if decoded != SHORT_STRING {
t.Error("Expected decoded string to be equal to the original!")
}
}