-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
85 lines (72 loc) · 1.74 KB
/
test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var test$ = function() {
window.answerList = {
A: $("div"),
B: $("img.some_class"),
C: $("#some_id"),
D: $(".some_class"),
E: $("input#some_id"),
F: $("div#some_id.some_class"),
G: $("div.some_class#some_id")
}
var expectedResult = {
A: {
DIV: 2
},
B: {
IMG: 1
},
C: {
DIV: 1
},
D: {
DIV: 1,
IMG: 1
},
E: {
},
F: {
DIV: 1
},
G: {
DIV: 1
},
questions: 7
}
var computeString = function(result) {
var returnArray = [];
var divs = result["DIV"] || 0;
var imgs = result["IMG"] || 0;
if (divs === 1) returnArray.push(divs + " DIV");
else returnArray.push(divs + " DIVs");
if (imgs === 1) returnArray.push(imgs + " IMGs");
else returnArray.push(imgs + " IMGs");
return returnArray.join(", ");
}
var testsPassed = 0;
for (answerName in answerList){
var answer = answerList[answerName], i = 0, ii = answer.length, tagList = {};
/* Little patch - answer isn't always a nodeList */
var answerTag = {};
if(ii === undefined) {
answerTag = answer.tagName;
if (tagList[answerTag]) tagList[answerTag]++;
else tagList[answerTag] = 1;
}
else {
for (; i < ii; i++) {
answerTag = answer[i].tagName;
if (tagList[answerTag]) tagList[answerTag]++;
else tagList[answerTag] = 1;
}
}
var expected = computeString(expectedResult[answerName]);
var found = computeString(tagList);
var result = (expected === found) ? "Yes" : "No";
if (result === "Yes") testsPassed++;
console.log("\n------------------------\n\nAnswer", answerName);
console.log("Expected:", expected);
console.log("Found:", found);
console.log("Correct:", result);
}
console.log("\n------------------------\n\nTests Passed:", testsPassed, "of", expectedResult.questions );
}