diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tbitio.nim (renamed from tests/tbitreader.nim) | 70 | ||||
-rw-r--r-- | tests/tbitwriter.nim | 85 | ||||
-rw-r--r-- | tests/thuffmandecoder.nim | 2 | ||||
-rw-r--r-- | tests/thuffmanencoder.nim | 2 | ||||
-rw-r--r-- | tests/thuffmantree.nim | 2 | ||||
-rw-r--r-- | tests/trawblock.nim | 2 | ||||
-rw-r--r-- | tests/tstreamblock.nim | 2 |
7 files changed, 74 insertions, 91 deletions
diff --git a/tests/tbitreader.nim b/tests/tbitio.nim index 294f6c9..0391974 100644 --- a/tests/tbitreader.nim +++ b/tests/tbitio.nim | |||
@@ -15,7 +15,8 @@ | |||
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, streams, sugar, sequtils | 17 | import unittest, streams, sugar, sequtils |
18 | import integers, bitreader | 18 | import integers |
19 | import bitio/bitreader, bitio/bitwriter | ||
19 | 20 | ||
20 | suite "bitreader": | 21 | suite "bitreader": |
21 | test "readBool": | 22 | test "readBool": |
@@ -82,3 +83,70 @@ suite "bitreader": | |||
82 | check bitReader.readSeq(32, uint16) == (32, @[0xF0F0'u16, 0xF0F0]) | 83 | check bitReader.readSeq(32, uint16) == (32, @[0xF0F0'u16, 0xF0F0]) |
83 | check bitReader.readSeq(40, uint8) == (32, @[0xFF'u8, 0xF0, 0x00, 0x0F]) | 84 | check bitReader.readSeq(40, uint8) == (32, @[0xFF'u8, 0xF0, 0x00, 0x0F]) |
84 | check bitReader.atEnd() | 85 | check bitReader.atEnd() |
86 | |||
87 | suite "bitwriter": | ||
88 | test "flush": | ||
89 | let stream = newStringStream() | ||
90 | defer: stream.close() | ||
91 | let bitWriter = stream.bitWriter() | ||
92 | |||
93 | bitWriter.writeBool(true) | ||
94 | stream.setPosition(0) | ||
95 | expect IOError: discard stream.peekUint8() | ||
96 | |||
97 | bitWriter.flush() | ||
98 | stream.setPosition(0) | ||
99 | check stream.readUint8() == 0x01'u8 | ||
100 | check stream.atEnd() | ||
101 | |||
102 | bitWriter.flush() | ||
103 | check stream.atEnd() | ||
104 | |||
105 | test "writeBool": | ||
106 | let stream = newStringStream() | ||
107 | defer: stream.close() | ||
108 | |||
109 | let bitWriter = stream.bitWriter() | ||
110 | let booleanValues = @[ | ||
111 | true, true, true, true, true, false, false, true, | ||
112 | false, false, false, false, false, true, true, false, | ||
113 | true, true, false, true] | ||
114 | for b in booleanValues: bitWriter.writeBool(b) | ||
115 | bitWriter.flush() | ||
116 | |||
117 | stream.setPosition(0) | ||
118 | check stream.readUint8() == 0b1001_1111'u8 | ||
119 | check stream.readUint8() == 0b0110_0000'u8 | ||
120 | check stream.readUint8() == 0b0000_1011'u8 | ||
121 | expect IOError: discard stream.readUint8() | ||
122 | check stream.atEnd() | ||
123 | |||
124 | test "writeBits": | ||
125 | let stream = newStringStream() | ||
126 | defer: stream.close() | ||
127 | |||
128 | let bitWriter = stream.bitWriter() | ||
129 | bitWriter.writeBits(4, 0xF00F'u16) | ||
130 | bitWriter.writeBits(16, 0xF00F'u16) | ||
131 | bitWriter.writeBits(16, 0xFFFF'u16) | ||
132 | bitWriter.flush() | ||
133 | |||
134 | stream.setPosition(0) | ||
135 | check stream.readUint16() == 0x00FF'u16 | ||
136 | check stream.readUint16() == 0xFFFF'u16 | ||
137 | check stream.readUint8() == 0x0F'u8 | ||
138 | expect IOError: discard stream.readUint8() | ||
139 | check stream.atEnd() | ||
140 | |||
141 | test "writeSeq": | ||
142 | let stream = newStringStream() | ||
143 | defer: stream.close() | ||
144 | |||
145 | let bitWriter = stream.bitWriter() | ||
146 | bitWriter.writeSeq(32, @[0xF0F0'u16, 0xF0F0]) | ||
147 | bitWriter.writeSeq(28, @[0xFF'u8, 0xF0, 0x00, 0xFF]) | ||
148 | bitWriter.flush() | ||
149 | |||
150 | stream.setPosition(0) | ||
151 | check stream.readUint64() == 0x0F00_F0FF_F0F0_F0F0'u64 | ||
152 | check stream.atEnd() | ||
diff --git a/tests/tbitwriter.nim b/tests/tbitwriter.nim deleted file mode 100644 index 2c570af..0000000 --- a/tests/tbitwriter.nim +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
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, streams | ||
18 | import integers, bitwriter | ||
19 | |||
20 | suite "bitwriter": | ||
21 | test "flush": | ||
22 | let stream = newStringStream() | ||
23 | defer: stream.close() | ||
24 | let bitWriter = stream.bitWriter() | ||
25 | |||
26 | bitWriter.writeBool(true) | ||
27 | stream.setPosition(0) | ||
28 | expect IOError: discard stream.peekUint8() | ||
29 | |||
30 | bitWriter.flush() | ||
31 | stream.setPosition(0) | ||
32 | check stream.readUint8() == 0x01'u8 | ||
33 | check stream.atEnd() | ||
34 | |||
35 | bitWriter.flush() | ||
36 | check stream.atEnd() | ||
37 | |||
38 | test "writeBool": | ||
39 | let stream = newStringStream() | ||
40 | defer: stream.close() | ||
41 | |||
42 | let bitWriter = stream.bitWriter() | ||
43 | let booleanValues = @[ | ||
44 | true, true, true, true, true, false, false, true, | ||
45 | false, false, false, false, false, true, true, false, | ||
46 | true, true, false, true] | ||
47 | for b in booleanValues: bitWriter.writeBool(b) | ||
48 | bitWriter.flush() | ||
49 | |||
50 | stream.setPosition(0) | ||
51 | check stream.readUint8() == 0b1001_1111'u8 | ||
52 | check stream.readUint8() == 0b0110_0000'u8 | ||
53 | check stream.readUint8() == 0b0000_1011'u8 | ||
54 | expect IOError: discard stream.readUint8() | ||
55 | check stream.atEnd() | ||
56 | |||
57 | test "writeBits": | ||
58 | let stream = newStringStream() | ||
59 | defer: stream.close() | ||
60 | |||
61 | let bitWriter = stream.bitWriter() | ||
62 | bitWriter.writeBits(4, 0xF00F'u16) | ||
63 | bitWriter.writeBits(16, 0xF00F'u16) | ||
64 | bitWriter.writeBits(16, 0xFFFF'u16) | ||
65 | bitWriter.flush() | ||
66 | |||
67 | stream.setPosition(0) | ||
68 | check stream.readUint16() == 0x00FF'u16 | ||
69 | check stream.readUint16() == 0xFFFF'u16 | ||
70 | check stream.readUint8() == 0x0F'u8 | ||
71 | expect IOError: discard stream.readUint8() | ||
72 | check stream.atEnd() | ||
73 | |||
74 | test "writeSeq": | ||
75 | let stream = newStringStream() | ||
76 | defer: stream.close() | ||
77 | |||
78 | let bitWriter = stream.bitWriter() | ||
79 | bitWriter.writeSeq(32, @[0xF0F0'u16, 0xF0F0]) | ||
80 | bitWriter.writeSeq(28, @[0xFF'u8, 0xF0, 0x00, 0xFF]) | ||
81 | bitWriter.flush() | ||
82 | |||
83 | stream.setPosition(0) | ||
84 | check stream.readUint64() == 0x0F00_F0FF_F0F0_F0F0'u64 | ||
85 | check stream.atEnd() | ||
diff --git a/tests/thuffmandecoder.nim b/tests/thuffmandecoder.nim index d4d81b4..9b44e9d 100644 --- a/tests/thuffmandecoder.nim +++ b/tests/thuffmandecoder.nim | |||
@@ -15,7 +15,7 @@ | |||
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, streams | 17 | import unittest, streams |
18 | import bitreader, bitwriter | 18 | import bitio/bitreader, bitio/bitwriter |
19 | import huffmantree, huffmandecoder | 19 | import huffmantree, huffmandecoder |
20 | 20 | ||
21 | suite "huffdecoder": | 21 | suite "huffdecoder": |
diff --git a/tests/thuffmanencoder.nim b/tests/thuffmanencoder.nim index 04318b7..9c46eed 100644 --- a/tests/thuffmanencoder.nim +++ b/tests/thuffmanencoder.nim | |||
@@ -15,7 +15,7 @@ | |||
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, streams, tables | 17 | import unittest, streams, tables |
18 | import bitreader, bitwriter | 18 | import bitio/bitreader, bitio/bitwriter |
19 | import huffmantree, huffmanencoder | 19 | import huffmantree, huffmanencoder |
20 | 20 | ||
21 | suite "huffencoder": | 21 | suite "huffencoder": |
diff --git a/tests/thuffmantree.nim b/tests/thuffmantree.nim index bc6a505..467fac5 100644 --- a/tests/thuffmantree.nim +++ b/tests/thuffmantree.nim | |||
@@ -15,7 +15,7 @@ | |||
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, streams, sequtils, tables, heapqueue | 17 | import unittest, streams, sequtils, tables, heapqueue |
18 | import bitreader, bitwriter, huffmantree | 18 | import bitio/bitreader, bitio/bitwriter, huffmantree |
19 | 19 | ||
20 | suite "huffmantree": | 20 | suite "huffmantree": |
21 | let tree = huffmanBranch( | 21 | let tree = huffmanBranch( |
diff --git a/tests/trawblock.nim b/tests/trawblock.nim index 2544199..0271e33 100644 --- a/tests/trawblock.nim +++ b/tests/trawblock.nim | |||
@@ -15,7 +15,7 @@ | |||
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, streams | 17 | import unittest, streams |
18 | import bitreader, bitwriter, rawblock | 18 | import bitio/bitreader, bitio/bitwriter, rawblock |
19 | 19 | ||
20 | suite "rawblock": | 20 | suite "rawblock": |
21 | test "serialise": | 21 | test "serialise": |
diff --git a/tests/tstreamblock.nim b/tests/tstreamblock.nim index 89f69e0..57eaf3a 100644 --- a/tests/tstreamblock.nim +++ b/tests/tstreamblock.nim | |||
@@ -15,7 +15,7 @@ | |||
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, streams | 17 | import unittest, streams |
18 | import bitreader, bitwriter, streamblock | 18 | import bitio/bitreader, bitio/bitwriter, streamblock |
19 | 19 | ||
20 | suite "streamblock": | 20 | suite "streamblock": |
21 | test "serialise": | 21 | test "serialise": |