Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 18421680ea
Fetching contributors…

Cannot retrieve contributors at this time

163 lines (136 sloc) 5.359 kb
<!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("returns zero when given nothing", function() {
var value = $('input[name=nothing]').sum();
equal(value, 0, "should return zero" );
});
test("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("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("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("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("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("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("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" );
});
test("returns 0 when given one item that is NaN", function(){
$('input[name=one]').val(NaN);
var value = $('input[name=one]').multiply();
equal(value, 0, "should return zero" );
});
test("returns 0 when given one item that is invalid", function(){
$('input[name=one]').val("abc");
var value = $('input[name=one]').multiply();
equal(value, 0, "should return zero" );
});
test("returns 2.2 when given two items that multiply to 2.2", function(){
$('#B1').val(2);
$('#B2').val(1.1);
var value = $('.two').multiply();
equal(value, 2.2, "should return 2.2" );
});
module("FormatAsDollars");
test("returns 1.23 when given 1.23", function(){
var value = $.formatAsDollars(1.23);
equal(value, "1.23", "should return 1.23");
});
test("returns 2.79 when given 2.79", function(){
var value = $.formatAsDollars(2.79);
equal(value, "2.79", "should return 2.79");
});
test("returns 0.00 when given 0", function(){
var value = $.formatAsDollars(0);
equal(value, "0.00", "should return 0");
});
test("returns 0.00 when given abc", function(){
var value = $.formatAsDollars("abc");
equal(value, "0.00", "should return 0");
});
test("returns 0.00 when given NaN", function(){
var value = $.formatAsDollars(NaN);
equal(value, "0.00", "should return 0");
});
test("returns 0.01 when given 0.011", function(){
var value = $.formatAsDollars(0.011);
equal(value, "0.01", "should return 0.01");
});
test("returns 0.02 when given 0.015", function() {
var value = $.formatAsDollars(0.015);
equal(value, "0.02", "should return 0.02");
});
});
</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>
Jump to Line
Something went wrong with that request. Please try again.