Skip to content

Commit bb12641

Browse files
Added wallaby and finished the exercise
1 parent edc6a4e commit bb12641

13 files changed

Lines changed: 183 additions & 71 deletions

support/koans.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11

22
var __ = "incomplete";
33

4+
var fakeQuery = function (selector) {
5+
function jquery(selector) {
6+
this.selector = selector;
7+
}
8+
9+
jquery.prototype.html = function () {
10+
return '';
11+
};
12+
13+
return jquery;
14+
};
15+
16+
console.log(fakeQuery())
17+
18+
var $ = $ || fakeQuery;
19+
420
// ignore this. It simplifies determining array equality
521
Array.prototype.equalTo = function(compareTo) {
622
if (this.length !== compareTo.length) {

support/tester.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
var __ = "incomplete";
2+
3+
// ignore this. It simplifies determining array equality
4+
Array.prototype.equalTo = function(compareTo) {
5+
if (this.length !== compareTo.length) {
6+
return false;
7+
}
8+
for(var i = 0; i < compareTo.length; i++) {
9+
if (this[i] !== compareTo[i]) {
10+
return false;
11+
}
12+
}
13+
return true;
14+
};
15+
16+
(function() {
17+
18+
var lastAssertLogReason, ignoreFurtherFailures = false;
19+
var zenMessages = [
20+
"The path to enlightenment has many stones",
21+
"Do not stray from your path, for enlightenment comes with perseverance",
22+
"The only Zen you find on tops of mountains is the Zen you bring there",
23+
"Enlightenment occurs when someone becomes inspired by information and uses it to enhance their life",
24+
"Be master of mind rather than mastered by mind",
25+
"Zen is not some kind of excitement, but concentration on our usual everyday routine",
26+
"I think self-awareness is probably the most important thing towards being a champion",
27+
"The reward of all action is to be found in enlightenment",
28+
"lasting enlightenment can be achieved only through persistent exercise of real love",
29+
"The real meaning of enlightenment is to gaze with undimmed eyes on all darkness",
30+
"Do not think you will necessarily be aware of your own enlightenment",
31+
"Enlightenment must come little by little - otherwise it would overwhelm",
32+
"The greatest gift is to give people your enlightenment, to share it. It has to be the greatest",
33+
"In the beginner's mind there are many possibilities, but in the expert's mind there are few",
34+
"Only the hand that erases can write the true thing",
35+
"Enlightenment is ego's ultimate disappointment",
36+
"Man suffers only because he takes seriously what the gods made for fun",
37+
"It is easy to believe we are each waves and forget we are also the ocean",
38+
"Working out is my biggest hobby. It's my Zen hour. I just zone out",
39+
"A self-motivation is an enlightenment of mind, empowerment of heart and enrichment of soul to arise, awake and ascend to achieve the noble and coveted goal even if it entails walking on its enervating path all alone"
40+
];
41+
42+
QUnit.config.reorder = false;
43+
44+
// QUnit.done(function(results) {
45+
// var failures = results.failed;
46+
// var total = results.total;
47+
// if (failures > 0) {
48+
// var failed = $('ol#qunit-tests > li.fail');
49+
// failed.hide();
50+
// $(failed[0]).show();
51+
// }
52+
// if (failures < total) {
53+
// $('h3.welcome_message').hide();
54+
// }
55+
// if (failures > 0) {
56+
// $("#zen-help").show();
57+
// }
58+
// $("body").scrollTop($(document).height());
59+
// });
60+
61+
QUnit.log(function(result) {
62+
lastAssertLogReason = result.message;
63+
});
64+
65+
// QUnit.testDone(function(result) {
66+
// var message;
67+
// if (!ignoreFurtherFailures && result.failed > 0) {
68+
// ignoreFurtherFailures = true;
69+
// message = "" + randomZenMessage() + "\nTry meditating on this: " + result.module + ": " + result.name + " (" + lastAssertLogReason + ")";
70+
// $("#zen-help").html(message.replace(/\n/g, "<br /><br />"));
71+
// console.log(message);
72+
// }
73+
// });
74+
75+
function randomZenMessage() {
76+
var randomIndex = Math.floor(Math.random() * zenMessages.length);
77+
var zenMessage = zenMessages[randomIndex];
78+
zenMessage = zenMessage.charAt(0).toUpperCase() + zenMessage.substr(1);
79+
return "" + zenMessage + ".";
80+
}
81+
82+
})();

topics/about_functions_and_closure.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ test("defining functions directly", function() {
77
result = "b";
88
};
99
changeResult();
10-
equal(__, result, 'what is the value of result?');
10+
equal('b', result, 'what is the value of result?');
1111
});
1212

1313
test("assigning functions to variables", function() {
1414
var triple = function(input) {
1515
return input * 3;
1616
};
17-
equal(__, triple(4), 'what is triple 4?');
17+
equal(12, triple(4), 'what is triple 4?');
1818
});
1919

2020
test("self invoking functions", function() {
@@ -23,23 +23,23 @@ test("self invoking functions", function() {
2323
// self invoking functions are used to provide scoping and to alias variables
2424
(function(pv) {
2525
var secretValue = "password";
26-
equal(__, pv, 'what is the value of pv?');
27-
equal("__", typeof(secretValue), "is secretValue available in this context?");
28-
equal("__", typeof(publicValue), "is publicValue available in this context?");
26+
equal("shared", pv, 'what is the value of pv?');
27+
equal("string", typeof(secretValue), "is secretValue available in this context?");
28+
equal("string", typeof(publicValue), "is publicValue available in this context?");
2929
})(publicValue);
3030

31-
equal("__", typeof(secretValue), "is secretValue available in this context?");
32-
equal("__", typeof(publicValue), "is publicValue available in this context?");
31+
equal("undefined", typeof(secretValue), "is secretValue available in this context?");
32+
equal("string", typeof(publicValue), "is publicValue available in this context?");
3333
});
3434

3535
test("arguments array", function() {
3636
var add = function() {
3737
var total = 0;
3838
for(var i = 0; i < arguments.length; i++) {
3939
// complete the implementation of this method so that it returns the sum of its arguments
40-
// __
40+
total = total + arguments[i];
4141
}
42-
// __
42+
return total;
4343
};
4444

4545
equal(15, add(1,2,3,4,5), "add 1,2,3,4,5");
@@ -57,7 +57,7 @@ test("using call to invoke function",function(){
5757
//function, and the arguments to be sent to the function,multiple arguments are separated by commas.
5858
var result = invokee.call("I am this!", "Where did it come from?");
5959

60-
equal(__, result, "what will the value of invokee's this be?");
60+
equal("I am this!Where did it come from?", result, "what will the value of invokee's this be?");
6161
});
6262

6363
test("using apply to invoke function",function(){
@@ -70,6 +70,6 @@ test("using apply to invoke function",function(){
7070
//function and the second is the array of arguments to be passed into the called function.
7171
var result = invokee.apply("I am this!", ["I am arg1","I am arg2"]);
7272

73-
equal(__, result, "what will the value of invokee's this be?");
73+
equal("I am this!I am arg1I am arg2", result, "what will the value of invokee's this be?");
7474
});
7575

topics/about_numbers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module("About Numbers (topics/about_numbers.js)");
44
test("types", function() {
55
var typeOfIntegers = typeof(6);
66
var typeOfFloats = typeof(3.14159);
7-
equal(__, typeOfIntegers === typeOfFloats, 'are ints and floats the same type?');
8-
equal(__, typeOfIntegers, 'what is the javascript numeric type?');
9-
equal(__, 1.0, 'what is a integer number equivalent to 1.0?');
7+
equal(true, typeOfIntegers === typeOfFloats, 'are ints and floats the same type?');
8+
equal("number", typeOfIntegers, 'what is the javascript numeric type?');
9+
equal(1, 1.0, 'what is a integer number equivalent to 1.0?');
1010
});
1111

1212
test("NaN", function() {
1313
var resultOfFailedOperations = 7/'apple';
14-
equal(__, isNaN(resultOfFailedOperations), 'what will satisfy the equals assertion?');
15-
equal(__, resultOfFailedOperations == NaN, 'is NaN == NaN?');
14+
equal(true, isNaN(resultOfFailedOperations), 'what will satisfy the equals assertion?');
15+
equal(false, resultOfFailedOperations == NaN, 'is NaN == NaN?');
1616
});

topics/about_objects.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ module("About Objects (topics/about_objects.js)");
33

44
test("object type", function() {
55
var empty_object = {};
6-
equal(__, typeof(empty_object), 'what is the type of an object?');
6+
equal("object", typeof(empty_object), 'what is the type of an object?');
77
});
88

99
test("object literal notation", function() {
1010
var person = {
11-
__:__,
12-
__:__
11+
"name":"Amory Blaine",
12+
"age":102
1313
};
1414
equal("Amory Blaine", person.name, "what is the person's name?");
1515
equal(102, person.age, "what is the person's age?");
1616
});
1717

1818
test("dynamically adding properties", function() {
1919
var person = {};
20-
person.__ = "Amory Blaine";
21-
person.__ = 102;
20+
person.name = "Amory Blaine";
21+
person.age = 102;
2222
equal("Amory Blaine", person.name, "what is the person's name?");
2323
equal(102, person.age, "what is the person's age?");
2424
});
2525

2626
test("adding properties from strings", function() {
2727
var person = {};
28-
person["__"] = "Amory Blaine";
29-
person["__"] = 102;
28+
person["name"] = "Amory Blaine";
29+
person["age"] = 102;
3030
equal("Amory Blaine", person.name, "what is the person's name?");
3131
equal(102, person.age, "what is the person's age?");
3232
});
@@ -36,7 +36,7 @@ test("adding functions", function() {
3636
name: "Amory Blaine",
3737
age: 102,
3838
toString: function() {
39-
return __; // HINT: use the 'this' keyword to refer to the person object.
39+
return "I "+ this.name +" am "+ this.age +" years old."; // HINT: use the 'this' keyword to refer to the person object.
4040
}
4141
};
4242
equal("I Amory Blaine am 102 years old.", person.toString(), "what should the toString function be?");

topics/about_prototypal_inheritance.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Mammal.prototype = {
1616

1717
test("defining a 'class'", function() {
1818
var eric = new Mammal("Eric");
19-
equal(__, eric.sayHi(), 'what will Eric say?');
19+
equal('Hello, my name is Eric', eric.sayHi(), 'what will Eric say?');
2020
});
2121

2222
// add another function to the Mammal 'type' that uses the sayHi function
@@ -26,7 +26,7 @@ Mammal.prototype.favouriteSaying = function() {
2626

2727
test("more functions", function() {
2828
var bobby = new Mammal("Bobby");
29-
equal(__, bobby.favouriteSaying(), "what is Bobby's favourite saying?");
29+
equal("Bobby's favourite saying is Hello, my name is Bobby", bobby.favouriteSaying(), "what is Bobby's favourite saying?");
3030
});
3131

3232
test("calling functions added to a prototype after an object was created", function() {
@@ -36,7 +36,7 @@ test("calling functions added to a prototype after an object was created", funct
3636
};
3737
// the following statement asks the paul object to call a function that was added
3838
// to the Mammal prototype after paul was constructed.
39-
equal(__, paul.numberOfLettersInName(), "how long is Paul's name?");
39+
equal("4", paul.numberOfLettersInName(), "how long is Paul's name?");
4040
});
4141

4242
// helper function for inheritance.
@@ -56,6 +56,6 @@ extend(Bat, Mammal);
5656

5757
test("Inheritance", function() {
5858
var lenny = new Bat("Lenny", "1.5m");
59-
equal(__, lenny.sayHi(), "what does Lenny say?");
60-
equal(__, lenny.wingspan, "what is Lenny's wingspan?");
59+
equal("Hello, my name is Lenny", lenny.sayHi(), "what does Lenny say?");
60+
equal("1.5m", lenny.wingspan, "what is Lenny's wingspan?");
6161
});

topics/about_prototype_chain.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,37 @@ child.b = 2;
2727
* */
2828

2929
test("Is there an 'a' and 'b' own property on child?", function () {
30-
equal(__, child.hasOwnProperty('a'), 'child.hasOwnProperty(\'a\')?');
31-
equal(__, child.hasOwnProperty('b'), 'child.hasOwnProperty(\'b\')?');
30+
equal(true, child.hasOwnProperty('a'), 'child.hasOwnProperty(\'a\')?');
31+
equal(true, child.hasOwnProperty('b'), 'child.hasOwnProperty(\'b\')?');
3232
});
3333

3434
test("Is there an 'a' and 'b' property on child?", function () {
35-
equal(__, child.a, 'what is \'a\' value?');
36-
equal(__, child.b, 'what is \'b\' value?');
35+
equal(1, child.a, 'what is \'a\' value?');
36+
equal(2, child.b, 'what is \'b\' value?');
3737
});
3838

3939
test("If 'b' was removed, whats b value?", function () {
4040
delete child.b;
41-
equal(__, child.b, 'what is \'b\' value now?');
41+
equal(3, child.b, 'what is \'b\' value now?');
4242
});
4343

4444

4545
test("Is there a 'c' own property on child?", function () {
46-
equal(__, child.hasOwnProperty('c'), 'child.hasOwnProperty(\'c\')?');
46+
equal(false, child.hasOwnProperty('c'), 'child.hasOwnProperty(\'c\')?');
4747
});
4848

4949
// Is there a 'c' own property on child? No, check its prototype
5050
// Is there a 'c' own property on child.[[Prototype]]? Yes, its value is...
5151
test("Is there a 'c' property on child?", function () {
52-
equal(__, child.c, 'what is the value of child.c?');
52+
equal(4, child.c, 'what is the value of child.c?');
5353
});
5454

5555

5656
// Is there a 'd' own property on child? No, check its prototype
5757
// Is there a 'd' own property on child.[[Prototype]]? No, check it prototype
5858
// child.[[Prototype]].[[Prototype]] is null, stop searching, no property found, return...
5959
test("Is there an 'd' property on child?", function () {
60-
equal(__, child.d, 'what is the value of child.d?');
60+
equal(undefined, child.d, 'what is the value of child.d?');
6161
});
6262

6363

topics/about_reflection.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ function B() {
1111
B.prototype = new A();
1212

1313
test("typeof", function() {
14-
equal(__, typeof({}), 'what is the type of an empty object?');
15-
equal(__, typeof('apple'), 'what is the type of a string?');
16-
equal(__, typeof(-5), 'what is the type of -5?');
17-
equal(__, typeof(false), 'what is the type of false?');
14+
equal('object', typeof({}), 'what is the type of an empty object?');
15+
equal('string', typeof('apple'), 'what is the type of a string?');
16+
equal('number', typeof(-5), 'what is the type of -5?');
17+
equal('boolean', typeof(false), 'what is the type of false?');
1818
});
1919

2020
test("property enumeration", function() {
@@ -25,8 +25,8 @@ test("property enumeration", function() {
2525
keys.push(propertyName);
2626
values.push(person[propertyName]);
2727
}
28-
ok(keys.equalTo(['__','__','__']), 'what are the property names of the object?');
29-
ok(values.equalTo(['__',__,__]), 'what are the property values of the object?');
28+
ok(keys.equalTo(['name','age','unemployed']), 'what are the property names of the object?');
29+
ok(values.equalTo(['Amory Blaine',102,true]), 'what are the property values of the object?');
3030
});
3131

3232
test("hasOwnProperty", function() {
@@ -37,8 +37,8 @@ test("hasOwnProperty", function() {
3737
for (propertyName in b) {
3838
keys.push(propertyName);
3939
}
40-
equal(__, keys.length, 'how many elements are in the keys array?');
41-
deepEqual([__, __], keys, 'what are the properties of the array?');
40+
equal(2, keys.length, 'how many elements are in the keys array?');
41+
deepEqual(['bprop', 'aprop'], keys, 'what are the properties of the array?');
4242

4343
// hasOwnProperty returns true if the parameter is a property directly on the object,
4444
// but not if it is a property accessible via the prototype chain.
@@ -48,21 +48,21 @@ test("hasOwnProperty", function() {
4848
ownKeys.push(propertyName);
4949
}
5050
}
51-
equal(__, ownKeys.length, 'how many elements are in the ownKeys array?');
52-
deepEqual([__], ownKeys, 'what are the own properties of the array?');
51+
equal(1, ownKeys.length, 'how many elements are in the ownKeys array?');
52+
deepEqual(['bprop'], ownKeys, 'what are the own properties of the array?');
5353
});
5454

5555
test("constructor property", function () {
5656
var a = new A();
5757
var b = new B();
58-
equal(__, typeof(a.constructor), "what is the type of a's constructor?");
59-
equal(__, a.constructor.name, "what is the name of a's constructor?");
60-
equal(__, b.constructor.name, "what is the name of b's constructor?");
58+
equal('function', typeof(a.constructor), "what is the type of a's constructor?");
59+
equal('A', a.constructor.name, "what is the name of a's constructor?");
60+
equal('A', b.constructor.name, "what is the name of b's constructor?");
6161
});
6262

6363
test("eval", function() {
6464
// eval executes a string
6565
var result = "";
6666
eval("result = 'apple' + ' ' + 'pie'");
67-
equal(__, result, 'what is the value of result?');
67+
equal("apple pie", result, 'what is the value of result?');
6868
});

0 commit comments

Comments
 (0)