Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

Commit 6714c74

Browse files
author
Stephanie H. Chang
committed
Add matrix transpose test and update other tests to use 'equal' instead 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
1 parent cee3c85 commit 6714c74

File tree

8 files changed

+208
-170
lines changed

8 files changed

+208
-170
lines changed

test/qunit

Submodule qunit updated from bd6a75e to 515de77

utils/test/calculus.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ neg_coefs[1] = 6;
1515
neg_coefs[2] =-2;
1616

1717
test("ddxPolynomial - Differentiate Polynomials", function() {
18-
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}" );
19-
equals((KhanUtil.ddxPolynomial(new KhanUtil.Polynomial(-1, 2, neg_coefs, "x", null))).toString(), "-4x+6+x^{-2}", "differentiate -2x^{2}+6x+4-x^{-1}" );
18+
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}" );
19+
equal((KhanUtil.ddxPolynomial(new KhanUtil.Polynomial(-1, 2, neg_coefs, "x", null))).toString(), "-4x+6+x^{-2}", "differentiate -2x^{2}+6x+4-x^{-1}" );
2020
});
2121

2222
test("PowerRule - helper object for polynomial differentiation", function(){
@@ -26,8 +26,8 @@ test("PowerRule - helper object for polynomial differentiation", function(){
2626
ok(powerRule.ddxFText, "null constructor produces a displayable differentiated function");
2727

2828
powerRule = new KhanUtil.PowerRule(2, 5, coefs, "x");
29-
equals(powerRule.fText,"5x^{5}+4x^{4}+3x^{3}+2x^{2}","check it correctly converts polynomial to LaTeX");
30-
equals(powerRule.ddxFText,"25x^{4}+16x^{3}+9x^{2}+4x", "check it correctly converts the differential of the polynomial to LaTeX" );
29+
equal(powerRule.fText,"5x^{5}+4x^{4}+3x^{3}+2x^{2}","check it correctly converts polynomial to LaTeX");
30+
equal(powerRule.ddxFText,"25x^{4}+16x^{3}+9x^{2}+4x", "check it correctly converts the differential of the polynomial to LaTeX" );
3131

3232
for (var index in powerRule.wrongsText){
3333
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(){
3838

3939
test ( "Hints for PowerRule", function(){
4040
var powerRule = new KhanUtil.PowerRule ( -1, 2, neg_coefs, "x", KhanUtil.funcNotation ( "x", 1 ) ); //-2x^{2}+6x+4-x^{-1}
41-
equals ( powerRule.hints.length, 4 );
42-
equals ( powerRule.hints[0], "f'(-2x^{2}) = 2 \\cdot -2x^{2-1} = -4x" );
43-
equals ( powerRule.hints[1], "f'(6x) = 1 \\cdot 6x^{1-1} = 6" );
44-
equals ( powerRule.hints[2], "f'(4) = 0 \\cdot 4x^{0-1} = 0" );
45-
equals ( powerRule.hints[3], "f'(-x^{-1}) = -1 \\cdot -1x^{-1-1} = x^{-2}");
41+
equal ( powerRule.hints.length, 4 );
42+
equal ( powerRule.hints[0], "f'(-2x^{2}) = 2 \\cdot -2x^{2-1} = -4x" );
43+
equal ( powerRule.hints[1], "f'(6x) = 1 \\cdot 6x^{1-1} = 6" );
44+
equal ( powerRule.hints[2], "f'(4) = 0 \\cdot 4x^{0-1} = 0" );
45+
equal ( powerRule.hints[3], "f'(-x^{-1}) = -1 \\cdot -1x^{-1-1} = x^{-2}");
4646

4747
powerRule = new KhanUtil.PowerRule ( -1, 2, neg_coefs, "x", KhanUtil.funcNotation ( "x", 4 ) ); //-2x^{2}+6x+4-x^{-1}
48-
equals ( powerRule.hints.length, 4 );
49-
equals ( powerRule.hints[0], "f(x)=-2x^{2} \\implies \\frac{d}{dx}f(x) = 2 \\cdot -2x^{2-1} = -4x" );
48+
equal ( powerRule.hints.length, 4 );
49+
equal ( powerRule.hints[0], "f(x)=-2x^{2} \\implies \\frac{d}{dx}f(x) = 2 \\cdot -2x^{2-1} = -4x" );
5050
});
5151

5252
test("funcNotation - helper for randomly choosing a notation for the function", function(){
5353
ok(KhanUtil.funcNotation().f, "generates a notation for the function");
5454
ok(KhanUtil.funcNotation().ddxF, "generates a notation for the function derivative");
55-
equals(KhanUtil.funcNotation("x",1).f, "f(x)","index works and variable is substituted");
56-
equals(KhanUtil.funcNotation("x",1).ddxF,"f'(x)","index works and variable is substituted");
55+
equal(KhanUtil.funcNotation("x",1).f, "f(x)","index works and variable is substituted");
56+
equal(KhanUtil.funcNotation("x",1).ddxF,"f'(x)","index works and variable is substituted");
5757
ok(KhanUtil.funcNotation("x",1000).f,"randomly choose a notation if out of range");
58-
equals(KhanUtil.funcNotation("x",0).diffHint,"y=Ax^{n} \\implies \\frac{dy}{dx}=n \\cdot Ax^{n-1}", "check diffHint");
59-
equals(KhanUtil.funcNotation("b",1).diffHint,"f'(Ab^{n})=n \\cdot Ab^{n-1}","check diffHint");
60-
equals(KhanUtil.funcNotation("x",2).diffHint,"g'(Ax^{n})=n \\cdot Ax^{n-1}","check diffHint");
61-
equals(KhanUtil.funcNotation("b",3).diffHint,"y=Ab^{n} \\implies y'=n \\cdot Ab^{n-1}","check diffHint");
62-
equals(KhanUtil.funcNotation("x",4).diffHint,"f(x)=Ax^{n} \\implies \\frac{d}{dx}f(x)=n \\cdot Ax^{n-1}","check diffHint");
63-
equals(KhanUtil.funcNotation("b",5).diffHint,"a=Ab^{n} \\implies a'=n \\cdot Ab^{n-1}","check diffHint");
64-
equals(KhanUtil.funcNotation("x",6).diffHint,"a=Ax^{n} \\implies \\frac{da}{dx}=n \\cdot Ax^{n-1}","check diffHint");
58+
equal(KhanUtil.funcNotation("x",0).diffHint,"y=Ax^{n} \\implies \\frac{dy}{dx}=n \\cdot Ax^{n-1}", "check diffHint");
59+
equal(KhanUtil.funcNotation("b",1).diffHint,"f'(Ab^{n})=n \\cdot Ab^{n-1}","check diffHint");
60+
equal(KhanUtil.funcNotation("x",2).diffHint,"g'(Ax^{n})=n \\cdot Ax^{n-1}","check diffHint");
61+
equal(KhanUtil.funcNotation("b",3).diffHint,"y=Ab^{n} \\implies y'=n \\cdot Ab^{n-1}","check diffHint");
62+
equal(KhanUtil.funcNotation("x",4).diffHint,"f(x)=Ax^{n} \\implies \\frac{d}{dx}f(x)=n \\cdot Ax^{n-1}","check diffHint");
63+
equal(KhanUtil.funcNotation("b",5).diffHint,"a=Ab^{n} \\implies a'=n \\cdot Ab^{n-1}","check diffHint");
64+
equal(KhanUtil.funcNotation("x",6).diffHint,"a=Ax^{n} \\implies \\frac{da}{dx}=n \\cdot Ax^{n-1}","check diffHint");
6565
});
6666

6767
})();

utils/test/expressions.js

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,81 +7,81 @@ var exprStripColor = KhanUtil.exprStripColor;
77
var exprSimplifyAssociative = KhanUtil.exprSimplifyAssociative;
88

99
test( "Expression formatter", function() {
10-
equals( expr([ "-", 1 ]), "-1", "-1");
11-
equals( expr([ "+", 1, 2 ]), "1+2", "1 + 2" );
12-
equals( expr([ "+", "elephant", "potato" ]), "elephant+potato", "random strings" );
10+
equal( expr([ "-", 1 ]), "-1", "-1");
11+
equal( expr([ "+", 1, 2 ]), "1+2", "1 + 2" );
12+
equal( expr([ "+", "elephant", "potato" ]), "elephant+potato", "random strings" );
1313

14-
equals( expr([ "-", 1, 2 ]), "1-2", "1 - 2" );
15-
equals( expr([ "-", 1, 2, 3, -4 ]), "1-2-3-(-4)", "1-2-3-(-4)" );
16-
equals( expr([ "-", 1 ]), "-1", "-1" );
17-
equals( expr([ "-", -1 ]), "-(-1)", "-(-1)" );
18-
equals( expr([ "-", 2 ]), "-2", "-2" );
19-
equals( expr([ "-", -2 ]), "-(-2)", "-(-2)" );
14+
equal( expr([ "-", 1, 2 ]), "1-2", "1 - 2" );
15+
equal( expr([ "-", 1, 2, 3, -4 ]), "1-2-3-(-4)", "1-2-3-(-4)" );
16+
equal( expr([ "-", 1 ]), "-1", "-1" );
17+
equal( expr([ "-", -1 ]), "-(-1)", "-(-1)" );
18+
equal( expr([ "-", 2 ]), "-2", "-2" );
19+
equal( expr([ "-", -2 ]), "-(-2)", "-(-2)" );
2020

21-
equals( expr([ "*", "x", "y" ]), "xy", "x * y" );
22-
equals( expr([ "*", 2, 4 ]), "(2)(4)", "2 * 4" );
23-
equals( expr([ "*", 2, 4, "x" ]), "(2)(4)(x)", "2 * 4 * x" );
21+
equal( expr([ "*", "x", "y" ]), "xy", "x * y" );
22+
equal( expr([ "*", 2, 4 ]), "(2)(4)", "2 * 4" );
23+
equal( expr([ "*", 2, 4, "x" ]), "(2)(4)(x)", "2 * 4 * x" );
2424

25-
equals( expr([ "*", 2, ["^", 4, 2 ] ]), "2(4^{2})", "2 * 4^2" );
26-
equals( expr([ "*", 2, ["^", 0, 2 ] ]), "2(0^{2})", "2 * 0^2" );
27-
equals( expr([ "*", 2, ["^", -3, 2 ] ]), "2(-3)^{2}", "2 * (-3)^2" );
25+
equal( expr([ "*", 2, ["^", 4, 2 ] ]), "2(4^{2})", "2 * 4^2" );
26+
equal( expr([ "*", 2, ["^", 0, 2 ] ]), "2(0^{2})", "2 * 0^2" );
27+
equal( expr([ "*", 2, ["^", -3, 2 ] ]), "2(-3)^{2}", "2 * (-3)^2" );
2828

29-
equals( expr([ "/", 5, 3 ]), "5/3", "5 / 3" );
29+
equal( expr([ "/", 5, 3 ]), "5/3", "5 / 3" );
3030

31-
equals( expr([ "^", "x", 2 ]), "x^{2}", "x^2" );
32-
equals( expr([ "^", [ "*", "x", "y" ], 2 ]), "(xy)^{2}", "(xy)^2" );
33-
equals( expr([ "^", [ "*", "x", "y" ], [ "+", 2, 3 ] ]), "(xy)^{2+3}", "(xy)^{2+3}" );
31+
equal( expr([ "^", "x", 2 ]), "x^{2}", "x^2" );
32+
equal( expr([ "^", [ "*", "x", "y" ], 2 ]), "(xy)^{2}", "(xy)^2" );
33+
equal( expr([ "^", [ "*", "x", "y" ], [ "+", 2, 3 ] ]), "(xy)^{2+3}", "(xy)^{2+3}" );
3434

35-
equals( expr([ "sin", "x" ]), "\\sin{x}", "sin x" );
36-
equals( expr([ "sin", [ "*", "x", "y" ] ]), "\\sin{(xy)}", "sin xy" );
37-
equals( expr([ "sin", [ "+", "x", "y" ] ]), "\\sin{(x+y)}", "sin(x + y)" );
35+
equal( expr([ "sin", "x" ]), "\\sin{x}", "sin x" );
36+
equal( expr([ "sin", [ "*", "x", "y" ] ]), "\\sin{(xy)}", "sin xy" );
37+
equal( expr([ "sin", [ "+", "x", "y" ] ]), "\\sin{(x+y)}", "sin(x + y)" );
3838

39-
equals( expr([ "*", 2, [ "sqrt", 5 ] ]), "2\\sqrt{5}", "2 sqrt(5)" );
40-
equals( expr([ "*", [ "+", "w", "x" ], "y" ]), "(w+x)(y)", "(w + x) * y" );
39+
equal( expr([ "*", 2, [ "sqrt", 5 ] ]), "2\\sqrt{5}", "2 sqrt(5)" );
40+
equal( expr([ "*", [ "+", "w", "x" ], "y" ]), "(w+x)(y)", "(w + x) * y" );
4141

42-
equals( expr([ "+-", "x" ]), "\\pm x", "+- x" );
43-
equals( expr([ "+-", "x", "y" ]), "x \\pm y", "x +- y" );
44-
equals( expr([ "+-", [ "+", "x", "y" ] ]), "\\pm (x+y)", "x +- y" );
42+
equal( expr([ "+-", "x" ]), "\\pm x", "+- x" );
43+
equal( expr([ "+-", "x", "y" ]), "x \\pm y", "x +- y" );
44+
equal( expr([ "+-", [ "+", "x", "y" ] ]), "\\pm (x+y)", "x +- y" );
4545

46-
equals( expr([ "+", [ "*", 2, [ "^", 3, 2 ] ], [ "*", -3, 3 ], 4 ]), "2(3^{2})+(-3)(3)+4", "issue 90" );
47-
equals( expr([ "+", [ "*", 2, [ "^", 3, "x" ] ], [ "*", -3, "x" ], 4 ]), "2(3^{x})-3x+4", "issue 90" );
48-
equals( expr([ "*", -2, [ "^", "x", 2 ] ]), "-2x^{2}", "polynomial term" );
46+
equal( expr([ "+", [ "*", 2, [ "^", 3, 2 ] ], [ "*", -3, 3 ], 4 ]), "2(3^{2})+(-3)(3)+4", "issue 90" );
47+
equal( expr([ "+", [ "*", 2, [ "^", 3, "x" ] ], [ "*", -3, "x" ], 4 ]), "2(3^{x})-3x+4", "issue 90" );
48+
equal( expr([ "*", -2, [ "^", "x", 2 ] ]), "-2x^{2}", "polynomial term" );
4949

50-
equals( expr([ "-", [ "+", 1, 2 ] ]), "-(1+2)", "-1*(1+2)" );
51-
equals( expr([ "-", [ "+", 1, -2 ] ]), "-(1-2)", "-1*(1-2)" );
52-
equals( expr([ "*", 3, [ "+", 1, -2 ], 4 ]), "3(1-2)(4)", "3 * (1-2) * 4" );
53-
equals( expr([ "*", 3, [ "-", 1, -2 ], 4 ]), "3(1-(-2))(4)", "3 * (1-(-2)) * 4" );
54-
equals( expr([ "+", 1, [ "-", [ "*", 2, 3, 4 ] ], 5, 6 ]), "1-(2)(3)(4)+5+6", "1-(2)(3)(4)+5+6" );
50+
equal( expr([ "-", [ "+", 1, 2 ] ]), "-(1+2)", "-1*(1+2)" );
51+
equal( expr([ "-", [ "+", 1, -2 ] ]), "-(1-2)", "-1*(1-2)" );
52+
equal( expr([ "*", 3, [ "+", 1, -2 ], 4 ]), "3(1-2)(4)", "3 * (1-2) * 4" );
53+
equal( expr([ "*", 3, [ "-", 1, -2 ], 4 ]), "3(1-(-2))(4)", "3 * (1-(-2)) * 4" );
54+
equal( expr([ "+", 1, [ "-", [ "*", 2, 3, 4 ] ], 5, 6 ]), "1-(2)(3)(4)+5+6", "1-(2)(3)(4)+5+6" );
5555

5656
// Test colors
57-
equals( expr([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ]), "4(2+\\color{blue}{2})", "4(2+\\color{blue}{2})" );
58-
equals( expr([ "*", 4, [ "color", "blue", 2 ] ]), "(4)(\\color{blue}{2})", "(4)(\\color{blue}{2})" );
57+
equal( expr([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ]), "4(2+\\color{blue}{2})", "4(2+\\color{blue}{2})" );
58+
equal( expr([ "*", 4, [ "color", "blue", 2 ] ]), "(4)(\\color{blue}{2})", "(4)(\\color{blue}{2})" );
5959
});
6060

6161
test( "Expression evaluator", function() {
62-
equals( expr([ "+", 2, 4 ], true ), 6, "2 + 4" );
63-
equals( expr([ "*", 2, 4 ], true ), 8, "2 * 4" );
64-
equals( expr([ "-", 2, 4 ], true ), -2, "2 - 4" );
65-
equals( expr([ "/", 2, 4 ], true ), 0.5, "2 / 4" );
66-
equals( expr([ "^", 2, 4 ], true ), 16, "2 ^ 4" );
67-
equals( expr([ "frac", 2, 4 ], true ), 0.5, "2 `frac` 4" );
68-
equals( expr([ "sqrt", 65536 ], true ), 256, "sqrt 65536" );
69-
equals( expr([ "+", [ "*", 2, 4 ], 6 ], true ), 14, "2 * 4 + 6" );
62+
equal( expr([ "+", 2, 4 ], true ), 6, "2 + 4" );
63+
equal( expr([ "*", 2, 4 ], true ), 8, "2 * 4" );
64+
equal( expr([ "-", 2, 4 ], true ), -2, "2 - 4" );
65+
equal( expr([ "/", 2, 4 ], true ), 0.5, "2 / 4" );
66+
equal( expr([ "^", 2, 4 ], true ), 16, "2 ^ 4" );
67+
equal( expr([ "frac", 2, 4 ], true ), 0.5, "2 `frac` 4" );
68+
equal( expr([ "sqrt", 65536 ], true ), 256, "sqrt 65536" );
69+
equal( expr([ "+", [ "*", 2, 4 ], 6 ], true ), 14, "2 * 4 + 6" );
7070

7171
// Test colors
72-
equals( expr([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ], true), 16, "4*(2+\\color{blue}{2})" );
73-
equals( expr([ "*", 4, [ "color", "blue", 2 ] ], true), 8, "(4)(\\color{blue}{2})" );
72+
equal( expr([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ], true), 16, "4*(2+\\color{blue}{2})" );
73+
equal( expr([ "*", 4, [ "color", "blue", 2 ] ], true), 8, "(4)(\\color{blue}{2})" );
7474
});
7575

7676
test( "Expression utilities", function() {
7777
//remove colors
78-
equals( expr(exprStripColor([ "color", "green", 17 ])), "17", "color outside" );
79-
equals( expr(exprStripColor([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ])), "4(2+2)", "color inside" );
78+
equal( expr(exprStripColor([ "color", "green", 17 ])), "17", "color outside" );
79+
equal( expr(exprStripColor([ "*", 4, [ "+", 2, [ "color", "blue", 2 ] ] ])), "4(2+2)", "color inside" );
8080

8181
//simplify an expression
82-
equals( expr(exprSimplifyAssociative([ "+", 1, [ "+", [ "+", 2, 3 ], 4 ] ])), "1+2+3+4", "Simplify 1+((2+3)+4)" );
83-
equals( expr(exprSimplifyAssociative([ "*", [ "*", [ "*", 2, 3 ], 4 ], 5 ])), "(2)(3)(4)(5)", "Simplify ((2*3)*4)*5" );
84-
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" );
82+
equal( expr(exprSimplifyAssociative([ "+", 1, [ "+", [ "+", 2, 3 ], 4 ] ])), "1+2+3+4", "Simplify 1+((2+3)+4)" );
83+
equal( expr(exprSimplifyAssociative([ "*", [ "*", [ "*", 2, 3 ], 4 ], 5 ])), "(2)(3)(4)(5)", "Simplify ((2*3)*4)*5" );
84+
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" );
8585
});
8686

8787
})();

utils/test/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
<script src="calculus.js"></script>
4545
<script src="../tmpl.js"></script>
4646
<script src="tmpl.js"></script>
47+
<script src="../matrix.js"></script>
48+
<script src="matrix.js"></script>
4749
</head>
4850
<body>
4951
<h1 id="qunit-header">Utility Test Suite</h1>

utils/test/math.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ test( "math miscellanea", 44, function() {
66
deepEqual( KhanUtil.digits(376), [ 6, 7, 3 ], "digits(376)" );
77
deepEqual( KhanUtil.integerToDigits(376), [ 3, 7, 6 ], "integerToDigits(376)" );
88

9-
equals( KhanUtil.getGCD(216, 1024), 8, "gcd(216, 1024)" );
10-
equals( KhanUtil.getGCD(512341, 2325183), 1, "gcd(512341, 2325183)" );
11-
equals( KhanUtil.getGCD(53110108, 109775188), 68, "gcd(53110108, 109775188)" );
12-
equals( KhanUtil.getGCD(-21, 14), 7, "gcd(-21, 14)" );
13-
equals( KhanUtil.getGCD(-21, -14), 7, "gcd(-21, -14)" );
14-
equals( KhanUtil.getGCD(123, 1), 1, "gcd(123, 1)" );
15-
equals( KhanUtil.getGCD(123, 1), 1, "gcd(123, 1)" );
16-
equals( KhanUtil.getGCD(123, 123), 123, "gcd(123, 123)" );
17-
equals( KhanUtil.getGCD(169, 26, -52), 13, "gcd(169, 26, -52)" );
9+
equal( KhanUtil.getGCD(216, 1024), 8, "gcd(216, 1024)" );
10+
equal( KhanUtil.getGCD(512341, 2325183), 1, "gcd(512341, 2325183)" );
11+
equal( KhanUtil.getGCD(53110108, 109775188), 68, "gcd(53110108, 109775188)" );
12+
equal( KhanUtil.getGCD(-21, 14), 7, "gcd(-21, 14)" );
13+
equal( KhanUtil.getGCD(-21, -14), 7, "gcd(-21, -14)" );
14+
equal( KhanUtil.getGCD(123, 1), 1, "gcd(123, 1)" );
15+
equal( KhanUtil.getGCD(123, 1), 1, "gcd(123, 1)" );
16+
equal( KhanUtil.getGCD(123, 123), 123, "gcd(123, 123)" );
17+
equal( KhanUtil.getGCD(169, 26, -52), 13, "gcd(169, 26, -52)" );
1818

19-
equals( KhanUtil.getLCM(216, 1024), 27648, "lcm(216, 1024)" );
20-
equals( KhanUtil.getLCM(216, -1024), 27648, "lcm(216, -1024)" );
21-
equals( KhanUtil.getLCM(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 2520, "lcm(1..10)" );
19+
equal( KhanUtil.getLCM(216, 1024), 27648, "lcm(216, 1024)" );
20+
equal( KhanUtil.getLCM(216, -1024), 27648, "lcm(216, -1024)" );
21+
equal( KhanUtil.getLCM(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 2520, "lcm(1..10)" );
2222

23-
equals( KhanUtil.isPrime(1), false, "primeq 1" );
24-
equals( KhanUtil.isPrime(2), true, "primeq 2" );
25-
equals( KhanUtil.isPrime(216), false, "primeq 216" );
26-
equals( KhanUtil.isPrime(127), true, "primeq 127" );
27-
equals( KhanUtil.isPrime(129), false, "primeq 129" );
23+
equal( KhanUtil.isPrime(1), false, "primeq 1" );
24+
equal( KhanUtil.isPrime(2), true, "primeq 2" );
25+
equal( KhanUtil.isPrime(216), false, "primeq 216" );
26+
equal( KhanUtil.isPrime(127), true, "primeq 127" );
27+
equal( KhanUtil.isPrime(129), false, "primeq 129" );
2828

29-
equals( KhanUtil.isOdd(0), false, "oddq 0" );
30-
equals( KhanUtil.isOdd(1), true, "oddq 1" );
29+
equal( KhanUtil.isOdd(0), false, "oddq 0" );
30+
equal( KhanUtil.isOdd(1), true, "oddq 1" );
3131

32-
equals( KhanUtil.isEven(0), true, "evenq 0" );
33-
equals( KhanUtil.isEven(1), false, "evenq 1" );
32+
equal( KhanUtil.isEven(0), true, "evenq 0" );
33+
equal( KhanUtil.isEven(1), false, "evenq 1" );
3434

3535
deepEqual( KhanUtil.getPrimeFactorization( 6 ), [ 2, 3 ], "factor 6" );
3636
deepEqual( KhanUtil.getPrimeFactorization( 23 ), [ 23 ], "factor 23" );
@@ -46,8 +46,8 @@ test( "math miscellanea", 44, function() {
4646
deepEqual( KhanUtil.getMultiples( 7, 80 ), [ 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77 ], "multiples 7, 80" );
4747
deepEqual( KhanUtil.getMultiples( 7, 83 ), [ 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77 ], "multiples 7, 83" );
4848

49-
equals( KhanUtil.roundTo( 2, Math.PI ), 3.14, "roundTo 2, pi" );
50-
equals( KhanUtil.roundTo( 0, Math.PI ), 3, "roundTo 0, pi" );
49+
equal( KhanUtil.roundTo( 2, Math.PI ), 3.14, "roundTo 2, pi" );
50+
equal( KhanUtil.roundTo( 0, Math.PI ), 3, "roundTo 0, pi" );
5151

5252
deepEqual( KhanUtil.toFraction( 4/8 ), [ 1, 2 ], "4/8" );
5353
deepEqual( KhanUtil.toFraction( 0.666 ), [ 333, 500 ], "0.666" );

utils/test/matrix.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module("matrix");
2+
3+
(function() {
4+
5+
test("matrixTranspose", function() {
6+
7+
function matrixToString(m) {
8+
return m.join("; ");
9+
}
10+
11+
function testMatrixTranspose(m, text) {
12+
13+
m = KhanUtil.makeMatrix(m);
14+
var n = KhanUtil.matrixTranspose(m);
15+
var d = KhanUtil.matrixTranspose(n);
16+
17+
var ms = matrixToString(m);
18+
if (text) {
19+
ms = ms + ": " + text;
20+
}
21+
22+
deepEqual(m, d, ms);
23+
}
24+
25+
testMatrixTranspose([[1, 2, 3, 4]]);
26+
testMatrixTranspose([[1,2],[3,4]]);
27+
28+
testMatrixTranspose([[1],[2],[3,4]], "ill-formatted");
29+
testMatrixTranspose([[1], [2], [3], [4]]);
30+
31+
testMatrixTranspose([[1, 2], [3, 4], [5, 6]]);
32+
testMatrixTranspose([[1, 2, 3], [4, 5, 6]]);
33+
testMatrixTranspose([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
34+
});
35+
36+
})();

utils/test/polynomials.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ polyCoefs[2] = -3;
1212
polyCoefs[4] = 2;
1313

1414
test("Polynomial constructor defaults", function(){
15-
equals((new KhanUtil.Polynomial(-1, 4, polyCoefs)).toString(),"2x^{4}-3x^{2}+12x+5+3x^{-1}", "defaults variable name to x");
15+
equal((new KhanUtil.Polynomial(-1, 4, polyCoefs)).toString(),"2x^{4}-3x^{2}+12x+5+3x^{-1}", "defaults variable name to x");
1616
ok((new KhanUtil.Polynomial(-1, 4)).toString(), "randomly generate coefs (3rd param) if not passed");
17-
equals(new KhanUtil.Polynomial(-1, 4, polyCoefs).getNumberOfTerms(),5,"should only have 5 terms as no 3 coef");
17+
equal(new KhanUtil.Polynomial(-1, 4, polyCoefs).getNumberOfTerms(),5,"should only have 5 terms as no 3 coef");
1818
});
1919

2020
test("Polynomial evalOf", function(){
21-
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");
21+
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");
2222
});
2323

2424
test( "Polynomial extractFromExpr", function(){
2525
var polynomial = new KhanUtil.Polynomial(-1, 4, polyCoefs);
26-
equals(polynomial.getCoefAndDegreeForTerm( 0 ).coef,2,"leading term is 2x^4");
27-
equals(polynomial.getCoefAndDegreeForTerm( 0 ).degree,4,"leading term is 2x^4");
28-
equals(polynomial.getCoefAndDegreeForTerm( 1 ).coef,-3,"second term is -3x^2");
29-
equals(polynomial.getCoefAndDegreeForTerm( 1 ).degree,2,"second term is -3x^2");
30-
equals(polynomial.getCoefAndDegreeForTerm( 2 ).coef,12,"third term is 12x");
31-
equals(polynomial.getCoefAndDegreeForTerm( 2 ).degree,1,"third term is 12x");
26+
equal(polynomial.getCoefAndDegreeForTerm( 0 ).coef,2,"leading term is 2x^4");
27+
equal(polynomial.getCoefAndDegreeForTerm( 0 ).degree,4,"leading term is 2x^4");
28+
equal(polynomial.getCoefAndDegreeForTerm( 1 ).coef,-3,"second term is -3x^2");
29+
equal(polynomial.getCoefAndDegreeForTerm( 1 ).degree,2,"second term is -3x^2");
30+
equal(polynomial.getCoefAndDegreeForTerm( 2 ).coef,12,"third term is 12x");
31+
equal(polynomial.getCoefAndDegreeForTerm( 2 ).degree,1,"third term is 12x");
3232
});
3333

3434
})();

0 commit comments

Comments
 (0)