Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Working on testing decompression too.

  • Loading branch information...
commit 5df8e713535a2e02043b5df2bf5035208474c7b0 1 parent e4d0969
@nmrugg authored
Showing with 63 additions and 42 deletions.
  1. +63 −42 test/test-node.js
View
105 test/test-node.js
@@ -1,27 +1,66 @@
-var fs = require("fs"),
+"use strict";
+
+var all_tests_pass = true,
+ fs = require("fs"),
path = require("path"),
my_lzma = require("../src/lzma.js").LZMA(),
compression_mode = process.argv[2] || 1,
path_to_files = "files";
+function display_result(str, pass) {
+ ///NOTE: \033[32m makes green text.
+ /// \033[31m makes red text.
+ /// \033[0m resets the text color.
+ console.log("\u001B[3" + (pass ? "2" : "1") + "m" + str + "\u001B[0m");
+}
+
+function decompression_test(content, correct_filename, next)
+{
+ console.log("TODO: test against " + correct_filename)
+ next();
+}
+
+function compression_test(content, next)
+{
+ var comp_start = (new Date).getTime();
+ console.log(" Initial size:", content.length);
+ my_lzma.compress(content, compression_mode, function (result) {
+ var comp_speed = (new Date).getTime() - comp_start,
+ deco_start;
+ console.log(" Compressed size:", result.length);
+
+ deco_start = (new Date).getTime();
+ my_lzma.decompress(result, function (result) {
+ var deco_speed = (new Date).getTime() - deco_start;
+ console.log("Decompressed size:", result.length);
+
+ if (content !== result) {
+ display_result("ERROR: files do not match!", false);
+ console.log();
+ all_tests_pass = false;
+ } else {
+ display_result("Test passed", true);
+ }
+
+ console.log(" Compression time:", comp_speed);
+ console.log("Decompression time:", deco_speed);
+
+ console.log();
+ next();
+ });
+ });
+}
+
fs.readdir(path_to_files, function (err, files) {
- var all_tests_pass = true,
- file_count = files.length,
+ var file_count = files.length,
run_test;
- function display_result(str, pass) {
- ///NOTE: \033[32m makes green text.
- /// \033[31m makes red text.
- /// \033[0m resets the text color.
- console.log("\033[3" + (pass ? "2" : "1") + "m" + str + "\033[0m");
- }
-
if (err) {
throw err;
}
- run_test = function (i) {
+ (function run_test(i) {
var file;
if (i >= file_count) {
if (all_tests_pass) {
@@ -35,42 +74,24 @@ fs.readdir(path_to_files, function (err, files) {
///TODO: Preform a decompress test on *.lzma files.
console.log("File:", file);
- fs.readFile(path.join(path_to_files, file), "utf8", function (erro, content) {
- var comp_start;
-
+ fs.readFile(path.join(path_to_files, file), "utf8", function (err, content) {
if (err) {
throw err;
}
- console.log(" Initial size:", content.length);
- comp_start = (new Date).getTime();
- my_lzma.compress(content, compression_mode, function (result) {
- var comp_speed = (new Date).getTime() - comp_start,
- deco_start;
- console.log(" Compressed size:", result.length);
-
- deco_start = (new Date).getTime();
- my_lzma.decompress(result, function (result) {
- var deco_speed = (new Date).getTime() - deco_start;
- console.log("Decompressed size:", result.length);
-
- if (content !== result) {
- display_result("ERROR: files do not match!", false);
- console.log();
- all_tests_pass = false;
- } else {
- display_result("Test passed", true);
- }
-
- console.log(" Compression time:", comp_speed);
- console.log("Decompression time:", deco_speed);
-
- console.log();
+ if (file.slice(-5) === ".lzma") {
+ /// Preform a decompress test on *.lzma files.
+ decompression_test(content, path.join(path_to_files, file.slice(0, -5)), function next()
+ {
run_test(i + 1);
});
- });
+ } else {
+ /// Preform a compression/decompression test.
+ compression_test(content, function next()
+ {
+ run_test(i + 1);
+ });
+ }
});
- };
-
- run_test(0);
+ }(0));
});
Please sign in to comment.
Something went wrong with that request. Please try again.