From 56bfed7e2cdd44dc4ad0c5e233224cf0080e05ac Mon Sep 17 00:00:00 2001
From: pacien
Date: Sun, 2 Dec 2018 00:38:12 +0100
Subject: replace linkedlists by seqs
---
tests/tlzss.nim | 51 +++++++++++++++++---------------------------------
tests/tlzsshuffman.nim | 8 ++++----
2 files changed, 21 insertions(+), 38 deletions(-)
(limited to 'tests')
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 @@
# along with this program. If not, see .
import unittest, sequtils, tables, lists
-import lzss/listpolyfill, lzss/matchtable, lzss/lzssnode, lzss/lzsschain, lzss/lzssencoder
-
-suite "listpolyfill":
- test "append":
- const data = [1, 2, 3, 4, 5, 6]
- var L: SinglyLinkedList[int]
- for d in items(data): listpolyfill.prepend(L, d)
- for d in items(data): listpolyfill.append(L, d)
- check $L == "[6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6]"
- check 4 in L
+import lzss/matchtable, lzss/lzssnode, lzss/lzsschain, lzss/lzssencoder
suite "matchtable":
test "matchList":
let matchTable = initMatchTable(seq[int], int)
- check toSeq(matchTable.matchList(@[0, 1, 2]).items).len == 0
+ check matchTable.matchList(@[0, 1, 2]).len == 0
test "addMatch":
let matchTable = initMatchTable(seq[int], int)
matchTable.addMatch(@[0, 1, 2], 42)
matchTable.addMatch(@[2, 1, 0], 24)
check matchTable.len == 2
- check toSeq(matchTable.matchList(@[0, 1, 2]).items) == @[42]
- check toSeq(matchTable.matchList(@[2, 1, 0]).items) == @[24]
+ check matchTable.matchList(@[0, 1, 2]) == [42]
+ check matchTable.matchList(@[2, 1, 0]) == [24]
matchTable.addMatch(@[0, 1, 2], 1337)
check matchTable.len == 2
- check toSeq(matchTable.matchList(@[0, 1, 2]).items) == @[1337, 42]
- check toSeq(matchTable.matchList(@[2, 1, 0]).items) == @[24]
+ check matchTable.matchList(@[0, 1, 2]) == [1337, 42]
+ check matchTable.matchList(@[2, 1, 0]) == [24]
suite "lzssnode":
test "equality":
@@ -52,19 +43,14 @@ suite "lzssnode":
check lzssCharacter(0) != lzssReference(0, 1)
suite "lzsschain":
- proc chain(): LzssChain =
- let chainArray = [
+ test "decode":
+ let chain = lzssChain([
lzssCharacter(0), lzssCharacter(1), lzssCharacter(2),
lzssCharacter(3), lzssCharacter(4), lzssCharacter(5),
lzssReference(4, 6), lzssCharacter(0), lzssCharacter(1),
lzssReference(3, 8), lzssCharacter(5),
- lzssReference(3, 3), lzssCharacter(5)]
- var chain = lzssChain()
- for node in chainArray: chain.append(node)
- result = chain
-
- test "decode":
- check chain().decode() == @[0'u8, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 4, 5, 0, 5, 5, 0, 5, 5]
+ lzssReference(3, 3), lzssCharacter(5)])
+ check chain.decode() == @[0'u8, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 4, 5, 0, 5, 5, 0, 5, 5]
suite "lzssencoder":
test "commonPrefixLength":
@@ -80,10 +66,7 @@ suite "lzssencoder":
0, 1, 2, 3,
0, 1, 2,
0, 1, 2, 3, 4]
- var candidatePos = initSinglyLinkedList[int]()
- listpolyfill.prepend(candidatePos, 0)
- listpolyfill.prepend(candidatePos, 4)
- listpolyfill.prepend(candidatePos, 8)
+ var candidatePos = [0, 4, 8]
let result = longestPrefix(candidatePos, buffer.toOpenArray(0, 10), buffer.toOpenArray(11, buffer.len - 1))
check result.pos == 4
check result.length == 4
@@ -95,15 +78,15 @@ suite "lzssencoder":
check matchTable.len == 0
matchTable.addGroups(buffer, 2, 9)
check matchTable.len == 5
- check toSeq(matchTable.matchList(@[1'u8, 2, 3]).items).len == 0
- check toSeq(matchTable.matchList(@[7'u8, 8, 9]).items).len == 0
- check toSeq(matchTable.matchList(@[2'u8, 3, 4]).items) == @[2]
- check toSeq(matchTable.matchList(@[4'u8, 5, 6]).items) == @[4]
- check toSeq(matchTable.matchList(@[6'u8, 7, 8]).items) == @[6]
+ check matchTable.matchList(@[1'u8, 2, 3]).len == 0
+ check matchTable.matchList(@[7'u8, 8, 9]).len == 0
+ check matchTable.matchList(@[2'u8, 3, 4]) == [2]
+ check matchTable.matchList(@[4'u8, 5, 6]) == [4]
+ check matchTable.matchList(@[6'u8, 7, 8]) == [6]
test "lzssEncode":
let buffer = [0'u8, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 4, 5, 0, 5, 5, 0, 5, 5]
- check toSeq(lzssEncode(buffer).items) == @[
+ check lzssEncode(buffer) == [
lzssCharacter(0), lzssCharacter(1), lzssCharacter(2),
lzssCharacter(3), lzssCharacter(4), lzssCharacter(5),
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 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
-import unittest, tables, lists, sequtils, streams
+import unittest, tables, sequtils, streams
import bitio/bitwriter, bitio/bitreader
-import lzss/listpolyfill, lzss/lzssnode, lzss/lzsschain
+import lzss/lzssnode, lzss/lzsschain
import huffman/huffmantree, huffman/huffmantreebuilder, huffman/huffmanencoder, huffman/huffmandecoder
import lzsshuffman/lzsshuffmansymbol, lzsshuffman/lzsshuffmanstats, lzsshuffman/lzsshuffmanencoder, lzsshuffman/lzsshuffmandecoder
@@ -109,7 +109,7 @@ suite "lzsshuffmandecoder":
stream.setPosition(0)
let bitReader = stream.bitReader()
let result = readChain(bitReader, symbolTree.decoder(), positionTree.decoder(), 32_000)
- check toSeq(result.items).len == 0
+ check result.len == 0
test "readChain (minimal)":
let symbolTree = huffmanBranch(
@@ -139,6 +139,6 @@ suite "lzsshuffmandecoder":
stream.setPosition(0)
let bitReader = stream.bitReader()
let result = readChain(bitReader, symbolTree.decoder(), positionTree.decoder(), 32_000)
- check toSeq(result.items) == [
+ check result == [
lzssCharacter(0), lzssCharacter(1), lzssCharacter(2),
lzssReference(3, 3), lzssReference(3, 4)]
--
cgit v1.2.3