/
mathstuff.tests.html
106 lines (91 loc) · 3.46 KB
/
mathstuff.tests.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
<script type="text/javascript" src="mathstuff.js"></script>
<script>
$(document).ready(function(){
module("Sum");
test("sum returns zero when given nothing", function() {
var value = $('input[name=nothing]').sum();
equal(value, 0, "should return zero" );
});
test("sum returns 1 when given a single-item selector with value of ", function() {
$('input[name=one]').val(1);
var value = $('input[name=one]').sum();
equal(value, 1, "should return 1");
});
test("sum returns 2 when given a single-item selector with value of 2", function() {
$('input[name=one]').val(2);
var value = $('input[name=one]').sum();
equal(value, 2, "should return 2");
});
test("sum returns 0 when given a single-item selector with value of NaN", function() {
$('input[name=one]').val(NaN);
var value = $('input[name=one]').sum();
equal(value, 0, "should return 0");
});
test("sum returns 0 when given a single-item selector with non-numeric value", function() {
$('input[name=one]').val("abc");
var value = $('input[name=one]').sum();
equal(value, 0, "should return 0");
});
test("sum returns 3 when given a two-item selector with total of 3", function() {
$('#B1').val(1);
$('#B2').val(2);
var value = $('.two').sum();
equal(value, 3, "should return 3");
});
test("sum returns 3 when given a three-item selector with total of 3 and a bad item", function() {
$('#C1').val(1);
$('#C2').val(2);
$('#C3').val("abc");
var value = $('.three').sum();
equal(value, 3, "should return 3");
});
test("sum returns 1.3 when given a two-item selector with total of 1.3", function() {
$('#B1').val(0.9);
$('#B2').val(0.4);
var value = $('.two').sum();
equal(value, 1.3, "should return 1.3");
});
module("Multiply");
test("returns 0 when given no items", function(){
var value = $('input[name=nothing]').multiply();
equal(value, 0, "should return zero" );
});
test("returns 1 when given one item of value 1", function(){
$('input[name=one]').val(1);
var value = $('input[name=one]').multiply();
equal(value, 1, "should return one" );
});
test("returns 6 when given two items that multiply to 6", function(){
$('#B1').val(2);
$('#B2').val(3);
var value = $('.two').multiply();
equal(value, 6, "should return six" );
});
});
</script>
</head>
<body>
<h1 id="qunit-header">QUnit example</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<form>
<input name="one" />
<input class="two" id="B1" />
<input class="two" id="B2" />
<input class="three" id="C1" />
<input class="three" id="C2" />
<input class="three" id="C3" />
</form>
</div>
</body>
</html>