-
Notifications
You must be signed in to change notification settings - Fork 2
/
regression.js
60 lines (50 loc) · 1.73 KB
/
regression.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var http = require('http');
var fs = require('fs');
eval(fs.readFileSync('./src/parser.js', 'utf8'));
eval(fs.readFileSync('./src/matcher.js', 'utf8'));
eval(fs.readFileSync('./src/scorer.js', 'utf8'));
eval(fs.readFileSync('./src/bestmatch.js', 'utf8'));
console.log("SemiDemi Regression Tests");
// Have a script to build tvs.demi.js from tvs.demi
// Run checker script and update matchers if required (may need ability to run it 'in sections'...)
var matchers = SemiDemi.parse(fs.readFileSync('./tvs.demi', 'utf8'));
var normaliseDemiValue = function (v) {
return v.toLowerCase().replace(/[^a-z0-9]/g, "_");
}
var runTest = function (testdata) {
var expected = normaliseDemiValue(testdata.brand) + "-" + normaliseDemiValue(testdata.model);
var result = SemiDemi.bestMatch(matchers, testdata.uagent);
if (!result) {
if (expected === "generic-smarttv") {
process.stdout.write(". ");
} else {
process.stdout.write("x ");
var msg = "\n\n**No match found*/* for: "+testdata.uagent;
msg += "\n> Expected: "+expected+"";
console.log(msg);
}
return;
}
var actual = result[0].brand+"-"+result[0].model;
if (expected === actual) {
process.stdout.write(". ");
} else {
process.stdout.write("x ");
var msg = "\n\n**FAIL*/*: "+testdata.uagent;
if (result) {
msg += "\n> Expected: "+expected;
msg += "\n> Actual : "+actual;
}
console.log(msg);
}
}
function runTests (tests) {
var start = process.argv[2] || 0;
var end = process.argv[3] || tests.length;
console.log("Num UAs: " + (tests.length+1));
for (var i = start; i < end; i++) {
runTest(tests[i]);
}
console.log("Finished");
}
runTests(JSON.parse(fs.readFileSync('testdata/testdata.json', 'utf8')));