Skip to content

Commit 3ee6b5e

Browse files
committed
1 parent 88d116e commit 3ee6b5e

9 files changed

+92
-129
lines changed

KoansRunner.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
<script type="text/javascript" src="koans/AboutObjects.js"></script>
2222
<script type="text/javascript" src="koans/AboutMutability.js"></script>
2323
<script type="text/javascript" src="koans/AboutLambda.js"></script>
24-
<script type="text/javascript" src="koans/AboutHigherOrderFunctions.js"></script>
24+
<script type="text/javascript" src="koans/AboutHigherOrderFunctions.js"></script>
25+
<script type="text/javascript" src="koans/AboutInheritance.js"></script>
2526
<script type="text/javascript" src="koans/aboutApplyingWhatWeHaveLearnt.js"></script>
27+
2628
</head>
2729
<body>
2830

koans/AboutApplyingWhatWeHaveLearnt.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ describe("About Applying What We Have Learnt", function() {
3232
return hasInvalidOperation;
3333
};
3434

35-
expect(__).toBe(findNeedle(operations));
35+
expect(findNeedle(operations)).toBe(__);
3636
});
3737

3838
it("should find needle in a haystack (functional)", function () {
39-
expect(__).toBe(df.some(operations, "x.direction === 'FWD' && x.distance > 100"));
39+
expect(df.some(operations, "x.direction === 'FWD' && x.distance > 100")).toBe(__);
4040
});
4141

4242
/*********************************************************************************/
@@ -50,7 +50,7 @@ describe("About Applying What We Have Learnt", function() {
5050
}
5151
}
5252

53-
expect(__).toBe(sum);
53+
expect(sum).toBe(__);
5454
});
5555

5656
it("should add all the natural numbers below 1000 that are multiples of 3 or 5 (functional)", function () {
@@ -62,7 +62,7 @@ describe("About Applying What We Have Learnt", function() {
6262
};
6363
var numbers = df.repeat(1000, "+1", 1);
6464

65-
expect(__).toBe(df.reduce(numbers, sumIfMultipleOf3Or5, 0));
65+
expect(df.reduce(numbers, sumIfMultipleOf3Or5, 0)).toBe(__);
6666
});
6767

6868
/*********************************************************************************/
@@ -81,7 +81,7 @@ describe("About Applying What We Have Learnt", function() {
8181
i+=1;
8282
} while (currentFib < 4000000);
8383

84-
expect(__).toBe(sum);
84+
expect(sum).toBe(__);
8585
});
8686

8787
it("should find the sum of all the even valued terms in the fibonacci sequence which do not exceed four million (functional)", function () {
@@ -97,7 +97,7 @@ describe("About Applying What We Have Learnt", function() {
9797
var fib = df.until("item[0] > 4000000", calcNextFibTuple, [0,1]);
9898
var sum = df.reduce(fib, addEven, 0);
9999

100-
expect(__).toBe(sum);
100+
expect(sum).toBe(__);
101101
});
102102

103103
/*********************************************************************************/

koans/AboutArrays.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,56 @@ describe("About Arrays", function() {
33
//We shall contemplate truth by testing reality, via spec expectations.
44
it("should create arrays", function() {
55
var emptyArray = [];
6-
expect(__).toBe(typeof(emptyArray)); //A mistake? - http:javascript.crockford.com/remedial.html
7-
expect(__).toBe(emptyArray.length);
6+
expect(typeof(emptyArray)).toBe(__); //A mistake? - http:javascript.crockford.com/remedial.html
7+
expect(emptyArray.length).toBe(__);
88

99
var multiTypeArray = [0, 1, "two", function () { return 3; }, {value1: 4, value2: 5}, [6, 7]];
10-
expect(__).toBe(multiTypeArray[0]);
11-
expect(__).toBe(multiTypeArray[2]);
12-
expect(__).toBe(multiTypeArray[3]());
13-
expect(__).toBe(multiTypeArray[4].value1);
14-
expect(__).toBe(multiTypeArray[4]["value2"]);
15-
expect(__).toBe(multiTypeArray[5][0]);
10+
expect(multiTypeArray[0]).toBe(__);
11+
expect(multiTypeArray[2]).toBe(__);
12+
expect(multiTypeArray[3]()).toBe(__);
13+
expect(multiTypeArray[4].value1).toBe(__);
14+
expect(multiTypeArray[4]["value2"]).toBe(__);
15+
expect(multiTypeArray[5][0]).toBe(__);
1616
});
1717

1818
it("should understand array literals", function () {
1919
var array = [];
20-
expect([]).toEqual(array);
20+
expect(array).toEqual([]);
2121

2222
array[0] = 1;
23-
expect([1]).toEqual(array);
23+
expect(array).toEqual([1]);
2424

2525
array[1] = 2;
26-
expect([1, __]).toEqual(array);
26+
expect(array).toEqual([1, __]);
2727

2828
array.push(3);
29-
expect(__).toEqual(array);
29+
expect(array).toEqual(__);
3030
});
3131

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

35-
expect(__).toBe(fourNumberArray.length);
35+
expect(fourNumberArray.length).toBe(__);
3636
fourNumberArray.push(5, 6);
37-
expect(__).toBe(fourNumberArray.length);
37+
expect(fourNumberArray.length).toBe(__);
3838

3939
var tenEmptyElementArray = new Array(10);
40-
expect(__).toBe(tenEmptyElementArray.length);
40+
expect(tenEmptyElementArray.length).toBe(__);
4141

4242
tenEmptyElementArray.length = 5;
43-
expect(__).toBe(tenEmptyElementArray.length);
43+
expect(tenEmptyElementArray.length).toBe(__);
4444
});
4545

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

49-
expect(__).toEqual(array.slice(0, 1));
50-
expect(__).toEqual(array.slice(0, 2));
51-
expect(__).toEqual(array.slice(2, 2));
52-
expect(__).toEqual(array.slice(2, 20));
53-
expect(__).toEqual(array.slice(3, 0));
54-
expect(__).toEqual(array.slice(3, 100));
55-
expect(__).toEqual(array.slice(5, 1));
49+
expect(array.slice(0, 1)).toEqual(__);
50+
expect(array.slice(0, 2)).toEqual(__);
51+
expect(array.slice(2, 2)).toEqual(__);
52+
expect(array.slice(2, 20)).toEqual(__);
53+
expect(array.slice(3, 0)).toEqual(__);
54+
expect(array.slice(3, 100)).toEqual(__);
55+
expect(array.slice(5, 1)).toEqual(__);
5656
});
5757

