Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 2015-09-01
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

14 changes: 7 additions & 7 deletions koans/00--AboutExpects.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
var expect = require('chai').expect,
FILL_ME_IN;
FILL_ME_IN;

describe("About Expects", function() {
// We shall contemplate truth by testing reality, via spec expectations.
it("should expect true", function() {
expect(FILL_ME_IN).to.be.true; //This should be true
expect(true).to.be.true; //This should be true
});

// To understand reality, we must compare our expectations against reality.
it("should expect equality", function () {
var actual = 1 + 1;

expect(actual === FILL_ME_IN).to.be.true
expect(actual === 2).to.be.true
});

// Some ways of asserting equality are better than others.
it("should assert equality a better way", function () {
var actual = 1 + 1;

// to.equal() compares using "strict" equality (===)
expect(actual).to.equal(FILL_ME_IN);
expect(actual).to.equal(2);
});

// Sometimes you need to be really exact about what you "type."
it("should check the _type_ first", function () {
var actual = (1 + 1).toString();

// use to.be.a() to check the type of a value
expect(actual).to.be.a(FILL_ME_IN);
expect(actual).to.be.a(typeof('object'));

expect(actual).to.be(1); // Fails?
expect(actual).to.be(2); // Fails?
});

// Sometimes we will ask you to fill in the values.
it("should have filled in values", function () {
expect(1 + 1).to.equal(FILL_ME_IN);
expect(1 + 1).to.equal(2);
});
});
63 changes: 32 additions & 31 deletions koans/01--AboutArrays.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
var expect = require('chai').expect,
FILL_ME_IN;


