-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
84 lines (84 loc) · 2.09 KB
/
test.html
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
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="str_calc.js"></script>
<script type="text/javascript">
function testStart() {
var cases = [
{
in: "1,2,3",
out: 6,
reason: "Standard input"
},
{
in: "//.\n1.2.3",
out: 6,
reason: "Standard use of custom delimeter"
},
{
in: "",
out: 0,
reason: "No input"
},
{
in: "//,\n,,,",
out: null,
reason: "Only separators"
},
{
in: "1001,3000,5000",
out: 9001,
reason: "Large number"
},
{
in: "0,0,0",
out: 0,
reason: "sum to zero"
},
{
in: "nope",
out: null,
reason: "blatantly invalid input"
},
{
in: "//ab\n1ab2ab3",
out: 6,
reason: "greater than one delimiter"
},
{
in: "//\n123",
out: 6,
reason: "empty delimeter"
},
{
in: "1,2,-3",
out: null,
reason: "use of negatives"
},
{
in: "//-\n1-2-3",
out: 6,
reason: "Use of dash as delimiter"
},
{
in: "1,1001,2,3",
out: 6,
reason: "Number greater than 1000"
}
]
for (var i=0; i<cases.length; i++) {
var result = string_to_Sum(cases[i].in)
console.log(`Case #${i}: "${cases[i].in}" > ${result}`);
if (result === cases[i].out) {
console.log(cases[i].reason + " case SUCESS");
} else {
console.log(cases[i].reason + " case FAILURE!\nExpected " + cases[i].out);
}
}
}
</script>
</head>
<body onload="testStart()">
Running test cases, refer to console.
</body>
</html>