diff options
author | pacien | 2018-12-02 00:38:12 +0100 |
---|---|---|
committer | pacien | 2018-12-02 00:38:12 +0100 |
commit | 56bfed7e2cdd44dc4ad0c5e233224cf0080e05ac (patch) | |
tree | d42919fdf57f7f014ca0c0db1a7a55e1465a0135 /tests | |
parent | 5cc4256a931b98ea167291397421d0db60c5d40c (diff) | |
download | gziplike-56bfed7e2cdd44dc4ad0c5e233224cf0080e05ac.tar.gz |
replace linkedlists by seqs
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tlzss.nim | 51 | ||||
-rw-r--r-- | tests/tlzsshuffman.nim | 8 |
2 files changed, 21 insertions, 38 deletions
diff --git a/tests/tlzss.nim b/tests/tlzss.nim index b6b3c51..ad667e5 100644 --- a/tests/tlzss.nim +++ b/tests/tlzss.nim | |||
@@ -15,33 +15,24 @@ | |||
15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | import unittest, sequtils, tables, lists | 17 | import unittest, sequtils, tables, lists |
18 | import lzss/listpolyfill, lzss/matchtable, lzss/lzssnode, lzss/lzsschain, lzss/lzssencoder | 18 | import lzss/matchtable, lzss/lzssnode, lzss/lzsschain, lzss/lzssencoder |
19 | |||
20 | suite "listpolyfill": | ||
21 | test "append": | ||
22 | const data = [1, 2, 3, 4, 5, 6] | ||
23 | var L: SinglyLinkedList[int] | ||
24 | for d in items(data): listpolyfill.prepend(L, d) | ||
25 | for d in items(data): listpolyfill.append(L, d) | ||
26 | check $L == "[6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6]" | ||
27 | check 4 in L | ||
28 | 19 | ||
29 | suite "matchtable": | 20 | suite "matchtable": |
30 | test "matchList": | 21 | test "matchList": |
31 | let matchTable = initMatchTable(seq[int], int) | 22 | let matchTable = initMatchTable(seq[int], int) |
32 | check toSeq(matchTable.matchList(@[0, 1, 2]).items).len == 0 | 23 | check matchTable.matchList(@[0, 1, 2]).len == 0 |
33 | 24 | ||
34 | test "addMatch": | 25 | test "addMatch": |
35 | let matchTable = initMatchTable(seq[int], int) | 26 | let matchTable = initMatchTable(seq[int], int) |
36 | matchTable.addMatch(@[0, 1, 2], 42) | 27 | matchTable.addMatch(@[0, 1, 2], 42) |
37 | matchTable.addMatch(@[2, 1, 0], 24) | 28 | matchTable.addMatch(@[2, 1, 0], 24) |
38 | check matchTable.len == 2 | 29 | check matchTable.len == 2 |
39 | check toSeq(matchTable.matchList(@[0, 1, 2]).items) == @[42] | 30 | check matchTable.matchList(@[0, 1, 2]) == [42] |
40 | check toSeq(matchTable.matchList(@[2, 1, 0]).items) == @[24] | 31 | check matchTable.matchList(@[2, 1, 0]) == [24] |
41 | matchTable.addMatch(@[0, 1, 2], 1337) | 32 | matchTable.addMatch(@[0, 1, 2], 1337) |
42 | check matchTable.len == 2 | 33 | check matchTable.len == 2 |
43 | check toSeq(matchTable.matchList(@[0, 1, 2]).items) == @[1337, 42] | 34 | check matchTable.matchList(@[0, 1, 2]) == [1337, 42] |
44 | check toSeq(matchTable.matchList(@[2, 1, 0]).items) == @[24] | 35 | check matchTable.matchList(@[2, 1, 0]) == [24] |
45 | 36 | ||
46 | suite "lzssnode": | 37 | suite "lzssnode": |
47 | test "equality": | 38 | test "equality": |
@@ -52,19 +43,14 @@ suite "lzssnode": | |||
52 | check lzssCharacter(0) != lzssReference(0, 1) | 43 | check lzssCharacter(0) != lzssReference(0, 1) |
53 | 44 | ||
54 | suite "lzsschain": | 45 | suite "lzsschain": |
55 | proc chain(): LzssChain = | 46 | test "decode": |
56 | let chainArray = [ | 47 | let chain = lzssChain([ |
57 | lzssCharacter(0), lzssCharacter(1), lzssCharacter(2), | 48 | lzssCharacter(0), lzssCharacter(1), lzssCharacter(2), |
58 | lzssCharacter(3), lzssCharacter(4), lzssCharacter(5), | 49 | lzssCharacter(3), lzssCharacter(4), lzssCharacter(5), |
59 | lzssReference(4, 6), lzssCharacter(0), lzssCharacter(1), | 50 | lzssReference(4, 6), lzssCharacter(0), lzssCharacter(1), |
60 | lzssReference(3, 8), lzssCharacter(5), | 51 | lzssReference(3, 8), lzssCharacter(5), |
61 | lzssReference(3, 3), lzssCharacter(5)] | 52 | lzssReference(3, 3), lzssCharacter(5)]) |
62 | var chain = lzssChain() | 53 | check chain.decode() == @[0'u8, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 4, 5, 0, 5, 5, 0, 5, 5] |
63 | for node in chainArray: chain.append(node) | ||
64 | result = chain | ||
65 | |||
66 | test "decode": | ||
67 | check chain().decode() == @[0'u8, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 4, 5, 0, 5, 5, 0, 5, 5] | ||
68 | 54 | ||
69 | suite "lzssencoder": | 55 | suite "lzssencoder": |
70 | test "commonPrefixLength": | 56 | test "commonPrefixLength": |
@@ -80,10 +66,7 @@ suite "lzssencoder": | |||
80 | 0, 1, 2, 3, | 66 | 0, 1, 2, 3, |
81 | 0, 1, 2, | 67 | 0, 1, 2, |
82 | 0, 1, 2, 3, 4] | 68 | 0, 1, 2, 3, 4] |
83 | var candidatePos = initSinglyLinkedList[int]() | 69 | var candidatePos = [0, 4, 8] |
84 | listpolyfill.prepend(candidatePos, 0) | ||
85 | listpolyfill.prepend(candidatePos, 4) | ||
86 | listpolyfill.prepend(candidatePos, 8) | ||
87 | let result = longestPrefix(candidatePos, buffer.toOpenArray(0, 10), buffer.toOpenArray(11, buffer.len - 1)) | 70 | let result = longestPrefix(candidatePos, buffer.toOpenArray(0, 10), buffer.toOpenArray(11, buffer.len - 1)) |
88 | check result.pos == 4 | 71 | check result.pos == 4 |
89 | check result.length == 4 | 72 | check result.length == 4 |
@@ -95,15 +78,15 @@ suite "lzssencoder": | |||
95 | check matchTable.len == 0 | 78 | check matchTable.len == 0 |
96 | matchTable.addGroups(buffer, 2, 9) | 79 | matchTable.addGroups(buffer, 2, 9) |
97 | check matchTable.len == 5 | 80 | check matchTable.len == 5 |
98 | check toSeq(matchTable.matchList(@[1'u8, 2, 3]).items).len == 0 | 81 | check matchTable.matchList(@[1'u8, 2, 3]).len == 0 |
99 | check toSeq(matchTable.matchList(@[7'u8, 8, 9]).items).len == 0 | 82 | check matchTable.matchList(@[7'u8, 8, 9]).len == 0 |
100 | check toSeq(matchTable.matchList(@[2'u8, 3, 4]).items) == @[2] | 83 | check matchTable.matchList(@[2'u8, 3, 4]) == [2] |
101 | check toSeq(matchTable.matchList(@[4'u8, 5, 6]).items) == @[4] | 84 | check matchTable.matchList(@[4'u8, 5, 6]) == [4] |
102 | check toSeq(matchTable.matchList(@[6'u8, 7, 8]).items) == @[6] | 85 | check matchTable.matchList(@[6'u8, 7, 8]) == [6] |
103 | 86 | ||
104 | test "lzssEncode": | 87 | test "lzssEncode": |
105 | let buffer = [0'u8, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 4, 5, 0, 5, 5, 0, 5, 5] | 88 | let buffer = [0'u8, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 4, 5, 0, 5, 5, 0, 5, 5] |
106 | check toSeq(lzssEncode(buffer).items) == @[ | 89 | check lzssEncode(buffer) == [ |
107 | lzssCharacter(0), lzssCharacter(1), lzssCharacter(2), | 90 | lzssCharacter(0), lzssCharacter(1), lzssCharacter(2), |
108 | lzssCharacter(3), lzssCharacter(4), lzssCharacter(5), | 91 | lzssCharacter(3), lzssCharacter(4), lzssCharacter(5), |
109 | lzssReference(4, 6), lzssCharacter(0), lzssCharacter(1), | 92 | lzssReference(4, 6), lzssCharacter(0), lzssCharacter(1), |
diff --git a/tests/tlzsshuffman.nim b/tests/tlzsshuffman.nim index f771f31..bd729e6 100644 --- a/tests/tlzsshuffman.nim +++ b/tests/tlzsshuffman.nim | |||
@@ -14,9 +14,9 @@ | |||
14 | # You should have received a copy of the GNU Affero General Public License | 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/>. | 15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | import unittest, tables, lists, sequtils, streams | 17 | import unittest, tables, sequtils, streams |
18 | import bitio/bitwriter, bitio/bitreader | 18 | import bitio/bitwriter, bitio/bitreader |
19 | import lzss/listpolyfill, lzss/lzssnode, lzss/lzsschain | 19 | import lzss/lzssnode, lzss/lzsschain |
20 | import huffman/huffmantree, huffman/huffmantreebuilder, huffman/huffmanencoder, huffman/huffmandecoder | 20 | import huffman/huffmantree, huffman/huffmantreebuilder, huffman/huffmanencoder, huffman/huffmandecoder |
21 | import lzsshuffman/lzsshuffmansymbol, lzsshuffman/lzsshuffmanstats, lzsshuffman/lzsshuffmanencoder, lzsshuffman/lzsshuffmandecoder | 21 | import lzsshuffman/lzsshuffmansymbol, lzsshuffman/lzsshuffmanstats, lzsshuffman/lzsshuffmanencoder, lzsshuffman/lzsshuffmandecoder |
22 | 22 | ||
@@ -109,7 +109,7 @@ suite "lzsshuffmandecoder": | |||
109 | stream.setPosition(0) | 109 | stream.setPosition(0) |
110 | let bitReader = stream.bitReader() | 110 | let bitReader = stream.bitReader() |
111 | let result = readChain(bitReader, symbolTree.decoder(), positionTree.decoder(), 32_000) | 111 | let result = readChain(bitReader, symbolTree.decoder(), positionTree.decoder(), 32_000) |
112 | check toSeq(result.items).len == 0 | 112 | check result.len == 0 |
113 | 113 | ||
114 | test "readChain (minimal)": | 114 | test "readChain (minimal)": |
115 | let symbolTree = huffmanBranch( | 115 | let symbolTree = huffmanBranch( |
@@ -139,6 +139,6 @@ suite "lzsshuffmandecoder": | |||
139 | stream.setPosition(0) | 139 | stream.setPosition(0) |
140 | let bitReader = stream.bitReader() | 140 | let bitReader = stream.bitReader() |
141 | let result = readChain(bitReader, symbolTree.decoder(), positionTree.decoder(), 32_000) | 141 | let result = readChain(bitReader, symbolTree.decoder(), positionTree.decoder(), 32_000) |
142 | check toSeq(result.items) == [ | 142 | check result == [ |
143 | lzssCharacter(0), lzssCharacter(1), lzssCharacter(2), | 143 | lzssCharacter(0), lzssCharacter(1), lzssCharacter(2), |
144 | lzssReference(3, 3), lzssReference(3, 4)] | 144 | lzssReference(3, 3), lzssReference(3, 4)] |