Skip to content
Closed

test #72

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
122eeff
Fixed natural summing specs so that they are below 1000 rather than u…
Dec 28, 2011
7d392e3
Corrected typo "Please medit(i)ate on the following code:"
Dec 28, 2011
e3bb788
Merge pull request #13 from jfraser/patch-1
gregmalcolm Jan 2, 2012
656fd24
Merge pull request #14 from jfraser/patch-2
gregmalcolm Jan 2, 2012
431f0ec
Making function braces consistent
wyattdanger May 14, 2012
ff8f175
Merge pull request #15 from wyattdanger/master
mrdavidlaing May 14, 2012
ee4baf8
Made global variables local
sunesimonsen Jul 31, 2012
64317bd
Merge pull request #16 from sunesimonsen/patch-1
mrdavidlaing Jul 31, 2012
5ee5cc4
Obfuscate variable and function names to aid true understanding -- su…
ultrasaurus Dec 28, 2012
dc6daac
Merge pull request #17 from blazingcloud/master
Dec 28, 2012
60a9671
Update koans/AboutArrays.js
magopian Feb 15, 2013
dd71c36
Merge pull request #18 from magopian/patch-1
Feb 15, 2013
20fc218
Replaces tabs with 2 spaces and removes whitespace from specs
mraaroncruz Apr 12, 2013
6e9e0d1
Merge pull request #22 from pferdefleisch/remove-tabs-and-whitespace-…
mrdavidlaing Apr 12, 2013
27ad9ab
Removed troublesome function koan. Fixes #9. Fixes #10.
mraaroncruz Apr 12, 2013
b3e40cd
Small indentation fix
morty May 19, 2013
860dae7
Merge pull request #24 from morty/patch-1
mrdavidlaing May 20, 2013
44b1af3
Fix missing semicolon.
jonasac Nov 29, 2013
8300368
Merge pull request #26 from jonasac/patch-1
mraaroncruz Dec 3, 2013
bce7da3
corrected misspelling in "megalomaniac" instances
useffc Dec 18, 2013
f3cb0f6
Merge pull request #28 from useffc/master
gregmalcolm Dec 19, 2013
73d903b
updates the LICENSE to include a proper header, a range of years for …
choskim Mar 14, 2014
b8c7a03
fixes indentation for comments and a punctuation mistake.
choskim Mar 15, 2014
08832bd
removes extra quotation mark
choskim Mar 15, 2014
307bf10
updates all comments in aboutExpects.js to have one space (not two sp…
choskim Mar 15, 2014
bdf23a5
Merge pull request #29 from choskim/license
gregmalcolm Mar 16, 2014
5f83a47
Merge pull request #30 from choskim/aboutExpects
gregmalcolm Mar 16, 2014
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
4 changes: 3 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Copyright (c) 2010 David Laing
The MIT License (MIT)

Copyright (c) 2010-2014 David Laing and Greg Malcolm

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
20 changes: 10 additions & 10 deletions koans/AboutApplyingWhatWeHaveLearnt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe("About Applying What We Have Learnt", function() {

var products;

beforeEach(function () {
beforeEach(function () {
products = [
{ name: "Sonoma", ingredients: ["artichoke", "sundried tomatoes", "mushrooms"], containsNuts: false },
{ name: "Pizza Primavera", ingredients: ["roma", "sundried tomatoes", "goats cheese", "rosemary"], containsNuts: false },
Expand Down Expand Up @@ -47,22 +47,22 @@ describe("About Applying What We Have Learnt", function() {
/*********************************************************************************/

it("should add all the natural numbers below 1000 that are multiples of 3 or 5 (imperative)", function () {

var sum = 0;
for(var i=1; i<=1000; i+=1) {
for(var i=1; i<1000; i+=1) {
if (i % 3 === 0 || i % 5 === 0) {
sum += i;
}
}

expect(sum).toBe(FILL_ME_IN);
});

it("should add all the natural numbers below 1000 that are multiples of 3 or 5 (functional)", function () {

var sum = FILL_ME_IN; /* try chaining range() and reduce() */

expect(234168).toBe(FILL_ME_IN);
expect(233168).toBe(FILL_ME_IN);
});

/*********************************************************************************/
Expand Down Expand Up @@ -90,20 +90,20 @@ describe("About Applying What We Have Learnt", function() {
/* UNCOMMENT FOR EXTRA CREDIT */
/*
it("should find the largest prime factor of a composite number", function () {

});

it("should find the largest palindrome made from the product of two 3 digit numbers", function () {

});

it("should find the smallest number divisible by each of the numbers 1 to 20", function () {


});

it("should find the difference between the sum of the squares and the square of the sums", function () {

});

it("should find the 10001st prime", function () {
Expand Down
20 changes: 10 additions & 10 deletions koans/AboutArrays.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe("About Arrays", function() {

//We shall contemplate truth by testing reality, via spec expectations.
//We shall contemplate truth by testing reality, via spec expectations.
it("should create arrays", function() {
var emptyArray = [];
expect(typeof(emptyArray)).toBe(FILL_ME_IN); //A mistake? - http:javascript.crockford.com/remedial.html
expect(typeof(emptyArray)).toBe(FILL_ME_IN); //A mistake? - http://javascript.crockford.com/remedial.html
expect(emptyArray.length).toBe(FILL_ME_IN);

var multiTypeArray = [0, 1, "two", function () { return 3; }, {value1: 4, value2: 5}, [6, 7]];
Expand All @@ -18,13 +18,13 @@ describe("About Arrays", function() {
it("should understand array literals", function () {
var array = [];
expect(array).toEqual([]);

array[0] = 1;
expect(array).toEqual([1]);

array[1] = 2;
expect(array).toEqual([1, FILL_ME_IN]);

array.push(3);
expect(array).toEqual(FILL_ME_IN);
});
Expand All @@ -36,7 +36,7 @@ describe("About Arrays", function() {
fourNumberArray.push(5, 6);
expect(fourNumberArray.length).toBe(FILL_ME_IN);

var tenEmptyElementArray = new Array(10);
var tenEmptyElementArray = new Array(10);
expect(tenEmptyElementArray.length).toBe(FILL_ME_IN);

tenEmptyElementArray.length = 5;
Expand All @@ -45,7 +45,7 @@ describe("About Arrays", function() {

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

expect(array.slice(0, 1)).toEqual(FILL_ME_IN);
expect(array.slice(0, 2)).toEqual(FILL_ME_IN);
expect(array.slice(2, 2)).toEqual(FILL_ME_IN);
Expand Down Expand Up @@ -78,7 +78,7 @@ describe("About Arrays", function() {
array.push(3);

expect(array).toEqual(FILL_ME_IN);

var poppedValue = array.pop();
expect(poppedValue).toBe(FILL_ME_IN);
expect(array).toEqual(FILL_ME_IN);
Expand All @@ -89,9 +89,9 @@ describe("About Arrays", function() {

array.unshift(3);
expect(array).toEqual(FILL_ME_IN);

var shiftedValue = array.shift();
expect(shiftedValue).toEqual(FILL_ME_IN);
expect(array).toEqual(FILL_ME_IN);
});
});
});
48 changes: 24 additions & 24 deletions koans/AboutExpects.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
describe("About Expects", function() {

//We shall contemplate truth by testing reality, via spec expectations.
// We shall contemplate truth by testing reality, via spec expectations.
it("should expect true", function() {
expect(false).toBeTruthy(); //This should be true
});

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

//Some ways of asserting equality are better than others.
it("should assert equality a better way", function () {
var expectedValue = FILL_ME_IN;
var actualValue = 1 + 1;
// To understand reality, we must compare our expectations against reality.
it("should expect equality", function () {
var expectedValue = FILL_ME_IN;
var actualValue = 1 + 1;

expect(actualValue === expectedValue).toBeTruthy();
});

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

// toEqual() compares using common sense equality.
expect(actualValue).toEqual(expectedValue);
expect(actualValue).toEqual(expectedValue);
});

//Sometimes you need to be really exact about what you "type".
it("should assert equality with ===", function () {
var expectedValue = FILL_ME_IN;
var actualValue = (1 + 1).toString();
// Sometimes you need to be really exact about what you "type."
it("should assert equality with ===", function () {
var expectedValue = FILL_ME_IN;
var actualValue = (1 + 1).toString();

// toBe() will always use === to compare.
expect(actualValue).toBe(expectedValue);
});
expect(actualValue).toBe(expectedValue);
});

//Sometimes we will ask you to fill in the values.
// Sometimes we will ask you to fill in the values.
it("should have filled in values", function () {
expect(1 + 1).toEqual(FILL_ME_IN);
expect(1 + 1).toEqual(FILL_ME_IN);
});
});
74 changes: 30 additions & 44 deletions koans/AboutFunctions.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
describe("About Functions", function() {

it("should declare functions", function() {

function add(a, b) {
return a + b;
}

expect(add(1, 2)).toBe(FILL_ME_IN);
});

it("should know internal variables override outer variables", function () {
var message = "Outer";

function getMessage() {
return message;
}

function overrideMessage() {
var message = "Inner";
return message;
}

expect(getMessage()).toBe(FILL_ME_IN);
expect(overrideMessage()).toBe(FILL_ME_IN);
expect(message).toBe(FILL_ME_IN);
Expand All @@ -29,57 +29,54 @@ describe("About Functions", function() {
it("should have lexical scoping", function () {
var variable = "top-level";
function parentfunction() {
var variable = "local";
var variable = "local";
function childfunction() {
return variable;
return variable;
}
return childfunction();
}
expect(parentfunction()).toBe(FILL_ME_IN);
});

it("should use lexical scoping to synthesise functions", function () {
function makeIncreaseByFunction(increaseByAmount)

function makeMysteryFunction(makerValue)
{
var increaseByFunction = function increaseBy(numberToIncrease)
var newFunction = function doMysteriousThing(param)
{
return numberToIncrease + increaseByAmount;
return makerValue + param;
};
return increaseByFunction;
return newFunction;
}
var increaseBy3 = makeIncreaseByFunction(3);
var increaseBy5 = makeIncreaseByFunction(5);
expect(increaseBy3(10) + increaseBy5(10)).toBe(FILL_ME_IN);

var mysteryFunction3 = makeMysteryFunction(3);
var mysteryFunction5 = makeMysteryFunction(5);

expect(mysteryFunction3(10) + mysteryFunction5(5)).toBe(FILL_ME_IN);
});

it("should allow extra function arguments", function () {

function returnFirstArg(firstArg)
{

function returnFirstArg(firstArg) {
return firstArg;
}

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

function returnSecondArg(firstArg, secondArg)
{

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

expect(returnSecondArg("only give first arg")).toBe(FILL_ME_IN);

function returnAllArgs()
{

function returnAllArgs() {
var argsArray = [];
for (var i = 0; i < arguments.length; i += 1) {
argsArray.push(arguments[i]);
}
return argsArray.join(",");
}

expect(returnAllArgs("first", "second", "third")).toBe(FILL_ME_IN);
});

Expand All @@ -88,27 +85,16 @@ describe("About Functions", function() {
var appendRules = function (name) {
return name + " rules!";
};

var appendDoubleRules = function (name) {
return name + " totally rules!";
};

var praiseSinger = { givePraise: appendRules };
expect(praiseSinger.givePraise("John")).toBe(FILL_ME_IN);

praiseSinger.givePraise = appendDoubleRules;
expect(praiseSinger.givePraise("Mary")).toBe(FILL_ME_IN);

});

it("should use function body as a string", function () {
var add = new Function("a", "b", "return a + b;");
expect(add(1, 2)).toBe(FILL_ME_IN);

var multiply = function (a, b) {
//An internal comment
return a * b;
};
expect(multiply.toString()).toBe(FILL_ME_IN);
});
});
});
Loading