aboutsummaryrefslogtreecommitdiff
path: root/tests/gziplike/tgziplike.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/gziplike/tgziplike.nim')
-rw-r--r--tests/gziplike/tgziplike.nim40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/gziplike/tgziplike.nim b/tests/gziplike/tgziplike.nim
new file mode 100644
index 0000000..b26a453
--- /dev/null
+++ b/tests/gziplike/tgziplike.nim
@@ -0,0 +1,40 @@
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
17import unittest, os, ospaths, osproc, times
18import gziplike
19
20suite "main":
21 const tempDir = "tmp"
22
23 proc testIdentity(input: string, intermediate = tempDir / "compressed", final = tempDir / "decompressed"): bool =
24 let compressionStartTime = getTime()
25 compress.transform(input, intermediate)
26 echo("compression done in ", getTime() - compressionStartTime)
27 echo("compression ratio: ", (intermediate.getFileSize() * 100) div input.getFileSize(), "%")
28 let decompressionStartTime = getTime()
29 decompress.transform(intermediate, final)
30 echo("decompression done in ", getTime() - decompressionStartTime)
31 startProcess("cmp", args=[input, final], options={poUsePath}).waitForExit() == 0
32
33 setup: createDir(tempDir)
34 teardown: removeDir(tempDir)
35
36 test "identity (text)":
37 check testIdentity("license.md")
38
39 test "identity (binary)":
40 check testIdentity("tests" / "tests")