diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tlzsschain.nim | 30 | ||||
-rw-r--r-- | tests/tlzssencoder.nim | 62 | ||||
-rw-r--r-- | tests/tlzssnode.nim | 26 | ||||
-rw-r--r-- | tests/tmatchtable.nim | 35 | ||||
-rw-r--r-- | tests/tpolyfill.nim | 27 |
5 files changed, 180 insertions, 0 deletions
diff --git a/tests/tlzsschain.nim b/tests/tlzsschain.nim new file mode 100644 index 0000000..241a0f1 --- /dev/null +++ b/tests/tlzsschain.nim | |||
@@ -0,0 +1,30 @@ | |||
1 | # gzip-like LZSS compressor | ||
2 | # Copyright (C) 2018 Pacien TRAN-GIRARD | ||
3 | # | ||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU Affero General Public License as | ||
6 | # published by the Free Software Foundation, either version 3 of the | ||
7 | # License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU Affero General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU Affero General Public License | ||
15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | |||
17 | import unittest | ||
18 | import polyfill, lzssnode, lzsschain | ||
19 | |||
20 | suite "lzsschain": | ||
21 | test "decode": | ||
22 | let chainArray = [ | ||
23 | lzssCharacter(0), lzssCharacter(1), lzssCharacter(2), | ||
24 | lzssCharacter(3), lzssCharacter(4), lzssCharacter(5), | ||
25 | lzssReference(4, 6), lzssCharacter(0), lzssCharacter(1), | ||
26 | lzssReference(3, 8), lzssCharacter(5), | ||
27 | lzssReference(3, 3), lzssCharacter(5)] | ||
28 | var chain = lzssChain() | ||
29 | for node in chainArray: chain.append(node) | ||
30 | check chain.decode() == @[0'u8, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 4, 5, 0, 5, 5, 0, 5, 5] | ||
diff --git a/tests/tlzssencoder.nim b/tests/tlzssencoder.nim new file mode 100644 index 0000000..253d0ac --- /dev/null +++ b/tests/tlzssencoder.nim | |||
@@ -0,0 +1,62 @@ | |||
1 | # gzip-like LZSS compressor | ||
2 | # Copyright (C) 2018 Pacien TRAN-GIRARD | ||
3 | # | ||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU Affero General Public License as | ||
6 | # published by the Free Software Foundation, either version 3 of the | ||
7 | # License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU Affero General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU Affero General Public License | ||
15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | |||
17 | import unittest, sequtils, lists, tables | ||
18 | import matchtable, lzssnode, lzsschain, lzssencoder | ||
19 | |||
20 | suite "lzssencoder": | ||
21 | test "commonPrefixLength": | ||
22 | check commonPrefixLength([], [], 0, 10) == 0 | ||
23 | check commonPrefixLength([1'u8, 2], [1'u8, 2, 3], 0, 10) == 2 | ||
24 | check commonPrefixLength([1'u8, 2], [1'u8, 2, 3], 1, 10) == 2 | ||
25 | check commonPrefixLength([1'u8, 2, 3], [1'u8, 2, 4], 1, 10) == 2 | ||
26 | check commonPrefixLength([1'u8, 2, 3, 4], [1'u8, 2, 3, 4], 1, 3) == 3 | ||
27 | |||
28 | test "longestPrefix": | ||
29 | let buffer = [ | ||
30 | 0'u8, 1, 2, 9, | ||
31 | 0, 1, 2, 3, | ||
32 | 0, 1, 2, | ||
33 | 0, 1, 2, 3, 4] | ||
34 | var candidatePos = initSinglyLinkedList[int]() | ||
35 | candidatePos.prepend(0) | ||
36 | candidatePos.prepend(4) | ||
37 | candidatePos.prepend(8) | ||
38 | let result = longestPrefix(candidatePos, buffer.toOpenArray(0, 10), buffer.toOpenArray(11, buffer.len - 1)) | ||
39 | check result.pos == 4 | ||
40 | check result.length == 4 | ||
41 | |||
42 | test "addGroups": | ||
43 | let matchTable = initMatchTable(seq[uint8], int) | ||
44 | let buffer = toSeq(0'u8..10'u8) | ||
45 | matchTable.addGroups(buffer, 0, 1) | ||
46 | check matchTable.len == 0 | ||
47 | matchTable.addGroups(buffer, 2, 9) | ||
48 | check matchTable.len == 5 | ||
49 | check toSeq(matchTable.matchList(@[1'u8, 2, 3]).items).len == 0 | ||
50 | check toSeq(matchTable.matchList(@[7'u8, 8, 9]).items).len == 0 | ||
51 | check toSeq(matchTable.matchList(@[2'u8, 3, 4]).items) == @[2] | ||
52 | check toSeq(matchTable.matchList(@[4'u8, 5, 6]).items) == @[4] | ||
53 | check toSeq(matchTable.matchList(@[6'u8, 7, 8]).items) == @[6] | ||
54 | |||
55 | test "lzssEncode": | ||
56 | let buffer = [0'u8, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 4, 5, 0, 5, 5, 0, 5, 5] | ||
57 | check toSeq(lzssEncode(buffer).items) == @[ | ||
58 | lzssCharacter(0), lzssCharacter(1), lzssCharacter(2), | ||
59 | lzssCharacter(3), lzssCharacter(4), lzssCharacter(5), | ||
60 | lzssReference(4, 6), lzssCharacter(0), lzssCharacter(1), | ||
61 | lzssReference(3, 8), lzssCharacter(5), | ||
62 | lzssReference(3, 3), lzssCharacter(5)] | ||
diff --git a/tests/tlzssnode.nim b/tests/tlzssnode.nim new file mode 100644 index 0000000..cb584ab --- /dev/null +++ b/tests/tlzssnode.nim | |||
@@ -0,0 +1,26 @@ | |||
1 | # gzip-like LZSS compressor | ||
2 | # Copyright (C) 2018 Pacien TRAN-GIRARD | ||
3 | # | ||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU Affero General Public License as | ||
6 | # published by the Free Software Foundation, either version 3 of the | ||
7 | # License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU Affero General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU Affero General Public License | ||
15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | |||
17 | import unittest | ||
18 | import lzssnode | ||
19 | |||
20 | suite "lzssnode": | ||
21 | test "equality": | ||
22 | check lzssCharacter(1) == lzssCharacter(1) | ||
23 | check lzssCharacter(0) != lzssCharacter(1) | ||
24 | check lzssReference(0, 1) == lzssReference(0, 1) | ||
25 | check lzssReference(1, 0) != lzssReference(0, 1) | ||
26 | check lzssCharacter(0) != lzssReference(0, 1) | ||
diff --git a/tests/tmatchtable.nim b/tests/tmatchtable.nim new file mode 100644 index 0000000..4b21f1d --- /dev/null +++ b/tests/tmatchtable.nim | |||
@@ -0,0 +1,35 @@ | |||
1 | # gzip-like LZSS compressor | ||
2 | # Copyright (C) 2018 Pacien TRAN-GIRARD | ||
3 | # | ||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU Affero General Public License as | ||
6 | # published by the Free Software Foundation, either version 3 of the | ||
7 | # License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU Affero General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU Affero General Public License | ||
15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | |||
17 | import unittest, lists, sequtils, tables | ||
18 | import matchtable | ||
19 | |||
20 | suite "matchtable": | ||
21 | test "matchList": | ||
22 | let matchTable = initMatchTable(seq[int], int) | ||
23 | check toSeq(matchTable.matchList(@[0, 1, 2]).items).len == 0 | ||
24 | |||
25 | test "addMatch": | ||
26 | let matchTable = initMatchTable(seq[int], int) | ||
27 | matchTable.addMatch(@[0, 1, 2], 42) | ||
28 | matchTable.addMatch(@[2, 1, 0], 24) | ||
29 | check matchTable.len == 2 | ||
30 | check toSeq(matchTable.matchList(@[0, 1, 2]).items) == @[42] | ||
31 | check toSeq(matchTable.matchList(@[2, 1, 0]).items) == @[24] | ||
32 | matchTable.addMatch(@[0, 1, 2], 1337) | ||
33 | check matchTable.len == 2 | ||
34 | check toSeq(matchTable.matchList(@[0, 1, 2]).items) == @[1337, 42] | ||
35 | check toSeq(matchTable.matchList(@[2, 1, 0]).items) == @[24] | ||
diff --git a/tests/tpolyfill.nim b/tests/tpolyfill.nim new file mode 100644 index 0000000..b48eb77 --- /dev/null +++ b/tests/tpolyfill.nim | |||
@@ -0,0 +1,27 @@ | |||
1 | # gzip-like LZSS compressor | ||
2 | # Copyright (C) 2018 Pacien TRAN-GIRARD | ||
3 | # | ||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU Affero General Public License as | ||
6 | # published by the Free Software Foundation, either version 3 of the | ||
7 | # License, or (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU Affero General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU Affero General Public License | ||
15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | |||
17 | import unittest, sugar, lists, tables | ||
18 | import polyfill | ||
19 | |||
20 | suite "polyfill": | ||
21 | test "SinglyLinkedList append": | ||
22 | const data = [1, 2, 3, 4, 5, 6] | ||
23 | var L: SinglyLinkedList[int] | ||
24 | for d in items(data): polyfill.prepend(L, d) | ||
25 | for d in items(data): polyfill.append(L, d) | ||
26 | check $L == "[6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6]" | ||
27 | check 4 in L | ||