5858
it("should know array references", function () {
@@ -62,36 +62,36 @@ describe("About Arrays", function() {
6262
refArray[1] = "changed in function";
6363
}
6464
passedByReference(array);
65-
expect(__).toBe(array[1]);
65+
expect(array[1]).toBe(__);
6666

6767
var assignedArray = array;
6868
assignedArray[5] = "changed in assignedArray";
69-
expect(__).toBe(array[5]);
69+
expect(array[5]).toBe(__);
7070

7171
var copyOfArray = array.slice();
7272
copyOfArray[3] = "changed in copyOfArray";
73-
expect(__).toBe(array[3]);
73+
expect(array[3]).toBe(__);
7474
});
7575

7676
it("should push and pop", function () {
7777
var array = [1, 2];
7878
array.push(3);
7979

80-
expect(__).toEqual(array);
80+
expect(array).toEqual(__);
8181

8282
var poppedValue = array.pop();
83-
expect(__).toBe(poppedValue);
84-
expect(__).toEqual(array);
83+
expect(poppedValue).toBe(__);
84+
expect(array).toEqual(__);
8585
});
8686

8787
it("should shifting arrays", function () {
8888
var array = [1, 2];
8989

9090
array.unshift(3);
91-
expect(__).toEqual(array);
91+
expect(array).toEqual(__);
9292

9393
var shiftedValue = array.shift();
94-
expect(__).toEqual(shiftedValue);
95-
expect(__).toEqual(array);
94+
expect(shiftedValue).toEqual(__);
95+
expect(array).toEqual(__);
9696
});
9797
});

koans/AboutExpects.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

koans/AboutFunctions.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ describe("About Functions", function() {
66
return a + b;
77
}
88

9-
expect(__).toBe(add(1, 2));
10-
9+
expect(add(1, 2)).toBe(__);
1110
});
1211

