Skip to content

Commit 0c0e2df

Browse files
committed
Add tests and makefile; ignore test log
1 parent 8113709 commit 0c0e2df

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/_lcs_test_suite.log

tests/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This Makefile takes advantage of the fact that the LiveCode engine's
2+
# "tests/Makefile" already does pretty much everything required for
3+
# running a test suite. Rather than duplicating it, it can
4+
# just be included with a few tweaks to its configuration.
5+
6+
# Override the default value of top_srcdir so that it points to the
7+
# top of the engine repository.
8+
top_srcdir = ../livecode
9+
10+
LCS_TESTS_DIR = test-scripts
11+
12+
# Things have now been setup enough that the engine's test Makefile
13+
# can perform the tests without any further configuration.
14+
include $(top_srcdir)/tests/Makefile
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
script "TestCiphers"
2+
3+
on TestSetup
4+
local tSourceFile
5+
put the filename of me into tSourceFile
6+
set the itemdelimiter to slash
7+
put "src/PuzzleTools.livecodescript" into item -3 to -1 of tSourceFile
8+
start using stack tSourceFile
9+
end TestSetup
10+
11+
private command TestAssertUserThrows pDesc, pHandler, pError
12+
local tError
13+
try
14+
dispatch pHandler to me
15+
catch tError
16+
end try
17+
18+
TestDiagnostic tError
19+
20+
TestAssert pDesc, tError is pError
21+
end TestAssertUserThrows
22+
23+
on LetterToNumberThrow
24+
get toNumber("'")
25+
end LetterToNumberThrow
26+
27+
on TestLetterToNumber
28+
local tIndex
29+
put 0 into tIndex
30+
repeat for each char tChar in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
31+
add 1 to tIndex
32+
TestAssert "uppercase letter" && tChar && "to number correct", \
33+
toNumber(tChar) is tIndex
34+
end repeat
35+
36+
put 0 into tIndex
37+
repeat for each char tChar in "abcdefghijklmnopqrstuvwxyz"
38+
add 1 to tIndex
39+
TestAssert "lowercase letter" && tChar && "to number correct", \
40+
toNumber(tChar) is tIndex
41+
end repeat
42+
43+
TestAssertUserThrows "non alphabetic input to toNumber function throws", \
44+
"LetterToNumberThrow", "char not alphabetical"
45+
end TestLetterToNumber
46+
47+
on TestLetterFromNumber
48+
local tIndex
49+
put 0 into tIndex
50+
repeat for each char tChar in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
51+
add 1 to tIndex
52+
TestAssert "uppercase letter" && tChar && "from number correct", \
53+
fromNumber(tIndex) is tChar
54+
end repeat
55+
56+
put 0 into tIndex
57+
repeat for each char tChar in "abcdefghijklmnopqrstuvwxyz"
58+
add 1 to tIndex
59+
TestAssert "lowercase letter" && tChar && "from number correct", \
60+
fromNumber(tIndex) is tChar
61+
end repeat
62+
end TestLetterFromNumber
63+
64+
on TestCaesarCipher
65+
TestAssert "abjurer <-> nowhere (13)", caesarShift("abjurer", 13) is "nowhere"
66+
TestAssert "inkier <-> purply (7)", caesarShift("inkier", 7) is "purply"
67+
TestAssert "fusion <-> layout (6)", caesarShift("fusion", 6) is "layout"
68+
TestAssert "manful <-> thumbs (7)", caesarShift("manful", 7) is "thumbs"
69+
TestAssert "primero <-> sulphur (3)", caesarShift("primero", 3) is "sulphur"
70+
TestAssert "steeds <-> tuffet (1)", caesarShift("steeds", 1) is "tuffet"
71+
end TestCaesarCipher
72+
73+
on TestVigenereCipher
74+
TestAssert "LIVECODE encoded using vigenere cipher with key TEST is EMNXVSVX", \
75+
vigenereShift("LIVECODE","TEST") is "EMNXVSVX"
76+
end TestVigenereCipher
77+

0 commit comments

Comments
 (0)