This repository has been archived by the owner on Feb 6, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These 4 critical files don't work anymore. Learn why!
Summary: Adds the test files from khan-exercises back. These currently don't run, but I will add a commit transforming them to use mocha+node instead of QUnit in the future. Test Plan: broken
- Loading branch information
1 parent
7bf3b45
commit b134578
Showing
6 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.PHONY: all install test | ||
|
||
all: install test | ||
|
||
install: | ||
npm install | ||
|
||
# Tricks to work with both linux and mac os x `find`, | ||
# taken from Perseus: | ||
FIND_TESTS_1 := find -E . -type f -regex '.*/__tests__/.*\.jsx?' | ||
FIND_TESTS_2 := find . -type f -regex '.*/__tests__/.*\.jsx?' | ||
|
||
ifneq ("$(shell $(FIND_TESTS_1) 2>/dev/null)","") | ||
FIND_TESTS := $(FIND_TESTS_1) | ||
else | ||
ifneq ("$(shell $(FIND_TESTS_2) 2>/dev/null)","") | ||
FIND_TESTS := $(FIND_TESTS_2) | ||
else | ||
FIND_TESTS := echo "Could not figure out how to run tests; skipping"; echo "" | ||
endif | ||
endif | ||
|
||
test: | ||
$(FIND_TESTS) | xargs ./node_modules/.bin/mocha --reporter spec | ||
shorttest: | ||
$(FIND_TESTS) | xargs ./node_modules/.bin/mocha --reporter dot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
(function() { | ||
module("kline"); | ||
|
||
var line = KhanUtil.kline; | ||
|
||
asyncTest('two identical lines should be equal', 1, function() { | ||
var result = line.equal([[1, 1], [3, 3]], [[1, 1], [3, 3]]); | ||
strictEqual(result, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('two parallel lines should not be equal', 1, function() { | ||
var result = line.equal([[1, 1], [3, 3]], [[1, 2], [3, 4]]); | ||
strictEqual(result, false); | ||
start(); | ||
}); | ||
|
||
asyncTest('two intersecting lines should not be equal', 1, function() { | ||
var result = line.equal([[1, 1], [3, 3]], [[1, 1], [3, 4]]); | ||
strictEqual(result, false); | ||
start(); | ||
}); | ||
|
||
asyncTest('two collinear lines should be equal #1', 1, function() { | ||
var result = line.equal([[1, 1], [3, 3]], [[0, 0], [5, 5]]); | ||
strictEqual(result, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('two collinear lines should be equal #2', 1, function() { | ||
var result = line.equal([[4, 4], [5, 5]], [[0, 0], [1, 1]]); | ||
strictEqual(result, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('two collinear lines should be equal #3', 1, function() { | ||
var result = line.equal([[0, 0], [1, 1]], [[3, 3], [6, 6]]); | ||
strictEqual(result, true); | ||
start(); | ||
}); | ||
|
||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
(function() { | ||
module("knumber"); | ||
|
||
var number = KhanUtil.knumber; | ||
|
||
asyncTest('two equal numbers should be equal', 1, function() { | ||
var result = number.equal(1 / 3, 1 / 90 * 30); | ||
strictEqual(result, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('two different numbers should be equal', 1, function() { | ||
var result = number.equal(1 / 3, 1.333333); | ||
strictEqual(result, false); | ||
start(); | ||
}); | ||
|
||
asyncTest('sign(0) should be 0', 1, function() { | ||
strictEqual(number.sign(0), 0); | ||
start(); | ||
}); | ||
|
||
asyncTest('sign(-0.0) should be 0', 1, function() { | ||
strictEqual(number.sign(-0.0), 0); | ||
start(); | ||
}); | ||
|
||
asyncTest('sign(3.2) should be 1', 1, function() { | ||
strictEqual(number.sign(3.2), 1); | ||
start(); | ||
}); | ||
|
||
asyncTest('sign(-2.8) should be -1', 1, function() { | ||
strictEqual(number.sign(-2.8), -1); | ||
start(); | ||
}); | ||
|
||
asyncTest('isInteger(-2.8) should be false', 1, function() { | ||
strictEqual(number.isInteger(-2.8), false); | ||
start(); | ||
}); | ||
|
||
asyncTest('isInteger(-2) should be true', 1, function() { | ||
strictEqual(number.isInteger(-2), true); | ||
start(); | ||
}); | ||
|
||
asyncTest('toFraction(-2) should be -2/1', 1, function() { | ||
deepEqual(number.toFraction(-2), [-2, 1]); | ||
start(); | ||
}); | ||
|
||
asyncTest('toFraction(-2.5) should be -5/2', 1, function() { | ||
deepEqual(number.toFraction(-2.5), [-5, 2]); | ||
start(); | ||
}); | ||
|
||
asyncTest('toFraction(2/3) should be 2/3', 1, function() { | ||
deepEqual(number.toFraction(2/3), [2, 3]); | ||
start(); | ||
}); | ||
|
||
asyncTest('toFraction(283.33...) should be 850/3', 1, function() { | ||
deepEqual(number.toFraction(283 + 1/3), [850, 3]); | ||
start(); | ||
}); | ||
|
||
asyncTest('toFraction(0) should be 0/1', 1, function() { | ||
deepEqual(number.toFraction(0), [0, 1]); | ||
start(); | ||
}); | ||
|
||
asyncTest('toFraction(pi) should be pi/1', 1, function() { | ||
deepEqual(number.toFraction(Math.PI), [Math.PI, 1]); | ||
start(); | ||
}); | ||
|
||
asyncTest('toFraction(0.66) should be 33/50', 1, function() { | ||
deepEqual(number.toFraction(0.66), [33, 50]); | ||
start(); | ||
}); | ||
|
||
asyncTest('toFraction(0.66, 0.01) should be 2/3', 1, function() { | ||
deepEqual(number.toFraction(0.66, 0.01), [2, 3]); | ||
start(); | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
(function() { | ||
module("kpoint"); | ||
|
||
var point = KhanUtil.kpoint; | ||
|
||
asyncTest('point.compare should return positive if the first element is larger', 1, function() { | ||
var result = point.compare([5, 2], [3, 4]); | ||
strictEqual(result > 0, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('point.compare should return negative if the first element is smaller', 1, function() { | ||
var result = point.compare([2, 2], [4, 0]); | ||
strictEqual(result < 0, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('point.compare should return positive if the second element is larger', 1, function() { | ||
var result = point.compare([5, 2], [5, 1]); | ||
strictEqual(result > 0, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('point.compare should return negative if the second element is smaller', 1, function() { | ||
var result = point.compare([2, 2], [2, 4]); | ||
strictEqual(result < 0, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('point.compare should return positive if the third element is larger', 1, function() { | ||
var result = point.compare([5, 3, -2], [5, 3, -4]); | ||
strictEqual(result > 0, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('point.compare should return negative if the third element is smaller', 1, function() { | ||
var result = point.compare([2, -1, -4], [2, -1, -2]); | ||
strictEqual(result < 0, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('point.compare should return 0 if the vectors are equal', 1, function() { | ||
var result = point.compare([2, 4, 3], [2, 4, 3]); | ||
strictEqual(result, 0); | ||
start(); | ||
}); | ||
|
||
asyncTest('point.compare should return negative if v1 is shorter than v2', 1, function() { | ||
var result = point.compare([2, 4], [2, 4, 3]); | ||
strictEqual(result < 0, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('point.compare should return positive if v1 is longer than v2', 1, function() { | ||
var result = point.compare([2, 4, -2], [2, 2]); | ||
strictEqual(result > 0, true); | ||
start(); | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
(function() { | ||
module("kvector"); | ||
|
||
var vector = KhanUtil.kvector; | ||
|
||
asyncTest('vector.add should add two 2D vectors', 1, function() { | ||
var result = vector.add([1, 2], [3, 4]); | ||
deepEqual(result, [4, 6]); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.add should add two 3D vectors', 1, function() { | ||
var result = vector.add([1, 2, 3], [4, 5, 6]); | ||
deepEqual(result, [5, 7, 9]); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.add should add three 2D vectors', 1, function() { | ||
var result = vector.add([1, 2], [3, 4], [5, 6]); | ||
deepEqual(result, [9, 12]); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.subtract should subtract two 2D vectors', 1, function() { | ||
var result = vector.subtract([1, 2], [3, 4]); | ||
deepEqual(result, [-2, -2]); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.subtract should subtract two 3D vectors', 1, function() { | ||
var result = vector.subtract([1, 2, 3], [4, 5, 6]); | ||
deepEqual(result, [-3, -3, -3]); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.dot should take the dot product of 2 2D vectors', 1, function() { | ||
var result = vector.dot([1, 2], [3, 4]); | ||
strictEqual(result, 3 + 8); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.dot should take the dot product of 2 3D vectors', 1, function() { | ||
var result = vector.dot([1, 2, 3], [4, 5, 6]); | ||
strictEqual(result, 4 + 10 + 18); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.scale should scale a 2D vector', 1, function() { | ||
var result = vector.scale([4, 2], 0.5); | ||
deepEqual(result, [2, 1]); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.scale should scale a 3D vector', 1, function() { | ||
var result = vector.scale([1, 2, 3], 2); | ||
deepEqual(result, [2, 4, 6]); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.length should take the length of a 2D vector', 1, function() { | ||
var result = vector.length([3, 4]); | ||
strictEqual(result, 5); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.length should take the length of a 3D vector', 1, function() { | ||
var result = vector.length([4, 0, 3]); | ||
strictEqual(result, 5); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.equal should return true on two equal 3D vectors', 1, function() { | ||
var result = vector.equal([6, 3, 4], [6, 3, 4]); | ||
strictEqual(result, true); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.equal should return false on two inequal 3D vectors', 1, function() { | ||
var result = vector.equal([6, 3, 4], [6, 4, 4]); | ||
strictEqual(result, false); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.equal should return false on a 2D and 3D vector', 1, function() { | ||
var result = vector.equal([6, 4], [6, 4, 4]); | ||
strictEqual(result, false); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.equal should return false on a 2D and 3D vector', 1, function() { | ||
var result = vector.equal([6, 3, 4], [6, 3]); | ||
strictEqual(result, false); | ||
start(); | ||
}); | ||
|
||
asyncTest('vector.equal should return false on a 2D and 3D vector with a trailing 0', 1, function() { | ||
var result = vector.equal([6, 3, 0], [6, 3]); | ||
strictEqual(result, false); | ||
start(); | ||
}); | ||
|
||
asyncTest("vector.collinear should return true on two collinear vectors of " | ||
+ "the same magnitude but different direction", 1, function() { | ||
var result = vector.collinear([3, 3], [-3, -3]); | ||
strictEqual(result, true); | ||
start(); | ||
}); | ||
|
||
asyncTest("vector.collinear should return true on two collinear vectors of " | ||
+ "different magnitudes", 1, function() { | ||
var result = vector.collinear([2, 1], [6, 3]); | ||
strictEqual(result, true); | ||
start(); | ||
}); | ||
|
||
asyncTest("vector.collinear should return false on non-collinear vectors", | ||
1, function() { | ||
var result = vector.collinear([1, 2], [-1, 2]); | ||
strictEqual(result, false); | ||
start(); | ||
}); | ||
|
||
asyncTest("vector.negate of [-2, 2] is [2, -2]", 1, function() { | ||
var result = vector.negate([-2, 2]); | ||
deepEqual(result, [2, -2]); | ||
start(); | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "kmath", | ||
"version": "0.0.0", | ||
"description": "Khan Academy's Javascript Numeric Math Utilities", | ||
"main": "kmath.js", | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Khan/kmath.git" | ||
}, | ||
"keywords": [ | ||
"math" | ||
], | ||
"author": "Khan Academy", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Khan/kmath/issues" | ||
}, | ||
"homepage": "https://github.com/Khan/kmath", | ||
"devDependencies": { | ||
"mocha": "^1.21.5" | ||
}, | ||
"dependencies": { | ||
"underscore": "^1.4.4" | ||
} | ||
} |