-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmesostic_test.go
157 lines (120 loc) · 3.79 KB
/
mesostic_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
Tests
*/
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
)
// TestTmesoMain ::: Create a mesostic from a static source file.
// For now this test is display-only.
// TODO: Checksum or something.
func TestTmesoMain(t *testing.T) {
fmt.Printf("\n\t::: Test Target mesoMain() :::\n")
// This mimics the calls made by various API endpoints.
// There is no automatic filename creation, a known file is used to match.
// this test is "failing" because the mesoMain function now *removes* the file it is passed.
// Set up store
TTstore, err := ioutil.TempDir(".", "store")
if err != nil {
t.Error(err)
}
defer os.RemoveAll(TTstore)
// Set up tmp
TTdir, err := ioutil.TempDir(".", "txrx")
if err != nil {
t.Error(err)
}
defer os.RemoveAll(TTdir)
spine := "craque"
sourceFile := "sources/lorenipsum-plaintext.txt"
testTmp := "sources/lorenipsum.txt"
// simulate reading an input source
bRead, berr := ioutil.ReadFile(sourceFile)
if berr != nil {
t.Error(berr)
}
// write a scratch tmp file, which mesoMain removes
werr := ioutil.WriteFile(testTmp, bRead, 0644)
if werr != nil {
t.Error(werr)
}
// mesoMain receives ::: tmp filename, the SpineString, data channel
mcMeso := make(chan string)
go mesoMain(testTmp, spine, mcMeso)
// receive the channel data and display result
mesostic := <-mcMeso
fmt.Println(mesostic)
// check if mesoMain removed the scratch tmp correctly
if _, lserr := os.Stat(testTmp); lserr == nil {
t.Error(lserr)
}
/*
lorem ipsum dolor sit amet, Consectetu
elit, sed do eiusmod tempoR incididunt ut l
dolore mAgna ali
nostrud exercitation ullamco laboris nisi ut aliQ
ex ea commodo conseqUat. duis aut
rEprehenderit in voluptate velit esse
eu fugiat nulla pariatur. exCepteu
cupidatat non pRoident, sunt in culp
deserunt mollit Anim id est laborum.
*/
}
// TestTIctus ::: Using a specific string, test this function's ability to rotate through each character.
func TestTIctus(t *testing.T) {
fmt.Printf("\n\t::: Test Target Ictus() :::\n")
spineString := "cra"
ictus := 0
nexus := 1
var spineChars []string
for h := 0; h < len(spineString); h++ {
spineChars = append(spineChars, strings.ToLower(string(spineString[h])))
}
// Test each character and then that it rotates to the first successfully.
if spineChars[ictus] != "c" {
t.Errorf("%q\n", spineString)
}
Ictus(len(spineString), &ictus, &nexus)
if spineChars[ictus] != "r" {
t.Errorf("%q\n", spineString)
}
Ictus(len(spineString), &ictus, &nexus)
if spineChars[ictus] != "a" {
t.Errorf("%q\n", spineString)
}
Ictus(len(spineString), &ictus, &nexus)
if spineChars[ictus] != "c" {
t.Errorf("Rotation failed! %q\n", spineString)
}
}
// TestTPreus ::: Using a specific string, test this function's ability to rewind the SpineString rotation done by Ictus().
func TestTPreus(t *testing.T) {
fmt.Printf("\n\t::: Test Target Preus() :::\n")
spineString := "cra"
ictus := 0
nexus := 1
var spineChars []string
for h := 0; h < len(spineString); h++ {
spineChars = append(spineChars, strings.ToLower(string(spineString[h])))
}
// Test each character and then that it rewinds to the one before it.
if spineChars[ictus] != "c" {
t.Errorf("%q\n", spineString)
}
Preus(len(spineString), &ictus, &nexus)
if spineChars[ictus] != "a" {
t.Errorf("%q\n", spineString)
}
Preus(len(spineString), &ictus, &nexus)
if spineChars[ictus] != "r" {
t.Errorf("%q\n", spineString)
}
Preus(len(spineString), &ictus, &nexus)
if spineChars[ictus] != "c" {
t.Errorf("Rewind failed! %q\n", spineString)
}
}