Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add matrix transpose test and update other tests to use 'equal' inste…

…ad of 'equals' to work with qunit 2009+

Summary: Our qunit tests are um, out of date.

Test Plan: Tested locally

Reviewers: eater, alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D895
  • Loading branch information...
commit 6714c746ba84a97bcf8d5fc75785644c4a4857c2 1 parent cee3c85
Stephanie H. Chang authored
2  test/qunit
@@ -1 +1 @@
-Subproject commit bd6a75e29e97576f12bed0c6d8f949d7bafcd9d7
+Subproject commit 515de778ca756e181cc56c23b0c2841ef4eda8fa
View
40 utils/test/calculus.js
@@ -15,8 +15,8 @@ neg_coefs[1] = 6;
neg_coefs[2] =-2;
test("ddxPolynomial - Differentiate Polynomials", function() {
- equals((KhanUtil.ddxPolynomial(new KhanUtil.Polynomial(2, 5, coefs, "x", null))).toString(), "25x^{4}+16x^{3}+9x^{2}+4x", "differentiate 5x^{5}+4x^{4}+3x^{3}+2x^{2}" );
- equals((KhanUtil.ddxPolynomial(new KhanUtil.Polynomial(-1, 2, neg_coefs, "x", null))).toString(), "-4x+6+x^{-2}", "differentiate -2x^{2}+6x+4-x^{-1}" );
+ equal((KhanUtil.ddxPolynomial(new KhanUtil.Polynomial(2, 5, coefs, "x", null))).toString(), "25x^{4}+16x^{3}+9x^{2}+4x", "differentiate 5x^{5}+4x^{4}+3x^{3}+2x^{2}" );
+ equal((KhanUtil.ddxPolynomial(new KhanUtil.Polynomial(-1, 2, neg_coefs, "x", null))).toString(), "-4x+6+x^{-2}", "differentiate -2x^{2}+6x+4-x^{-1}" );
});
test("PowerRule - helper object for polynomial differentiation", function(){
@@ -26,8 +26,8 @@ test("PowerRule - helper object for polynomial differentiation", function(){
ok(powerRule.ddxFText, "null constructor produces a displayable differentiated function");
powerRule = new KhanUtil.PowerRule(2, 5, coefs, "x");
- equals(powerRule.fText,"5x^{5}+4x^{4}+3x^{3}+2x^{2}","check it correctly converts polynomial to LaTeX");
- equals(powerRule.ddxFText,"25x^{4}+16x^{3}+9x^{2}+4x", "check it correctly converts the differential of the polynomial to LaTeX" );
+ equal(powerRule.fText,"5x^{5}+4x^{4}+3x^{3}+2x^{2}","check it correctly converts polynomial to LaTeX");
+ equal(powerRule.ddxFText,"25x^{4}+16x^{3}+9x^{2}+4x", "check it correctly converts the differential of the polynomial to LaTeX" );
for (var index in powerRule.wrongsText){
notEqual(powerRule.wrongsText[index],powerRule.ddxFText,"none of the wrong answers should match the right one");
@@ -38,30 +38,30 @@ test("PowerRule - helper object for polynomial differentiation", function(){
test ( "Hints for PowerRule", function(){
var powerRule = new KhanUtil.PowerRule ( -1, 2, neg_coefs, "x", KhanUtil.funcNotation ( "x", 1 ) ); //-2x^{2}+6x+4-x^{-1}
- equals ( powerRule.hints.length, 4 );
- equals ( powerRule.hints[0], "f'(-2x^{2}) = 2 \\cdot -2x^{2-1} = -4x" );
- equals ( powerRule.hints[1], "f'(6x) = 1 \\cdot 6x^{1-1} = 6" );
- equals ( powerRule.hints[2], "f'(4) = 0 \\cdot 4x^{0-1} = 0" );
- equals ( powerRule.hints[3], "f'(-x^{-1}) = -1 \\cdot -1x^{-1-1} = x^{-2}");
+ equal ( powerRule.hints.length, 4 );
+ equal ( powerRule.hints[0], "f'(-2x^{2}) = 2 \\cdot -2x^{2-1} = -4x" );
+ equal ( powerRule.hints[1], "f'(6x) = 1 \\cdot 6x^{1-1} = 6" );
+ equal ( powerRule.hints[2], "f'(4) = 0 \\cdot 4x^{0-1} = 0" );
+ equal ( powerRule.hints[3], "f'(-x^{-1}) = -1 \\cdot -1x^{-1-1} = x^{-2}");
powerRule = new KhanUtil.PowerRule ( -1, 2, neg_coefs, "x", KhanUtil.funcNotation ( "x", 4 ) ); //-2x^{2}+6x+4-x^{-1}
- equals ( powerRule.hints.length, 4 );
- equals ( powerRule.hints[0], "f(x)=-2x^{2} \\implies \\frac{d}{dx}f(x) = 2 \\cdot -2x^{2-1} = -4x" );
+ equal ( powerRule.hints.length, 4 );
+ equal ( powerRule.hints[0], "f(x)=-2x^{2} \\implies \\frac{d}{dx}f(x) = 2 \\cdot -2x^{2-1} = -4x" );
});
test("funcNotation - helper for randomly choosing a notation for the function", function(){
ok(KhanUtil.funcNotation().f, "generates a notation for the function");
ok(KhanUtil.funcNotation().ddxF, "generates a notation for the function derivative");
- equals(KhanUtil.funcNotation("x",1).f, "f(x)","index works and variable is substituted");
- equals(KhanUtil.funcNotation("x",1).ddxF,"f'(x)","index works and variable is substituted");
+ equal(KhanUtil.funcNotation("x",1).f, "f(x)","index works and variable is substituted");
+ equal(KhanUtil.funcNotation("x",1).ddxF,"f'(x)","index works and variable is substituted");
ok(KhanUtil.funcNotation("x",1000).f,"randomly choose a notation if out of range");
- equals(KhanUtil.funcNotation("x",0).diffHint,"y=Ax^{n} \\implies \\frac{dy}{dx}=n \\cdot Ax^{n-1}", "check diffHint");
- equals(KhanUtil.funcNotation("b",1).diffHint,"f'(Ab^{n})=n \\cdot Ab^{n-1}","check diffHint");
- equals(KhanUtil.funcNotation("x",2).diffHint,"g'(Ax^{n})=n \\cdot Ax^{n-1}","check diffHint");
- equals(KhanUtil.funcNotation("b",3).diffHint,"y=Ab^{n} \\implies y'=n \\cdot Ab^{n-1}","check diffHint");
- equals(KhanUtil.funcNotation("x",4).diffHint,"f(x)=Ax^{n} \\implies \\frac{d}{dx}f(x)=n \\cdot Ax^{n-1}","check diffHint");
- equals(KhanUtil.funcNotation("b",5).diffHint,"a=Ab^{n} \\implies a'=n \\cdot Ab^{n-1}","check diffHint");
- equals(KhanUtil.funcNotation("x",6).diffHint,"a=Ax^{n} \\implies \\frac{da}{dx}=n \\cdot Ax^{n-1}","check diffHint");
+ equal(KhanUtil.funcNotation("x",0).diffHint,"y=Ax^{n} \\implies \\frac{dy}{dx}=n \\cdot Ax^{n-1}", "check diffHint");
+ equal(KhanUtil.funcNotation("b",1).diffHint,"f'(Ab^{n})=n \\cdot Ab^{n-1}","check diffHint");
+ equal(KhanUtil.funcNotation("x",2).diffHint,"g'(Ax^{n})=n \\cdot Ax^{n-1}","check diffHint");
+ equal(KhanUtil.funcNotation("b",3).diffHint,"y=Ab^{n} \\implies y'=n \\cdot Ab^{n-1}","check diffHint");
+ equal(KhanUtil.funcNotation("x",4).diffHint,"f(x)=Ax^{n} \\implies \\frac{d}{dx}f(x)=n \\cdot Ax^{n-1}","check diffHint");
+ equal(KhanUtil.funcNotation("b",5).diffHint,"a=Ab^{n} \\implies a'=n \\cdot Ab^{n-1}","check diffHint");
+ equal(KhanUtil.funcNotation("x",6).diffHint,"a=Ax^{n} \\implies \\frac{da}{dx}=n \\cdot Ax^{n-1}","check diffHint");
});
})();
View
104 utils/test/expressions.js
@@ -7,81 +7,81 @@ var exprStripColor = KhanUtil.exprStripColor;
var exprSimplifyAssociative = KhanUtil.exprSimplifyAssociative;
test( "Expression formatter", function() {
- equals( expr([ "-", 1 ]), "-1", "-1");
- equals( expr([ "+", 1, 2 ]), "1+2", "1 + 2" );
- equals( expr([ "+", "elephant", "potato" ]), "elephant+potato", "random strings" );
+ equal( expr([ "-", 1 ]), "-1", "-1");
+ equal( expr([ "+", 1, 2 ]), "1+2", "1 + 2" );
+ equal( expr([ "+", "elephant", "potato" ]), "elephant+potato", "random strings" );
- equals( expr([ "-", 1, 2 ]), "1-2", "1 - 2" );
- equals( expr([ "-", 1, 2, 3, -4 ]), "1-2-3-(-4)", "1-2-3-(-4)" );
- equals( expr([ "-", 1 ]), "-1", "-1" );
- equals( expr([ "-", -1 ]), "-(-1)", "-(-1)" );
- equals( expr([ "-", 2 ]), "-2", "-2" );
- equals( expr([ "-", -2 ]), "-(-2)", "-(-2)" );
+ equal( expr([ "-", 1, 2 ]), "1-2", "1 - 2" );
+ equal( expr([ "-", 1, 2, 3, -4 ]), "1-2-3-(-4)", "1-2-3-(-4)" );
+ equal( expr([ "-", 1 ]), "-1", "-1" );
+ equal( expr([ "-", -1 ]), "-(-1)", "-(-1)" );
+ equal( expr([ "-", 2 ]), "-2", "-2" );
+ equal( expr([ "-", -2 ]), "-(-2)", "-(-2)" );
- equals( expr([ "*", "x", "y" ]), "xy", "x * y" );
- equals( expr([ "*", 2, 4 ]), "(2)(4)", "2 * 4" );
- equals( expr([ "*", 2, 4, "x" ]), "(2)(4)(x)", "2 * 4 * x" );
+ equal( expr([ "*", "x", "y" ]), "xy", "x * y" );
+ equal( expr([ "*", 2, 4 ]), "(2)(4)", "2 * 4" );
+ equal( expr([ "*", 2, 4, "x" ]), "(2)(4)(x)", "2 * 4 * x" );
- equals( expr([ "*", 2, ["^", 4, 2 ] ]), "2(4^{2})", "2 * 4^2" );
- equals( expr([ "*", 2, ["^", 0, 2 ] ]), "2(0^{2})", "2 * 0^2" );
- equals( expr([ "*", 2, ["^", -3, 2 ] ]), "2(-3)^{2}", "2 * (-3)^2" );
+ equal( expr([ "*", 2, ["^", 4, 2 ] ]), "2(4^{2})", "2 * 4^2" );
+ equal( expr([ "*", 2, ["^", 0, 2 ] ]), "2(0^{2})", "2 * 0^2" );
+ equal( expr([ "*", 2, ["^", -3, 2 ] ]), "2(-3)^{2}", "2 * (-3)^2" );
- equals( expr([ "/", 5, 3 ]), "5/3", "5 / 3" );
+ equal( expr([ "/", 5, 3 ]), "5/3", "5 / 3" );
- equals( expr([ "^", "x", 2 ]), "x^{2}", "x^2" );
- equals( expr([ "^", [ "*", "x", "y" ], 2 ]), "(xy)^{2}", "(xy)^2" );
- equals( expr([ "^", [ "*", "x", "y" ], [ "+", 2, 3 ] ]), "(xy)^{2+3}", "(xy)^{2+3}" );
+ equal( expr([ "^", "x", 2 ]), "x^{2}", "x^2" );
+ equal( expr([ "^", [ "*", "x", "y" ], 2 ]), "(xy)^{2}", "(xy)^2" );
+ equal( expr([ "^", [ "*", "x", "y" ], [ "+", 2, 3 ] ]), "(xy)^{2+3}", "(xy)^{2+3}" );
- equals( expr([ "sin", "x" ]), "\\sin{x}", "sin x" );
- equals( expr([ "sin", [ "*", "x", "y" ] ]), "\\sin{(xy)}", "sin xy" );
- equals( expr([ "sin", [ "+", "x", "y" ] ]), "\\sin{(x+y)}", "sin(x + y)" );
+ equal( expr([ "sin", "x" ]), "\\sin{x}", "sin x" );
+ equal( expr([ "sin", [ "*", "x", "y" ] ]), "\\sin{(xy)}", "sin xy" );
+ equal( expr([ "sin", [ "+", "x", "y" ] ]), "\\sin{(x+y)}", "sin(x + y)" );
- equals( expr([ "*", 2, [ "sqrt", 5 ] ]), "2\\sqrt{5}", "2 sqrt(5)" );
- equals( expr([ "*", [ "+", "w", "x" ], "y" ]), "(w+x)(y)", "(w + x) * y" );
+ equal( expr([ "*", 2, [ "sqrt", 5 ] ]), "2\\sqrt{5}", "2 sqrt(5)" );
+ equal( expr([ "*", [ "+", "w", "x" ], "y" ]), "(w+x)(y)", "(w + x) * y" );
- equals( expr([ "+-", "x" ]), "\\pm x", "+- x" );
- equals( expr([ "+-", "x", "y" ]), "x \\pm y", "x +- y" );
- equals( expr([ "+-", [ "+", "x", "y" ] ]), "\\pm (x+y)", "x +- y" );
+ equal( expr([ "+-", "x" ]), "\\pm x", "+- x" );
+ equal( expr([ "+-", "x", "y" ]), "x \\pm y", "x +- y" );
+ equal( expr([ "+-", [ "+", "x", "y" ] ]), "\\pm (x+y)", "x +- y" );
- equals( expr([ "+", [ "*", 2, [ "^", 3, 2 ] ], [ "*", -3, 3 ], 4 ]), "2(3^{2})+(-3)(3)+4", "issue 90" );
- equals( expr([ "+", [ "*", 2, [ "^", 3, "x" ] ], [ "*", -3, "x" ], 4 ]), "2(3^{x})-3x+4", "issue 90" );
- equals( expr([ "*", -2, [ "^", "x", 2 ] ]), "-2x^{2}", "polynomial term" );
+ equal( expr([ "+", [ "*", 2, [ "^", 3, 2 ] ], [ "*", -3, 3 ], 4 ]), "2(3^{2})+(-3)(3)+4", "issue 90" );
+ equal( expr([ "+", [ "*", 2, [ "^", 3, "x" ] ], [ "*", -3, "x" ], 4 ]), "2(3^{x})-3x+4", "issue 90" );
+ equal( expr([ "*", -2, [ "^", "x", 2 ] ]), "-2x^{2}", "polynomial term" );
- equals( expr([ "-", [ "+", 1, 2 ] ]), "-(1+2)", "-1*(1+2)" );
- equals( expr([ "-", [ "+", 1, -2 ] ]), "-(1-2)", "-1*(1-2)" );
- equals( expr([ "*", 3, [ "+", 1, -2 ], 4 ]), "3(1-2)(4)", "3 * (1-2) * 4" );
- equals( expr([ "*", 3, [ "-", 1, -2 ], 4 ]), "3(1-(-2))(4)", "3 * (1-(-2)) * 4" );
- equals( expr([ "+", 1, [ "-", [ "*", 2, 3, 4 ] ], 5, 6 ]), "1-(2)(3)(4)+5+6", "1-(2)(3)(4)+5+6" );
+ equal( expr([ "-", [ "+", 1, 2 ] ]), "-(1+2)", "-1*(1+2)" );
+ equal( expr([ "-", [ "+", 1, -2 ] ]), "-(1-2)", "-1*(1-2)" );
+ equal( expr([ "*", 3, [ "+", 1, -2 ], 4 ]), "3(1-2)(4)", "3 * (1-2) * 4" );
+ equal( expr([ "*", 3, [ "-", 1, -2 ], 4 ]), "3(1-(-2))(4)", "3 * (1-(-2)) * 4" );
+ equal( expr([ "+", 1, [ "-", [ "*", 2, 3, 4 ] ], 5, 6 ]), "1-(2)(3)(4)+5+6", "1-(2)(3)(4)+5+6" );
// Test colors
- equals( expr([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ]), "4(2+\\color{blue}{2})", "4(2+\\color{blue}{2})" );
- equals( expr([ "*", 4, [ "color", "blue", 2 ] ]), "(4)(\\color{blue}{2})", "(4)(\\color{blue}{2})" );
+ equal( expr([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ]), "4(2+\\color{blue}{2})", "4(2+\\color{blue}{2})" );
+ equal( expr([ "*", 4, [ "color", "blue", 2 ] ]), "(4)(\\color{blue}{2})", "(4)(\\color{blue}{2})" );
});
test( "Expression evaluator", function() {
- equals( expr([ "+", 2, 4 ], true ), 6, "2 + 4" );
- equals( expr([ "*", 2, 4 ], true ), 8, "2 * 4" );
- equals( expr([ "-", 2, 4 ], true ), -2, "2 - 4" );
- equals( expr([ "/", 2, 4 ], true ), 0.5, "2 / 4" );
- equals( expr([ "^", 2, 4 ], true ), 16, "2 ^ 4" );
- equals( expr([ "frac", 2, 4 ], true ), 0.5, "2 `frac` 4" );
- equals( expr([ "sqrt", 65536 ], true ), 256, "sqrt 65536" );
- equals( expr([ "+", [ "*", 2, 4 ], 6 ], true ), 14, "2 * 4 + 6" );
+ equal( expr([ "+", 2, 4 ], true ), 6, "2 + 4" );
+ equal( expr([ "*", 2, 4 ], true ), 8, "2 * 4" );
+ equal( expr([ "-", 2, 4 ], true ), -2, "2 - 4" );
+ equal( expr([ "/", 2, 4 ], true ), 0.5, "2 / 4" );
+ equal( expr([ "^", 2, 4 ], true ), 16, "2 ^ 4" );
+ equal( expr([ "frac", 2, 4 ], true ), 0.5, "2 `frac` 4" );
+ equal( expr([ "sqrt", 65536 ], true ), 256, "sqrt 65536" );
+ equal( expr([ "+", [ "*", 2, 4 ], 6 ], true ), 14, "2 * 4 + 6" );
// Test colors
- equals( expr([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ], true), 16, "4*(2+\\color{blue}{2})" );
- equals( expr([ "*", 4, [ "color", "blue", 2 ] ], true), 8, "(4)(\\color{blue}{2})" );
+ equal( expr([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ], true), 16, "4*(2+\\color{blue}{2})" );
+ equal( expr([ "*", 4, [ "color", "blue", 2 ] ], true), 8, "(4)(\\color{blue}{2})" );
});
test( "Expression utilities", function() {
//remove colors
- equals( expr(exprStripColor([ "color", "green", 17 ])), "17", "color outside" );
- equals( expr(exprStripColor([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ])), "4(2+2)", "color inside" );
+ equal( expr(exprStripColor([ "color", "green", 17 ])), "17", "color outside" );
+ equal( expr(exprStripColor([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ])), "4(2+2)", "color inside" );
//simplify an expression
- equals( expr(exprSimplifyAssociative([ "+", 1, [ "+", [ "+", 2, 3 ], 4 ] ])), "1+2+3+4", "Simplify 1+((2+3)+4)" );
- equals( expr(exprSimplifyAssociative([ "*", [ "*", [ "*", 2, 3 ], 4 ], 5 ])), "(2)(3)(4)(5)", "Simplify ((2*3)*4)*5" );
- equals( expr(exprSimplifyAssociative([ "*", [ "*", [ "*", [ "+", 1, [ "+", [ "+", 2, 3, [ "*", [ "*", [ "*", 2, 3 ], 4 ], 5 ] ], 4 ] ], 3 ], 4 ], 5 ])), "(1+2+3+(2)(3)(4)(5)+4)(3)(4)(5)", "Simplify alternating multiplication and addition" );
+ equal( expr(exprSimplifyAssociative([ "+", 1, [ "+", [ "+", 2, 3 ], 4 ] ])), "1+2+3+4", "Simplify 1+((2+3)+4)" );
+ equal( expr(exprSimplifyAssociative([ "*", [ "*", [ "*", 2, 3 ], 4 ], 5 ])), "(2)(3)(4)(5)", "Simplify ((2*3)*4)*5" );
+ equal( expr(exprSimplifyAssociative([ "*", [ "*", [ "*", [ "+", 1, [ "+", [ "+", 2, 3, [ "*", [ "*", [ "*", 2, 3 ], 4 ], 5 ] ], 4 ] ], 3 ], 4 ], 5 ])), "(1+2+3+(2)(3)(4)(5)+4)(3)(4)(5)", "Simplify alternating multiplication and addition" );
});
})();
View
2  utils/test/index.html
@@ -44,6 +44,8 @@
<script src="calculus.js"></script>
<script src="../tmpl.js"></script>
<script src="tmpl.js"></script>
+ <script src="../matrix.js"></script>
+ <script src="matrix.js"></script>
</head>
<body>
<h1 id="qunit-header">Utility Test Suite</h1>
View
46 utils/test/math.js
@@ -6,31 +6,31 @@ test( "math miscellanea", 44, function() {
deepEqual( KhanUtil.digits(376), [ 6, 7, 3 ], "digits(376)" );
deepEqual( KhanUtil.integerToDigits(376), [ 3, 7, 6 ], "integerToDigits(376)" );
- equals( KhanUtil.getGCD(216, 1024), 8, "gcd(216, 1024)" );
- equals( KhanUtil.getGCD(512341, 2325183), 1, "gcd(512341, 2325183)" );
- equals( KhanUtil.getGCD(53110108, 109775188), 68, "gcd(53110108, 109775188)" );
- equals( KhanUtil.getGCD(-21, 14), 7, "gcd(-21, 14)" );
- equals( KhanUtil.getGCD(-21, -14), 7, "gcd(-21, -14)" );
- equals( KhanUtil.getGCD(123, 1), 1, "gcd(123, 1)" );
- equals( KhanUtil.getGCD(123, 1), 1, "gcd(123, 1)" );
- equals( KhanUtil.getGCD(123, 123), 123, "gcd(123, 123)" );
- equals( KhanUtil.getGCD(169, 26, -52), 13, "gcd(169, 26, -52)" );
+ equal( KhanUtil.getGCD(216, 1024), 8, "gcd(216, 1024)" );
+ equal( KhanUtil.getGCD(512341, 2325183), 1, "gcd(512341, 2325183)" );
+ equal( KhanUtil.getGCD(53110108, 109775188), 68, "gcd(53110108, 109775188)" );
+ equal( KhanUtil.getGCD(-21, 14), 7, "gcd(-21, 14)" );
+ equal( KhanUtil.getGCD(-21, -14), 7, "gcd(-21, -14)" );
+ equal( KhanUtil.getGCD(123, 1), 1, "gcd(123, 1)" );
+ equal( KhanUtil.getGCD(123, 1), 1, "gcd(123, 1)" );
+ equal( KhanUtil.getGCD(123, 123), 123, "gcd(123, 123)" );
+ equal( KhanUtil.getGCD(169, 26, -52), 13, "gcd(169, 26, -52)" );
- equals( KhanUtil.getLCM(216, 1024), 27648, "lcm(216, 1024)" );
- equals( KhanUtil.getLCM(216, -1024), 27648, "lcm(216, -1024)" );
- equals( KhanUtil.getLCM(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 2520, "lcm(1..10)" );
+ equal( KhanUtil.getLCM(216, 1024), 27648, "lcm(216, 1024)" );
+ equal( KhanUtil.getLCM(216, -1024), 27648, "lcm(216, -1024)" );
+ equal( KhanUtil.getLCM(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 2520, "lcm(1..10)" );
- equals( KhanUtil.isPrime(1), false, "primeq 1" );
- equals( KhanUtil.isPrime(2), true, "primeq 2" );
- equals( KhanUtil.isPrime(216), false, "primeq 216" );
- equals( KhanUtil.isPrime(127), true, "primeq 127" );
- equals( KhanUtil.isPrime(129), false, "primeq 129" );
+ equal( KhanUtil.isPrime(1), false, "primeq 1" );
+ equal( KhanUtil.isPrime(2), true, "primeq 2" );
+ equal( KhanUtil.isPrime(216), false, "primeq 216" );
+ equal( KhanUtil.isPrime(127), true, "primeq 127" );
+ equal( KhanUtil.isPrime(129), false, "primeq 129" );
- equals( KhanUtil.isOdd(0), false, "oddq 0" );
- equals( KhanUtil.isOdd(1), true, "oddq 1" );
+ equal( KhanUtil.isOdd(0), false, "oddq 0" );
+ equal( KhanUtil.isOdd(1), true, "oddq 1" );
- equals( KhanUtil.isEven(0), true, "evenq 0" );
- equals( KhanUtil.isEven(1), false, "evenq 1" );
+ equal( KhanUtil.isEven(0), true, "evenq 0" );
+ equal( KhanUtil.isEven(1), false, "evenq 1" );
deepEqual( KhanUtil.getPrimeFactorization( 6 ), [ 2, 3 ], "factor 6" );
deepEqual( KhanUtil.getPrimeFactorization( 23 ), [ 23 ], "factor 23" );
@@ -46,8 +46,8 @@ test( "math miscellanea", 44, function() {
deepEqual( KhanUtil.getMultiples( 7, 80 ), [ 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77 ], "multiples 7, 80" );
deepEqual( KhanUtil.getMultiples( 7, 83 ), [ 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77 ], "multiples 7, 83" );
- equals( KhanUtil.roundTo( 2, Math.PI ), 3.14, "roundTo 2, pi" );
- equals( KhanUtil.roundTo( 0, Math.PI ), 3, "roundTo 0, pi" );
+ equal( KhanUtil.roundTo( 2, Math.PI ), 3.14, "roundTo 2, pi" );
+ equal( KhanUtil.roundTo( 0, Math.PI ), 3, "roundTo 0, pi" );
deepEqual( KhanUtil.toFraction( 4/8 ), [ 1, 2 ], "4/8" );
deepEqual( KhanUtil.toFraction( 0.666 ), [ 333, 500 ], "0.666" );
View
36 utils/test/matrix.js
@@ -0,0 +1,36 @@
+module("matrix");
+
+(function() {
+
+test("matrixTranspose", function() {
+
+ function matrixToString(m) {
+ return m.join("; ");
+ }
+
+ function testMatrixTranspose(m, text) {
+
+ m = KhanUtil.makeMatrix(m);
+ var n = KhanUtil.matrixTranspose(m);
+ var d = KhanUtil.matrixTranspose(n);
+
+ var ms = matrixToString(m);
+ if (text) {
+ ms = ms + ": " + text;
+ }
+
+ deepEqual(m, d, ms);
+ }
+
+ testMatrixTranspose([[1, 2, 3, 4]]);
+ testMatrixTranspose([[1,2],[3,4]]);
+
+ testMatrixTranspose([[1],[2],[3,4]], "ill-formatted");
+ testMatrixTranspose([[1], [2], [3], [4]]);
+
+ testMatrixTranspose([[1, 2], [3, 4], [5, 6]]);
+ testMatrixTranspose([[1, 2, 3], [4, 5, 6]]);
+ testMatrixTranspose([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
+});
+
+})();
View
18 utils/test/polynomials.js
@@ -12,23 +12,23 @@ polyCoefs[2] = -3;
polyCoefs[4] = 2;
test("Polynomial constructor defaults", function(){
- equals((new KhanUtil.Polynomial(-1, 4, polyCoefs)).toString(),"2x^{4}-3x^{2}+12x+5+3x^{-1}", "defaults variable name to x");
+ equal((new KhanUtil.Polynomial(-1, 4, polyCoefs)).toString(),"2x^{4}-3x^{2}+12x+5+3x^{-1}", "defaults variable name to x");
ok((new KhanUtil.Polynomial(-1, 4)).toString(), "randomly generate coefs (3rd param) if not passed");
- equals(new KhanUtil.Polynomial(-1, 4, polyCoefs).getNumberOfTerms(),5,"should only have 5 terms as no 3 coef");
+ equal(new KhanUtil.Polynomial(-1, 4, polyCoefs).getNumberOfTerms(),5,"should only have 5 terms as no 3 coef");
});
test("Polynomial evalOf", function(){
- equals((new KhanUtil.Polynomial(-1, 4, polyCoefs, polyX)).evalOf(1),19,"2*1^4-3*1^2+12*1+5+3*1^-1 = 2-3+12+5+3 = 19");
+ equal((new KhanUtil.Polynomial(-1, 4, polyCoefs, polyX)).evalOf(1),19,"2*1^4-3*1^2+12*1+5+3*1^-1 = 2-3+12+5+3 = 19");
});
test( "Polynomial extractFromExpr", function(){
var polynomial = new KhanUtil.Polynomial(-1, 4, polyCoefs);
- equals(polynomial.getCoefAndDegreeForTerm( 0 ).coef,2,"leading term is 2x^4");
- equals(polynomial.getCoefAndDegreeForTerm( 0 ).degree,4,"leading term is 2x^4");
- equals(polynomial.getCoefAndDegreeForTerm( 1 ).coef,-3,"second term is -3x^2");
- equals(polynomial.getCoefAndDegreeForTerm( 1 ).degree,2,"second term is -3x^2");
- equals(polynomial.getCoefAndDegreeForTerm( 2 ).coef,12,"third term is 12x");
- equals(polynomial.getCoefAndDegreeForTerm( 2 ).degree,1,"third term is 12x");
+ equal(polynomial.getCoefAndDegreeForTerm( 0 ).coef,2,"leading term is 2x^4");
+ equal(polynomial.getCoefAndDegreeForTerm( 0 ).degree,4,"leading term is 2x^4");
+ equal(polynomial.getCoefAndDegreeForTerm( 1 ).coef,-3,"second term is -3x^2");
+ equal(polynomial.getCoefAndDegreeForTerm( 1 ).degree,2,"second term is -3x^2");
+ equal(polynomial.getCoefAndDegreeForTerm( 2 ).coef,12,"third term is 12x");
+ equal(polynomial.getCoefAndDegreeForTerm( 2 ).degree,1,"third term is 12x");
});
})();
View
130 utils/test/tmpl.js
@@ -18,15 +18,15 @@ test("Var Loading", 7, function() {
jQuery("#qunit-fixture").tmpl();
- equals( jQuery.tmpl.VARS.B, 2, "Make sure that normal var loading works." );
- equals( jQuery.tmpl.VARS.A, 3, "Make sure that var overwriting works." );
+ equal( jQuery.tmpl.VARS.B, 2, "Make sure that normal var loading works." );
+ equal( jQuery.tmpl.VARS.A, 3, "Make sure that var overwriting works." );
- equals( jQuery.tmpl.VARS.C, true, "Make sure that booleans are evaluated." );
- equals( jQuery.tmpl.VARS.D, "test", "Make sure that strings are evaluated." );
- equals( jQuery.tmpl.VARS.E, 1, "Make sure that expressions are evaluated." );
+ equal( jQuery.tmpl.VARS.C, true, "Make sure that booleans are evaluated." );
+ equal( jQuery.tmpl.VARS.D, "test", "Make sure that strings are evaluated." );
+ equal( jQuery.tmpl.VARS.E, 1, "Make sure that expressions are evaluated." );
- equals( typeof jQuery.tmpl.VARS.F, "function", "Make sure that functions are evaluated." );
- equals( jQuery.tmpl.VARS.G, true, "Make sure that functions are evaluated." );
+ equal( typeof jQuery.tmpl.VARS.F, "function", "Make sure that functions are evaluated." );
+ equal( jQuery.tmpl.VARS.G, true, "Make sure that functions are evaluated." );
});
test("Var Replacement", 6, function() {
@@ -39,13 +39,13 @@ test("Var Replacement", 6, function() {
var span = jQuery("#qunit-fixture").tmpl().children( "span" );
- equals( span[0].innerHTML, "3", "Make sure that normal vars work." );
- equals( span[1].innerHTML, "2", "Make sure that numbers are evaluated." );
- equals( span[2].innerHTML, "true", "Make sure that booleans are evaluated." );
+ equal( span[0].innerHTML, "3", "Make sure that normal vars work." );
+ equal( span[1].innerHTML, "2", "Make sure that numbers are evaluated." );
+ equal( span[2].innerHTML, "true", "Make sure that booleans are evaluated." );
- equals( span[3].innerHTML, "test", "Make sure that strings are evaluated." );
- equals( span[4].innerHTML, "true", "Make sure that functions are evaluated." );
- equals( span[5].innerHTML, "1", "Make sure that expressions are evaluated." );
+ equal( span[3].innerHTML, "test", "Make sure that strings are evaluated." );
+ equal( span[4].innerHTML, "true", "Make sure that functions are evaluated." );
+ equal( span[5].innerHTML, "1", "Make sure that expressions are evaluated." );
});
test("Code Replacement", 10, function() {
@@ -58,19 +58,19 @@ test("Code Replacement", 10, function() {
var code = jQuery("#qunit-fixture").tmpl().children( "code, span" );
- equals( code[0].innerHTML, "3 + 2 = 5", "Make sure that strings work." );
- equals( code[0].type, "math/tex", "Make sure that it was turned into a MathJax element." );
+ equal( code[0].innerHTML, "3 + 2 = 5", "Make sure that strings work." );
+ equal( code[0].type, "math/tex", "Make sure that it was turned into a MathJax element." );
- equals( code[1].innerHTML, "3 + 2 = 5", "Make sure that variables are substituted." );
- equals( code[1].type, "math/tex", "Make sure that it was turned into a MathJax element." );
+ equal( code[1].innerHTML, "3 + 2 = 5", "Make sure that variables are substituted." );
+ equal( code[1].type, "math/tex", "Make sure that it was turned into a MathJax element." );
- equals( code[2].innerHTML, "3 + 2 = 5", "Make sure that extra HTML is stripped." );
- equals( code[2].type, "math/tex", "Make sure that it was turned into a MathJax element." );
+ equal( code[2].innerHTML, "3 + 2 = 5", "Make sure that extra HTML is stripped." );
+ equal( code[2].type, "math/tex", "Make sure that it was turned into a MathJax element." );
- equals( code[3].nodeName.toLowerCase(), "span", "Make sure that we're dealing with a span." );
- equals( code[3].className, "test", "Make sure that the className is maintained." );
- equals( code[3].firstChild.innerHTML, "3 + 2 = 5", "Make sure that variables are substituted." );
- equals( code[3].firstChild.type, "math/tex", "Make sure that it was turned into a MathJax element." );
+ equal( code[3].nodeName.toLowerCase(), "span", "Make sure that we're dealing with a span." );
+ equal( code[3].className, "test", "Make sure that the className is maintained." );
+ equal( code[3].firstChild.innerHTML, "3 + 2 = 5", "Make sure that variables are substituted." );
+ equal( code[3].firstChild.type, "math/tex", "Make sure that it was turned into a MathJax element." );
});
test("If Statement", 3, function() {
@@ -83,11 +83,11 @@ test("If Statement", 3, function() {
var div = jQuery("#qunit-fixture").tmpl().children( "div" );
- equals( div.length, 1, "Make sure that all the specified elements were removed." );
- equals( div[0].className, "A", "See that the expression was evaluated correctly." );
+ equal( div.length, 1, "Make sure that all the specified elements were removed." );
+ equal( div[0].className, "A", "See that the expression was evaluated correctly." );
// test data-if on var
- equals( jQuery.tmpl.VARS.TEST, 1, "Make sure that data-if stops var declaration." );
+ equal( jQuery.tmpl.VARS.TEST, 1, "Make sure that data-if stops var declaration." );
});
test("If/Else Statement", 4, function() {
@@ -103,10 +103,10 @@ test("If/Else Statement", 4, function() {
var div = jQuery("#qunit-fixture").tmpl().children( "div" );
- equals( div.length, 3, "Make sure that all the specified elements were removed." );
- equals( div[0].className, "A", "See that the if expression was evaluated correctly." );
- equals( div[1].className, "D", "See that the else expression was evaluated correctly." );
- equals( div[2].className, "E", "See that the if expression was evaluated correctly." );
+ equal( div.length, 3, "Make sure that all the specified elements were removed." );
+ equal( div[0].className, "A", "See that the if expression was evaluated correctly." );
+ equal( div[1].className, "D", "See that the else expression was evaluated correctly." );
+ equal( div[2].className, "E", "See that the if expression was evaluated correctly." );
});
test("If/Else/Else-if Statement", 4, function() {
@@ -120,10 +120,10 @@ test("If/Else/Else-if Statement", 4, function() {
var div = jQuery("#qunit-fixture").tmpl().children( "div" );
- equals( div.length, 3, "Make sure that all the specified elements were removed." );
- equals( div[0].className, "A", "See that the if expression was evaluated correctly." );
- equals( div[1].className, "E", "See that the else-if expression was evaluated correctly." );
- equals( div[2].className, "I", "See that the else expression was evaluated correctly." );
+ equal( div.length, 3, "Make sure that all the specified elements were removed." );
+ equal( div[0].className, "A", "See that the if expression was evaluated correctly." );
+ equal( div[1].className, "E", "See that the else-if expression was evaluated correctly." );
+ equal( div[2].className, "I", "See that the else expression was evaluated correctly." );
});
test("Ensure", function() {
@@ -136,11 +136,11 @@ test("Ensure", function() {
jQuery("#qunit-fixture").tmpl();
- equals( jQuery.tmpl.VARS.A, 5, "See that the A was incremented." );
- equals( jQuery.tmpl.VARS.B, 4, "See that the B was at the right value." );
+ equal( jQuery.tmpl.VARS.A, 5, "See that the A was incremented." );
+ equal( jQuery.tmpl.VARS.B, 4, "See that the B was at the right value." );
- equals( jQuery.tmpl.VARS.C, 5, "See that the C was incremented." );
- equals( jQuery.tmpl.VARS.D, 4, "See that the D was at the right value." );
+ equal( jQuery.tmpl.VARS.C, 5, "See that the C was incremented." );
+ equal( jQuery.tmpl.VARS.D, 4, "See that the D was at the right value." );
});
test("Unwrap", function() {
@@ -154,9 +154,9 @@ test("Unwrap", function() {
jQuery("#qunit-fixture").tmpl();
- equals( jQuery("#qunit-fixture > b").length, 1, "See that the div was unwrapped." );
- equals( jQuery("#qunit-fixture > i").length, 1, "See that the div was unwrapped with a true if." );
- equals( jQuery("#qunit-fixture > u").length, 0, "See that the div was unwrapped with a false if." );
+ equal( jQuery("#qunit-fixture > b").length, 1, "See that the div was unwrapped." );
+ equal( jQuery("#qunit-fixture > i").length, 1, "See that the div was unwrapped with a true if." );
+ equal( jQuery("#qunit-fixture > u").length, 0, "See that the div was unwrapped with a false if." );
});
test("Looping", 23, function() {
@@ -178,59 +178,59 @@ test("Looping", 23, function() {
jQuery("#qunit-fixture").tmpl();
- equals( jQuery.tmpl.VARS.items.length, 3, "Make sure that the array exists." );
+ equal( jQuery.tmpl.VARS.items.length, 3, "Make sure that the array exists." );
// test data-each="items"
var li = jQuery("#qunit-fixture ul.a li");
- equals( li.length, 3, "See that the list items were generated." );
- equals( jQuery( li[0] ).data( "each" ), undefined, "Verify the data-each attribute was removed." );
+ equal( li.length, 3, "See that the list items were generated." );
+ equal( jQuery( li[0] ).data( "each" ), undefined, "Verify the data-each attribute was removed." );
// test data-each="items as value"
li = jQuery("#qunit-fixture ul.b li");
- equals( li.length, 3, "See that the list items were generated." );
+ equal( li.length, 3, "See that the list items were generated." );
- equals( li[0].innerHTML, "a", "Verify the contents of the list item." );
- equals( li[1].innerHTML, "b", "Verify the contents of the list item." );
- equals( li[2].innerHTML, "c", "Verify the contents of the list item." );
+ equal( li[0].innerHTML, "a", "Verify the contents of the list item." );
+ equal( li[1].innerHTML, "b", "Verify the contents of the list item." );
+ equal( li[2].innerHTML, "c", "Verify the contents of the list item." );
// test data-each="items as key, value"
li = jQuery("#qunit-fixture ul.c li");
- equals( li.length, 3, "See that the list items were generated." );
+ equal( li.length, 3, "See that the list items were generated." );
- equals( li[0].innerHTML, "0: a", "Verify the contents of the list item." );
- equals( li[1].innerHTML, "1: b", "Verify the contents of the list item." );
- equals( li[2].innerHTML, "2: c", "Verify the contents of the list item." );
+ equal( li[0].innerHTML, "0: a", "Verify the contents of the list item." );
+ equal( li[1].innerHTML, "1: b", "Verify the contents of the list item." );
+ equal( li[2].innerHTML, "2: c", "Verify the contents of the list item." );
// make sure that variables don't bleed out
- equals( jQuery.tmpl.VARS.tmpVal, 2, "Make sure that the value is reset." );
- equals( jQuery.tmpl.VARS.tmpKey, 1, "Make sure that the key is reset." );
+ equal( jQuery.tmpl.VARS.tmpVal, 2, "Make sure that the value is reset." );
+ equal( jQuery.tmpl.VARS.tmpKey, 1, "Make sure that the key is reset." );
// test data-each on var
- equals( jQuery.tmpl.VARS.items2.length, 3, "Make sure that the cloned array exists." );
+ equal( jQuery.tmpl.VARS.items2.length, 3, "Make sure that the cloned array exists." );
- equals( jQuery.tmpl.VARS.items2[0], 0, "Make sure that the cloned array has the right contents." );
- equals( jQuery.tmpl.VARS.items2[1], 1, "Make sure that the cloned array has the right contents." );
- equals( jQuery.tmpl.VARS.items2[2], 2, "Make sure that the cloned array has the right contents." );
+ equal( jQuery.tmpl.VARS.items2[0], 0, "Make sure that the cloned array has the right contents." );
+ equal( jQuery.tmpl.VARS.items2[1], 1, "Make sure that the cloned array has the right contents." );
+ equal( jQuery.tmpl.VARS.items2[2], 2, "Make sure that the cloned array has the right contents." );
// test data-if and data-each
- equals( jQuery("#qunit-fixture div.d").length, 0, "Make sure the non-looped div doesn't exist." );
+ equal( jQuery("#qunit-fixture div.d").length, 0, "Make sure the non-looped div doesn't exist." );
// test data-each="items as key, value" on an object
li = jQuery("#qunit-fixture ul.e li");
- equals( li.length, 3, "See that the list items were generated." );
+ equal( li.length, 3, "See that the list items were generated." );
- equals( li[0].innerHTML, "a: 0", "Verify the contents of the object property." );
- equals( li[1].innerHTML, "b: 1", "Verify the contents of the object property." );
- equals( li[2].innerHTML, "c: 2", "Verify the contents of the object property." );
+ equal( li[0].innerHTML, "a: 0", "Verify the contents of the object property." );
+ equal( li[1].innerHTML, "b: 1", "Verify the contents of the object property." );
+ equal( li[2].innerHTML, "c: 2", "Verify the contents of the object property." );
// test data-each="[]"
li = jQuery("#qunit-fixture ul.f li");
- equals( li.length, 0, "See that the list item was removed." );
+ equal( li.length, 0, "See that the list item was removed." );
});
test( "Inheritance", function() {
@@ -245,5 +245,5 @@ test( "Inheritance", function() {
// Test appendContents
jQuery("#qunit-fixture *").tmplApply({ attribute: "class", defaultApply: "appendContents" });
- equals( jQuery("#test-base-1").children("p").length, 4, "Verify that child nodes were appended." );
+ equal( jQuery("#test-base-1").children("p").length, 4, "Verify that child nodes were appended." );
});
Please sign in to comment.
Something went wrong with that request. Please try again.