1312
it("should know internal wariables override outer variables", function () {
@@ -22,9 +21,9 @@ describe("About Functions", function() {
2221
return message;
2322
}
2423

25-
expect(__).toBe(getMessage());
26-
expect(__).toBe(overrideMessage());
27-
expect(__).toBe(message);
24+
expect(getMessage()).toBe(__);
25+
expect(overrideMessage()).toBe(__);
26+
expect(message).toBe(__);
2827
});
2928

3029
it("should have lexical scoping", function () {
@@ -36,7 +35,7 @@ describe("About Functions", function() {
3635
}
3736
return childfunction();
3837
}
39-
expect(__).toBe(parentfunction());
38+
expect(parentfunction()).toBe(__);
4039
});
4140

4241
it("should use lexical scoping to synthesise functions", function () {
@@ -53,7 +52,7 @@ describe("About Functions", function() {
5352
var increaseBy3 = makeIncreaseByFunction(3);
5453
var increaseBy5 = makeIncreaseByFunction(5);
5554

56-
expect(__).toBe(increaseBy3(10) + increaseBy5(10));
55+
expect(increaseBy3(10) + increaseBy5(10)).toBe(__);
5756
});
5857

5958
it("should allow extra function arguments", function () {
@@ -63,14 +62,14 @@ describe("About Functions", function() {
6362
return firstArg;
6463
}
6564

66-
expect(__).toBe(returnFirstArg("first", "second", "third"));
65+
expect(returnFirstArg("first", "second", "third")).toBe(__);
6766

6867
function returnSecondArg(firstArg, secondArg)
6968
{
7069
return secondArg;
7170
}
7271

73-
expect(__).toBe(returnSecondArg("only give first arg"));
72+
expect(returnSecondArg("only give first arg")).toBe(__);
7473

7574
function returnAllArgs()
7675
{
@@ -81,7 +80,7 @@ describe("About Functions", function() {
8180
return argsArray.join(",");
8281
}
8382

84-
expect(__).toBe(returnAllArgs("first", "second", "third"));
83+
expect(returnAllArgs("first", "second", "third")).toBe(__);
8584
});
8685

8786
it("should pass functions as values", function () {
@@ -95,21 +94,21 @@ describe("About Functions", function() {
9594
};
9695

9796
var praiseSinger = { givePraise: appendRules };
98-
expect(__).toBe(praiseSinger.givePraise("John"));
97+
expect(praiseSinger.givePraise("John")).toBe(__);
9998

10099
praiseSinger.givePraise = appendDoubleRules;
101-
expect(__).toBe(praiseSinger.givePraise("Mary"));
100+
expect(praiseSinger.givePraise("Mary")).toBe(__);
102101

103102
});
104103

105104
it("should use function body as a string", function () {
106105
var add = new Function("a", "b", "return a + b;");
107-
expect(__).toBe(add(1, 2));
106+
expect(add(1, 2)).toBe(__);
108107

109108
var multiply = function (a, b) {
110109
//An internal comment
111110
return a * b;
112111
};
113-
expect(__).toBe(multiply.toString());
112+
expect(multiply.toString()).toBe(__);
114113
});
115114
});

koans/AboutHigherOrderFunctions.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ describe("About Higher Order Functions", function () {
77
var numbers = [1,2,3];
88
var odd = df.filter(numbers, "x % 2 !== 0");
99

10-
expect(__).toEqual(odd);
11-
expect(__).toBe(odd.length);
12-
expect(__).toBe(numbers.length);
10+
expect(odd).toEqual(__);
11+
expect(odd.length).toBe(__);
12+
expect(numbers.length).toBe(__);
1313
});
1414

1515
it("should use 'map' to transform each element", function () {
1616
var numbers = [1, 2, 3];
1717
var numbersPlus1 = df.map(numbers, "x + 1");
1818

19-
expect(__).toEqual(numbersPlus1);
20-
expect(__).toEqual(numbers);
19+
expect(numbersPlus1).toEqual(__);
20+
expect(numbers).toEqual(__);
2121
});
2222

2323
it("should use 'reduce' to update the same result on each iteration ", function () {
2424
var numbers = [1, 2, 3];
2525
var reduction = df.reduce(numbers, "result + x");
2626

27-
expect(__).toBe(reduction);
28-
expect(__).toEqual(numbers);
27+
expect(reduction).toBe(__);
28+
expect(numbers).toEqual(__);
2929
});
3030

3131
it("should use 'forEach' for simple iteration", function () {
@@ -37,8 +37,8 @@ describe("About Higher Order Functions", function () {
3737

3838
df.forEach(numbers, isEven);
3939

40-
expect(__).toEqual(msg);
41-
expect(__).toEqual(numbers);
40+
expect(msg).toEqual(__);
41+
expect(numbers).toEqual(__);
4242
});
4343

4444
it("should use 'some' to apply until true", function () {
@@ -50,7 +50,7 @@ describe("About Higher Order Functions", function () {
5050
};
5151

5252
expect(numbers.some(isEven)).toBeTruthy();
53-
expect(__).toEqual(msg);
53+
expect(msg).toEqual(__);
5454
});
5555

5656
it("should use 'every' to applies until first false" , function () {
@@ -62,7 +62,7 @@ describe("About Higher Order Functions", function () {
6262
};
6363

6464
expect(numbers.every(isEven)).toBeFalsy();
65-
expect(__).toBe(msg);
65+
expect(msg).toBe(__);
6666
});
6767
});
6868

0 commit comments

Comments
 (0)