describe("About Arrays", function() {

//We shall contemplate truth by testing reality, via spec expectations.
it("should create arrays", function() {
var emptyArray = [];

expect(typeof(emptyArray)).to.equal(FILL_ME_IN);
expect(typeof(emptyArray)).to.equal('object');
// A mistake? - http://javascript.crockford.com/remedial.html

expect(emptyArray.length).to.equal(FILL_ME_IN);
expect(emptyArray.length).to.equal(0);

expect(emptyArray).to.be.empty;

Expand All @@ -24,19 +25,19 @@ describe("About Arrays", function() {
];

// What is the value of each element?
expect(multiTypeArray[0]).to.equal(FILL_ME_IN);
expect(multiTypeArray[0]).to.equal(0);

expect(multiTypeArray[2]).to.equal(FILL_ME_IN);
expect(multiTypeArray[2]).to.equal("two");

// Careful, this one is tricky... explain why!
expect( multiTypeArray[3]() ).to.equal(FILL_ME_IN);
expect( multiTypeArray[3]() ).to.equal(3);

expect(multiTypeArray[4].value1).to.equal(FILL_ME_IN);
expect(multiTypeArray[4].value1).to.equal(4);

// What are those brackets doing there?
expect(multiTypeArray[4]["value2"]).to.equal(FILL_ME_IN);
expect(multiTypeArray[4]["value2"]).to.equal(5);

expect(multiTypeArray[5][0]).to.equal(FILL_ME_IN);
expect(multiTypeArray[5][0]).to.equal(6);
});

it("should understand array literals", function () {
Expand All @@ -50,47 +51,47 @@ describe("About Arrays", function() {

array[1] = 2;

expect(array).to.deep.equal(FILL_ME_IN);
expect(array).to.deep.equal([1, 2]);

array.push(3);

expect(array).to.deep.equal(FILL_ME_IN);
expect(array).to.deep.equal([1, 2, 3]);
});

it("should understand array length", function () {
var fourNumberArray = [1, 2, 3, 4];

expect(fourNumberArray.length).to.equal(FILL_ME_IN);
expect(fourNumberArray.length).to.equal(4);

fourNumberArray.push(5, 6);

expect(fourNumberArray.length).to.equal(FILL_ME_IN);
expect(fourNumberArray.length).to.equal(6);

var tenEmptyElementArray = new Array(10);

expect(tenEmptyElementArray.length).to.equal(FILL_ME_IN);
expect(tenEmptyElementArray.length).to.equal(10);

tenEmptyElementArray.length = 5;

expect(tenEmptyElementArray.length).to.equal(FILL_ME_IN);
expect(tenEmptyElementArray.length).to.equal(5);
});

it("should slice arrays", function () {
var array = ["peanut", "butter", "and", "jelly"];

expect(array.slice(0, 1)).to.deep.equal(FILL_ME_IN);
expect(array.slice(0, 1)).to.deep.equal(["peanut"]);

expect(array.slice(0, 2)).to.deep.equal(FILL_ME_IN);
expect(array.slice(0, 2)).to.deep.equal(["peanut", "butter"]);

expect(array.slice(2, 2)).to.deep.equal(FILL_ME_IN);
expect(array.slice(2, 2)).to.deep.equal([]);

expect(array.slice(2, 20)).to.deep.equal(FILL_ME_IN);
expect(array.slice(2, 20)).to.deep.equal(["and", "jelly"]);

expect(array.slice(3, 0)).to.deep.equal(FILL_ME_IN);
expect(array.slice(3, 0)).to.deep.equal([]);

expect(array.slice(3, 100)).to.deep.equal(FILL_ME_IN);
expect(array.slice(3, 100)).to.deep.equal(["jelly"]);

expect(array.slice(5, 1)).to.deep.equal(FILL_ME_IN);
expect(array.slice(5, 1)).to.deep.equal([]);
});

it("should know array references", function () {
Expand All @@ -102,46 +103,46 @@ describe("About Arrays", function() {

passedByReference(array);

expect(array[1]).to.equal(FILL_ME_IN);
expect(array[1]).to.equal("changed in function");

var assignedArray = array;

assignedArray[5] = "changed in assignedArray";

expect(array[5]).to.equal(FILL_ME_IN);
expect(array[5]).to.equal("changed in assignedArray");

var copyOfArray = array.slice();

copyOfArray[3] = "changed in copyOfArray";

expect(array[3]).to.equal(FILL_ME_IN);
expect(array[3]).to.equal("three");
});

it("should push and pop", function () {
var array = [1, 2];

expect(array.push(3)).to.equal(FILL_ME_IN);
expect(array.push(3)).to.equal(3);

expect(array).to.deep.equal(FILL_ME_IN);
expect(array).to.deep.equal([1, 2, 3]);

var poppedValue = array.pop();

expect(poppedValue).to.equal(FILL_ME_IN);
expect(poppedValue).to.equal(3);

expect(array).to.deep.equal(FILL_ME_IN);
expect(array).to.deep.equal([1, 2]);
});

it("should know about shifting arrays", function () {
var array = [1, 2];

array.unshift(3);

expect(array).to.deep.equal(FILL_ME_IN);
expect(array).to.deep.equal([3, 1, 2]);

var shiftedValue = array.shift();

expect(shiftedValue).to.deep.equal(FILL_ME_IN);
expect(shiftedValue).to.deep.equal(3);

expect(array).to.deep.equal(FILL_ME_IN);
expect(array).to.deep.equal([1, 2]);
});
});
23 changes: 12 additions & 11 deletions koans/02--AboutFunctions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var expect = require('chai').expect,
FILL_ME_IN;


describe("About Functions", function() {

it("should declare functions", function() {
Expand All @@ -9,7 +10,7 @@ describe("About Functions", function() {
return a + b;
}

expect(add(1, 2)).to.equal(FILL_ME_IN);
expect(add(1, 2)).to.equal(3);
});

it("should know internal variables override outer variables", function () {
Expand All @@ -24,11 +25,11 @@ describe("About Functions", function() {
return message;
}

expect(getMessage()).to.equal(FILL_ME_IN);
expect(getMessage()).to.equal(message);

expect(overrideMessage()).to.equal(FILL_ME_IN);
expect(overrideMessage()).to.equal("Inner");

expect(message).to.equal(FILL_ME_IN);
expect(message).to.equal("Outer");
});

it("should have lexical scoping", function () {
Expand All @@ -45,7 +46,7 @@ describe("About Functions", function() {
return childfunction();
}

expect(parentfunction()).to.equal(FILL_ME_IN);
expect(parentfunction()).to.equal("local");
});

it("should use lexical scoping to synthesise functions", function () {
Expand All @@ -63,7 +64,7 @@ describe("About Functions", function() {

var mysteryFunction5 = makeMysteryFunction(5);

expect(mysteryFunction3(10) + mysteryFunction5(5)).to.equal(FILL_ME_IN);
expect(mysteryFunction3(10) + mysteryFunction5(5)).to.equal(23);
});

it("should allow extra function arguments", function () {
Expand All @@ -72,19 +73,19 @@ describe("About Functions", function() {
return firstArg;
}

expect(returnFirstArg("first", "second", "third")).to.equal(FILL_ME_IN);
expect(returnFirstArg("first", "second", "third")).to.equal("first");

function returnSecondArg(firstArg, secondArg) {
return secondArg;
}

expect(returnSecondArg("only give first arg")).to.equal(FILL_ME_IN);
expect(returnSecondArg("only give first arg")).to.equal(undefined);

function returnAllArgs() {
return [].slice.call(arguments);
}

expect(returnAllArgs("first", "second", "third")).to.deep.equal(FILL_ME_IN);
expect(returnAllArgs("first", "second", "third")).to.deep.equal('first,second,third');
});

it("should pass functions as values", function () {
Expand All @@ -99,11 +100,11 @@ describe("About Functions", function() {

var praiseSinger = { givePraise: appendRules };

expect(praiseSinger.givePraise("John")).to.equal(FILL_ME_IN);
expect(praiseSinger.givePraise("John")).to.equal("John rules!");

praiseSinger.givePraise = appendDoubleRules;

expect(praiseSinger.givePraise("Mary")).to.equal(FILL_ME_IN);
expect(praiseSinger.givePraise("Mary")).to.equal("Mary totally rules!");

});
});
30 changes: 15 additions & 15 deletions koans/03--AboutObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ describe("About Objects", function () {
});

it("should confirm objects are collections of properties", function () {
expect(megalomaniac.mastermind).to.equal(FILL_ME_IN);
expect(megalomaniac.mastermind).to.equal("Joker");
});

it("should confirm that properties are case sensitive", function () {
expect(megalomaniac.henchwoman).to.equal(FILL_ME_IN);
expect(megalomaniac.henchWoman).to.equal(FILL_ME_IN);
expect(megalomaniac.henchwoman).to.equal("Harley");
expect(megalomaniac.henchwoman).to.equal("Harley");
});
});

Expand All @@ -32,7 +32,7 @@ describe("About Objects", function () {
};

var battleCry = megalomaniac.battleCry(4);
expect(FILL_ME_IN).to.equal(battleCry);
expect("They are Pinky and the Brain Brain Brain Brain").to.equal(battleCry);
});

it("should confirm that when a function is attached to an object, 'this' refers to the object", function () {
Expand All @@ -47,8 +47,8 @@ describe("About Objects", function () {
}
};

expect(currentYear).to.equal(FILL_ME_IN);
expect(megalomaniac.calculateAge()).to.equal(FILL_ME_IN);
expect(currentYear).to.equal(2015);
expect(megalomaniac.calculateAge()).to.equal(45);
});

describe("'in' keyword", function () {
Expand All @@ -65,27 +65,27 @@ describe("About Objects", function () {

var hasBomb = "theBomb" in megalomaniac;

expect(hasBomb).to.equal(FILL_ME_IN);
expect(hasBomb).to.equal(true);
});

it("should not have the detonator however", function () {

var hasDetonator = "theDetonator" in megalomaniac;

expect(hasDetonator).to.equal(FILL_ME_IN);
expect(hasDetonator).to.equal(false);
});
});

it("should know that properties can be added and deleted", function () {
var megalomaniac = { mastermind : "Agent Smith", henchman: "Agent Smith" };

expect("secretary" in megalomaniac).to.equal(FILL_ME_IN);
expect("secretary" in megalomaniac).to.equal(false);

megalomaniac.secretary = "Agent Smith";
expect("secretary" in megalomaniac).to.equal(FILL_ME_IN);
expect("secretary" in megalomaniac).to.equal(true);

delete megalomaniac.henchman;
expect("henchman" in megalomaniac).to.equal(FILL_ME_IN);
expect("henchman" in megalomaniac).to.equal(false);
});


Expand All @@ -99,14 +99,14 @@ describe("About Objects", function () {
var colouredCircle = new Circle(5);
colouredCircle.colour = "red";

expect(simpleCircle.colour).to.equal(FILL_ME_IN);
expect(colouredCircle.colour).to.equal(FILL_ME_IN);
expect(simpleCircle.colour).to.equal(Circle.prototype)
expect(colouredCircle.colour).to.equal(red.prototype);

Circle.prototype.describe = function () {
return "This circle has a radius of: " + this.radius;
};

expect(simpleCircle.describe()).to.equal(FILL_ME_IN);
expect(colouredCircle.describe()).to.equal(FILL_ME_IN);
expect(simpleCircle.describe()).to.equal("This circle has a radius: (10)");
expect(colouredCircle.describe()).to.equal(FI);
});
});
Loading