From 925f8d7176c3d54d435896ec0d2eabda634bbcc8 Mon Sep 17 00:00:00 2001
From: pacien
Date: Mon, 3 Dec 2018 18:42:23 +0100
Subject: merge tests
---
tests/lzss/tlzsschain.nim | 29 ++++++++++++++++++++++
tests/lzss/tlzssencoder.nim | 59 +++++++++++++++++++++++++++++++++++++++++++++
tests/lzss/tlzssnode.nim | 26 ++++++++++++++++++++
tests/lzss/tmatchring.nim | 35 +++++++++++++++++++++++++++
tests/lzss/tmatchtable.nim | 29 ++++++++++++++++++++++
5 files changed, 178 insertions(+)
create mode 100644 tests/lzss/tlzsschain.nim
create mode 100644 tests/lzss/tlzssencoder.nim
create mode 100644 tests/lzss/tlzssnode.nim
create mode 100644 tests/lzss/tmatchring.nim
create mode 100644 tests/lzss/tmatchtable.nim
(limited to 'tests/lzss')
diff --git a/tests/lzss/tlzsschain.nim b/tests/lzss/tlzsschain.nim
new file mode 100644
index 0000000..92bee0f
--- /dev/null
+++ b/tests/lzss/tlzsschain.nim
@@ -0,0 +1,29 @@
+# gzip-like LZSS compressor
+# Copyright (C) 2018 Pacien TRAN-GIRARD
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
+import unittest
+import lzss/lzssnode, lzss/lzsschain
+
+suite "lzsschain":
+ 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)])
+ check chain.decode() == @[0'u8, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 4, 5, 0, 5, 5, 0, 5, 5]
+
\ No newline at end of file
diff --git a/tests/lzss/tlzssencoder.nim b/tests/lzss/tlzssencoder.nim
new file mode 100644
index 0000000..48477d7
--- /dev/null
+++ b/tests/lzss/tlzssencoder.nim
@@ -0,0 +1,59 @@
+# gzip-like LZSS compressor
+# Copyright (C) 2018 Pacien TRAN-GIRARD
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
+import unittest, sequtils
+import lzss/matchring, lzss/matchtable, lzss/lzssnode, lzss/lzssencoder
+
+suite "lzssencoder":
+ test "commonPrefixLength":
+ check commonPrefixLength([], [], 10) == 0
+ check commonPrefixLength([1'u8, 2], [1'u8, 2, 3], 10) == 2
+ check commonPrefixLength([1'u8, 2], [1'u8, 2, 3], 10) == 2
+ check commonPrefixLength([1'u8, 2, 3], [1'u8, 2, 4], 10) == 2
+ check commonPrefixLength([1'u8, 2, 3, 4], [1'u8, 2, 3, 4], 3) == 3
+
+ test "longestPrefix":
+ let buffer = [
+ 0'u8, 1, 2, 9,
+ 0, 1, 2, 3,
+ 0, 1, 2,
+ 0, 1, 2, 3, 4]
+ var candidatePos = [0, 4, 8]
+ var matchRing = initMatchRing()
+ for pos in candidatePos: matchRing.addMatch(pos)
+ let result = longestPrefix(matchRing, buffer.toOpenArray(0, 10), buffer.toOpenArray(11, buffer.len - 1))
+ check result.pos == 4
+ check result.length == 4
+
+ test "addGroups":
+ var matchTable = initMatchTable()
+ let buffer = toSeq(0'u8..10'u8)
+ matchTable.addGroups(buffer, 0, 1)
+ matchTable.addGroups(buffer, 2, 9)
+ check toSeq(matchTable.candidates([1'u8, 2, 3]).items).len == 0
+ check toSeq(matchTable.candidates([7'u8, 8, 9]).items).len == 0
+ check toSeq(matchTable.candidates([2'u8, 3, 4]).items) == [2]
+ check toSeq(matchTable.candidates([4'u8, 5, 6]).items) == [4]
+ check toSeq(matchTable.candidates([6'u8, 7, 8]).items) == [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 lzssEncode(buffer) == [
+ 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)]
diff --git a/tests/lzss/tlzssnode.nim b/tests/lzss/tlzssnode.nim
new file mode 100644
index 0000000..7675fc0
--- /dev/null
+++ b/tests/lzss/tlzssnode.nim
@@ -0,0 +1,26 @@
+# gzip-like LZSS compressor
+# Copyright (C) 2018 Pacien TRAN-GIRARD
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
+import unittest
+import lzss/lzssnode
+
+suite "lzssnode":
+ test "equality":
+ check lzssCharacter(1) == lzssCharacter(1)
+ check lzssCharacter(0) != lzssCharacter(1)
+ check lzssReference(0, 1) == lzssReference(0, 1)
+ check lzssReference(1, 0) != lzssReference(0, 1)
+ check lzssCharacter(0) != lzssReference(0, 1)
diff --git a/tests/lzss/tmatchring.nim b/tests/lzss/tmatchring.nim
new file mode 100644
index 0000000..ccf3856
--- /dev/null
+++ b/tests/lzss/tmatchring.nim
@@ -0,0 +1,35 @@
+# gzip-like LZSS compressor
+# Copyright (C) 2018 Pacien TRAN-GIRARD
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
+import unittest, sequtils, algorithm
+import lzss/matchring
+
+suite "matchring":
+ test "items (empty)":
+ var ring = initMatchRing()
+ check toSeq(ring.items).len == 0
+
+ test "addMatch, items (partial)":
+ var ring = initMatchRing()
+ let items = [0, 1, 2]
+ for i in items: ring.addMatch(i)
+ check toSeq(ring.items) == items.reversed()
+
+ test "addMatch, items (rolling)":
+ var ring = initMatchRing()
+ let items = toSeq(0..13)
+ for i in items: ring.addMatch(i)
+ check toSeq(ring.items) == items[^matchLimit...
+
+import unittest, sequtils
+import lzss/matchring, lzss/matchtable
+
+suite "matchtable":
+ test "addMatch":
+ var matchTable = initMatchTable()
+ matchTable.addMatch([0'u8, 1, 2], 42)
+ matchTable.addMatch([2'u8, 1, 0], 24)
+ check toSeq(matchTable.candidates([0'u8, 1, 2]).items) == [42]
+ check toSeq(matchTable.candidates([2'u8, 1, 0]).items) == [24]
+ matchTable.addMatch([0'u8, 1, 2], 1337)
+ check toSeq(matchTable.candidates([0'u8, 1, 2]).items) == [1337, 42]
+ check toSeq(matchTable.candidates([2'u8, 1, 0]).items) == [24]
--
cgit v1.2.3