-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUtilityTests.hs
32 lines (27 loc) · 1.23 KB
/
UtilityTests.hs
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
import Data.Bits
import Data.Char
import Data.List
import Test.QuickCheck
import Text.Printf
import Baskerville.Utilities.Bits
import Baskerville.Utilities.Chat
-- From some tutorial somewhere.
mapper :: PrintfArg t => (t, IO b) -> IO b
mapper (d, t) = printf "%-30s: " d >> t
main = mapM_ mapper tests
-- Baskerville.Utilities.Bits
unpackNibblesMod2 x = length (unpackNibbles x) `mod` 2 == 0
packUnpackNibbles x = packNibbles (unpackNibbles x) == x
-- Baskerville.Utilities.Chat
hashStringIndexRange x = let i = hashStringIndex x in i >= 0 && i < 15
betaChatNameHead x = head (betaChatName x) == '§'
betaChatNameSuffix x = isSuffixOf "§f" (betaChatName x)
consoleChatNamePrefix x = isPrefixOf "\x1b[" (consoleChatName x)
consoleChatNameSuffix x = isSuffixOf "\x1b[0m" (consoleChatName x)
tests = [("unpackNibbles/mod2", quickCheck unpackNibblesMod2)
,("packNibbles.unpackNibbles/id", quickCheck packUnpackNibbles)
,("hashStringIndex/range", quickCheck hashStringIndexRange)
,("betaChatName/head", quickCheck betaChatNameHead)
,("betaChatName/suffix", quickCheck betaChatNameSuffix)
,("consoleChatName/prefix", quickCheck consoleChatNamePrefix)
,("consoleChatName/suffix", quickCheck consoleChatNameSuffix)]