Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Declare vars in tests late

  • Loading branch information...
commit 2809bf9fbe80c0b805a741860dfe7b452f0b59ca 1 parent cc94b2b
@fhd authored
View
112 public/test/tests/dataStructures/display.js
@@ -56,105 +56,87 @@ module("dataStructures/display", {
});
test("initStack", 8, function() {
- var pushButton, popButton;
+ dataStructures.init(new Stack());
+
+ var pushButton = $("#pushButton"),
+ popButton = $("#popButton");
+
+ ok(pushButton.length,
+ "A button for the push operation should be created.");
+ ok(popButton.length,
+ "A button for the pop operation should be created.");
- function testPush(value) {
+ ["5", "6"].forEach(function(value) {
$("#pushInput").val(value);
pushButton.click();
ok(dataStructures.addBox.calledWith(0, value), "A box with value " +
value + " should be added.");
- }
+ });
- function testPop(value) {
+ ["6", "5"].forEach(function(value) {
popButton.click()
ok(dataStructures.removeBox.calledWith(0), "The box with value " +
value + " should be removed.");
equal($("#popOutput").text(), value);
- }
-
- dataStructures.init(new Stack());
-
- pushButton = $("#pushButton");
- popButton = $("#popButton");
-
- ok(pushButton.length,
- "A button for the push operation should be created.");
- ok(popButton.length,
- "A button for the pop operation should be created.");
-
- testPush("5");
- testPush("6");
-
- testPop("6");
- testPop("5");
+ });
});
test("initQueue", 8, function() {
- var enqueueButton, dequeueButton;
-
- function testEnqueue(value, index) {
- $("#enqueueInput").val(value);
- enqueueButton.click();
- ok(dataStructures.addBox.calledWith(index, value), "A box with value " +
- value + " should be added at position " + index + ".");
- }
-
- function testDequeue(value, index) {
- dequeueButton.click()
- ok(dataStructures.removeBox.calledWith(index), "The box at index " +
- index + " should be removed.");
- equal($("#dequeueOutput").text(), value);
- }
-
dataStructures.init(new Queue());
- enqueueButton = $("#enqueueButton");
- dequeueButton = $("#dequeueButton");
+ var enqueueButton = $("#enqueueButton"),
+ dequeueButton = $("#dequeueButton");
ok(enqueueButton.length,
"A button for the enqueue operation should be created.");
ok(dequeueButton.length,
"A button for the dequeue operation should be created.");
- testEnqueue("5", 0);
- testEnqueue("6", 0);
-
- testDequeue("5", 1);
- testDequeue("6", 0);
-});
-
-test("initLinkedList", 8, function() {
- var insertButton, deleteButton;
-
- function testInsert(value, index) {
- $("#insertInput").val(value);
- insertButton.click();
+ [["5", 0], ["6", 0]].forEach(function(pair) {
+ var value = pair[0],
+ index = pair[1];
+ $("#enqueueInput").val(value);
+ enqueueButton.click();
ok(dataStructures.addBox.calledWith(index, value), "A box with value " +
value + " should be added at position " + index + ".");
- }
+ });
- function testDelete(value, index) {
- $("#deleteInput").val(value);
- deleteButton.click()
+ [["5", 1], ["6", 0]].forEach(function(pair) {
+ var value = pair[0],
+ index = pair[1];
+ dequeueButton.click()
ok(dataStructures.removeBox.calledWith(index), "The box at index " +
index + " should be removed.");
- }
+ equal($("#dequeueOutput").text(), value);
+ });
+});
+test("initLinkedList", 8, function() {
dataStructures.init(new LinkedList());
- insertButton = $("#insertButton");
- deleteButton = $("#deleteButton");
+ var insertButton = $("#insertButton"),
+ deleteButton = $("#deleteButton");
ok(insertButton.length,
"A button for the insert operation should be created.");
ok(deleteButton.length,
"A button for the delete operation should be created.");
- testInsert("5", 0);
- testInsert("6", 1);
- testInsert("7", 2);
+ [["5", 0], ["6", 1], ["7", 2]].forEach(function(pair) {
+ var value = pair[0],
+ index = pair[1];
+ $("#insertInput").val(value);
+ insertButton.click();
+ ok(dataStructures.addBox.calledWith(index, value), "A box with value " +
+ value + " should be added at position " + index + ".");
+ });
- testDelete("6", 1);
- testDelete("5", 0);
- testDelete("7", 0);
+ [["6", 1], ["5", 0], ["7", 0]].forEach(function(pair) {
+ var value = pair[0],
+ index = pair[1];
+ $("#deleteInput").val(value);
+ deleteButton.click()
+ ok(dataStructures.removeBox.calledWith(index), "The box at index " +
+ index + " should be removed.");
+ });
});
View
4 public/test/tests/display.js
@@ -1,12 +1,10 @@
module("display");
test("init", 3, function() {
- var draw;
-
currentAlgorithmFile = "";
$("body").append($("<canvas/>").attr("id", "canvas"));
- draw = sinon.spy();
+ var draw = sinon.spy();
prettyPrint = sinon.spy();
sinon.stub(window, "setInterval");
View
7 public/test/tests/sorting/sort.js
@@ -8,20 +8,17 @@ module("sorting/sort", {
});
function isSorted(array) {
- var i;
- for (i = 0; i < array.length - 1; i++)
+ for (var i = 0; i < array.length - 1; i++)
if (array[i] >= array[i + 1])
return false;
return true;
};
function containsAll(array1, array2) {
- var i;
-
if (array1.length < array2.length)
return false;
- for (i = 0; i < array2.length; i++)
+ for (var i = 0; i < array2.length; i++)
if (array1.indexOf(array2[i]) === -1)
return false;
return true;
View
3  public/test/tests/sorting/worker.js
@@ -7,11 +7,10 @@ test("sleep", 1, function() {
});
test("update", 2, function() {
- var array = [1, 2, 3];
-
sinon.stub(window, "sleep");
sinon.stub(window, "postMessage");
+ var array = [1, 2, 3];
update(array);
ok(sleep.calledWith(200), "Should sleep on each update.");
Please sign in to comment.
Something went wrong with that request. Please try again.