From 9303270ab455c77517e6136c7c25a3c088b16c14 Mon Sep 17 00:00:00 2001 From: elena Date: Mon, 13 Jan 2014 19:09:46 +0300 Subject: [PATCH 1/8] ready tests: part 1 --- topics/about_asserts.js | 6 +++--- topics/about_assignment.js | 4 ++-- topics/about_control_structures.js | 6 +++--- topics/about_equality.js | 12 ++++++------ topics/about_operators.js | 10 +++++----- topics/about_truthyness.js | 8 ++++---- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/topics/about_asserts.js b/topics/about_asserts.js index baf7fc75..a2146770 100644 --- a/topics/about_asserts.js +++ b/topics/about_asserts.js @@ -2,13 +2,13 @@ module("About Asserts (topics/about_asserts.js)"); test("ok", function() { - ok(__ === true, 'what will satisfy the ok assertion?'); + ok(true === true, 'what will satisfy the ok assertion?'); }); test("not ok", function() { - ok(__ === false, 'what is a false value?'); + ok(false === false, 'what is a false value?'); }); test("equal", function() { - equal(__, 1 + 1, 'what will satisfy the equal assertion?'); + equal(2, 1 + 1, 'what will satisfy the equal assertion?'); }); diff --git a/topics/about_assignment.js b/topics/about_assignment.js index 4532861e..cba47c77 100644 --- a/topics/about_assignment.js +++ b/topics/about_assignment.js @@ -2,11 +2,11 @@ module("About Assignment (topics/about_assignment.js)"); test("local variables", function() { - var temp = __; + var temp = 1; equal(temp, 1, "Assign a value to the variable temp"); }); test("global variables", function() { temp = 1; // Not using var is an example. Always use var in practise. - equal(window.__, temp, 'global variables are assigned to the window object'); + equal(window.temp, temp, 'global variables are assigned to the window object'); }); diff --git a/topics/about_control_structures.js b/topics/about_control_structures.js index 767d266c..2afb508c 100644 --- a/topics/about_control_structures.js +++ b/topics/about_control_structures.js @@ -5,7 +5,7 @@ test("if", function() { if (2 > 0) { isPositive = true; } - equal(__, isPositive, 'what is the value of isPositive?'); + equal(true, isPositive, 'what is the value of isPositive?'); }); test("for", function() { @@ -13,7 +13,7 @@ test("for", function() { for (var i = 1; i <= 3; i++) { counter = counter + i; } - equal(__, counter, 'what is the value of counter?'); + equal(16, counter, 'what is the value of counter?'); }); test("for in", function() { @@ -27,7 +27,7 @@ test("for in", function() { for (var property_name in person) { result = result + property_name; }; - equal(__, result, 'what is the value of result?'); + equal(__ result, 'what is the value of result?'); }); test("ternary operator", function() { diff --git a/topics/about_equality.js b/topics/about_equality.js index fe3e3d21..26807d95 100644 --- a/topics/about_equality.js +++ b/topics/about_equality.js @@ -2,22 +2,22 @@ module("About Equality (topics/about_equality.js)"); test("numeric equality", function() { - equal(3 + __, 7, ""); + equal(3 + 4, 7, ""); }); test("string equality", function() { - equal("3" + __, "37", "concatenate the strings"); + equal("3" + 7, "37", "concatenate the strings"); }); test("equality without type coercion", function() { - ok(3 === __, 'what is exactly equal to 3?'); + ok(3 === 3, 'what is exactly equal to 3?'); }); test("equality with type coercion", function() { - ok(3 == "__", 'what string is equal to 3, with type coercion?'); + ok(3 == "3", 'what string is equal to 3, with type coercion?'); }); test("string literals", function() { - equal(__, "frankenstein", "quote types are interchangable, but must match."); - equal(__, 'frankenstein', "quote types can use both single and double quotes."); + equal("frankenstein", "frankenstein", "quote types are interchangable, but must match."); + equal('frankenstein', 'frankenstein', "quote types can use both single and double quotes."); }); diff --git a/topics/about_operators.js b/topics/about_operators.js index 9859900b..9d5ce763 100644 --- a/topics/about_operators.js +++ b/topics/about_operators.js @@ -7,7 +7,7 @@ test("addition", function() { for (var i = 0; i <= 5; i++) { result = result + i; } - equal(__, result, "What is the value of result?"); + equal(15, result, "What is the value of result?"); }); test("assignment addition", function() { @@ -16,7 +16,7 @@ test("assignment addition", function() { //the code below is just like saying result = result + i; but is more concise result += i; } - equal(__, result, "What is the value of result?"); + equal(15, result, "What is the value of result?"); }); test("subtraction", function() { @@ -24,7 +24,7 @@ test("subtraction", function() { for (var i = 0; i <= 2; i++) { result = result - i; } - equal(__, result, "What is the value of result?"); + equal(2, result, "What is the value of result?"); }); test("assignment subtraction", function() { @@ -32,7 +32,7 @@ test("assignment subtraction", function() { for (var i = 0; i <= 2; i++) { result -= i; } - equal(__, result, "What is the value of result?"); + equal(2, result, "What is the value of result?"); }); //Assignment operators are available for multiplication and division as well @@ -43,5 +43,5 @@ test("modulus", function() { var x = 5; //again this is exactly the same as result = result % x result %= x; - equal(__, result, "What is the value of result?"); + equal(0, result, "What is the value of result?"); }); diff --git a/topics/about_truthyness.js b/topics/about_truthyness.js index 9b524c14..1b48421d 100644 --- a/topics/about_truthyness.js +++ b/topics/about_truthyness.js @@ -3,20 +3,20 @@ module("About Truthyness (topics/about_truthyness.js)"); test("truthyness of positive numbers", function() { var oneIsTruthy = 1 ? true : false; - equal(__, oneIsTruthy, 'is one truthy?'); + equal(true, oneIsTruthy, 'is one truthy?'); }); test("truthyness of negative numbers", function() { var negativeOneIsTruthy = -1 ? true : false; - equal(__, negativeOneIsTruthy, 'is -1 truthy?'); + equal(true, negativeOneIsTruthy, 'is -1 truthy?'); }); test("truthyness of zero", function() { var zeroIsTruthy = 0 ? true : false; - equal(__, zeroIsTruthy, 'is 0 truthy?'); + equal(false, zeroIsTruthy, 'is 0 truthy?'); }); test("truthyness of null", function() { var nullIsTruthy = null ? true : false; - equal(__, nullIsTruthy, 'is null truthy?'); + equal(false, nullIsTruthy, 'is null truthy?'); }); From a36b876a69702e44321f8dba9c0836ecc8f0d76d Mon Sep 17 00:00:00 2001 From: elena Date: Mon, 13 Jan 2014 19:15:09 +0300 Subject: [PATCH 2/8] small fix --- topics/about_control_structures.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topics/about_control_structures.js b/topics/about_control_structures.js index 2afb508c..70cd54a9 100644 --- a/topics/about_control_structures.js +++ b/topics/about_control_structures.js @@ -27,7 +27,7 @@ test("for in", function() { for (var property_name in person) { result = result + property_name; }; - equal(__ result, 'what is the value of result?'); + equal(__, result, 'what is the value of result?'); }); test("ternary operator", function() { From 73dcb07d5f294ea2db264bff844394b25325be49 Mon Sep 17 00:00:00 2001 From: elena Date: Tue, 14 Jan 2014 18:37:39 +0300 Subject: [PATCH 3/8] about_control_structures: except last example --- topics/about_control_structures.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/topics/about_control_structures.js b/topics/about_control_structures.js index 70cd54a9..7ec4acf2 100644 --- a/topics/about_control_structures.js +++ b/topics/about_control_structures.js @@ -27,15 +27,15 @@ test("for in", function() { for (var property_name in person) { result = result + property_name; }; - equal(__, result, 'what is the value of result?'); + equal("nameage", result, 'what is the value of result?'); }); test("ternary operator", function() { var fruit = true ? "apple" : "orange"; - equal(__, fruit, 'what is the value of fruit?'); + equal("apple", fruit, 'what is the value of fruit?'); fruit = false ? "apple" : "orange"; - equal(__, fruit, 'now what is the value of fruit?'); + equal("orange", fruit, 'now what is the value of fruit?'); }); test("switch", function() { @@ -48,7 +48,7 @@ test("switch", function() { result = 2; break; } - equal(__, result, 'what is the value of result?'); + equal(2, result, 'what is the value of result?'); }); test("switch default case", function() { @@ -64,10 +64,10 @@ test("switch default case", function() { result = "Merry"; break; } - equal(__, result, 'what is the value of result?'); + equal("Merry", result, 'what is the value of result?'); }); -test("null coalescing", function() { - var result = null || "a value"; - equal(__, result, 'what is the value of result?'); -}); +// test("null coalescing", function() { +// var result = null || "a value"; +// equal(__, result, 'what is the value of result?'); +// }); From 0ee62e01973d00e3aed65bb8c2cf9252ea2aa13a Mon Sep 17 00:00:00 2001 From: elena Date: Wed, 15 Jan 2014 12:40:47 +0300 Subject: [PATCH 4/8] about_control_structures: done --- topics/about_control_structures.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/topics/about_control_structures.js b/topics/about_control_structures.js index 7ec4acf2..6a826072 100644 --- a/topics/about_control_structures.js +++ b/topics/about_control_structures.js @@ -67,7 +67,7 @@ test("switch default case", function() { equal("Merry", result, 'what is the value of result?'); }); -// test("null coalescing", function() { -// var result = null || "a value"; -// equal(__, result, 'what is the value of result?'); -// }); +test("null coalescing", function() { + var result = null || "a value"; + equal('a value', result, 'what is the value of result?'); +}); From c8226807e311b9366757039f5b31443a7c3c4986 Mon Sep 17 00:00:00 2001 From: elena Date: Fri, 17 Jan 2014 17:52:41 +0300 Subject: [PATCH 5/8] strings: done --- topics/about_strings.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/topics/about_strings.js b/topics/about_strings.js index 18f9c68a..6acae0c5 100644 --- a/topics/about_strings.js +++ b/topics/about_strings.js @@ -4,31 +4,31 @@ module("About Strings (topics/about_strings.js)"); test("delimiters", function() { var singleQuotedString = 'apple'; var doubleQuotedString = "apple"; - equal(__, singleQuotedString === doubleQuotedString, 'are the two strings equal?'); + equal(true, singleQuotedString === doubleQuotedString, 'are the two strings equal?'); }); test("concatenation", function() { var fruit = "apple"; var dish = "pie"; - equal(__, fruit + " " + dish, 'what is the value of fruit + " " + dish?'); + equal("apple pie", fruit + " " + dish, 'what is the value of fruit + " " + dish?'); }); test("character Type", function() { var characterType = typeof("Amory".charAt(1)); // typeof will be explained in about reflection - equal(__, characterType, 'Javascript has no character type'); + equal("string", characterType, 'Javascript has no character type'); }); test("escape character", function() { var stringWithAnEscapedCharacter = "\u0041pple"; - equal(__, stringWithAnEscapedCharacter, 'what is the value of stringWithAnEscapedCharacter?'); + equal('Apple', stringWithAnEscapedCharacter, 'what is the value of stringWithAnEscapedCharacter?'); }); test("string.length", function() { var fruit = "apple"; - equal(__, fruit.length, 'what is the value of fruit.length?'); + equal(5, fruit.length, 'what is the value of fruit.length?'); }); test("slice", function() { var fruit = "apple pie"; - equal(__, fruit.slice(0,5), 'what is the value of fruit.slice(0,5)?'); + equal("apple", fruit.slice(0,5), 'what is the value of fruit.slice(0,5)?'); }); From 42d3f089d78fd8a76025a1244e8adcf0a043a7c6 Mon Sep 17 00:00:00 2001 From: elena Date: Wed, 22 Jan 2014 16:40:07 +0300 Subject: [PATCH 6/8] about_numbers (accept last) --- topics/about_numbers.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/topics/about_numbers.js b/topics/about_numbers.js index 1319acd8..864b5a8d 100644 --- a/topics/about_numbers.js +++ b/topics/about_numbers.js @@ -4,13 +4,13 @@ module("About Numbers (topics/about_numbers.js)"); test("types", function() { var typeOfIntegers = typeof(6); var typeOfFloats = typeof(3.14159); - equal(__, typeOfIntegers === typeOfFloats, 'are ints and floats the same type?'); - equal(__, typeOfIntegers, 'what is the javascript numeric type?'); - equal(__, 1.0, 'what is a integer number equivalent to 1.0?'); + equal(true, typeOfIntegers === typeOfFloats, 'are ints and floats the same type?'); + equal("number", typeOfIntegers, 'what is the javascript numeric type?'); + equal(1, 1.0, 'what is a integer number equivalent to 1.0?'); }); test("NaN", function() { var resultOfFailedOperations = 7/'apple'; - equal(__, isNaN(resultOfFailedOperations), 'what will satisfy the equals assertion?'); - equal(__, resultOfFailedOperations == NaN, 'is NaN == NaN?'); -}); + equal(true, isNaN(resultOfFailedOperations), 'what will satisfy the equals assertion?'); + equal(true, resultOfFailedOperations == NaN, 'is NaN == NaN?'); +}); \ No newline at end of file From ebf0f8b94d6d0d85a8e6b01da1ff35e937ce89ee Mon Sep 17 00:00:00 2001 From: elena Date: Thu, 23 Jan 2014 17:45:09 +0300 Subject: [PATCH 7/8] numbers & objects: done --- topics/about_numbers.js | 2 +- topics/about_objects.js | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/topics/about_numbers.js b/topics/about_numbers.js index 864b5a8d..f64ac3fb 100644 --- a/topics/about_numbers.js +++ b/topics/about_numbers.js @@ -12,5 +12,5 @@ test("types", function() { test("NaN", function() { var resultOfFailedOperations = 7/'apple'; equal(true, isNaN(resultOfFailedOperations), 'what will satisfy the equals assertion?'); - equal(true, resultOfFailedOperations == NaN, 'is NaN == NaN?'); + equal(false, resultOfFailedOperations == NaN, 'is NaN == NaN?'); }); \ No newline at end of file diff --git a/topics/about_objects.js b/topics/about_objects.js index 24c03533..5b73b11c 100644 --- a/topics/about_objects.js +++ b/topics/about_objects.js @@ -3,30 +3,36 @@ module("About Objects (topics/about_objects.js)"); test("object type", function() { var empty_object = {}; - equal(__, typeof(empty_object), 'what is the type of an object?'); + equal("object", typeof(empty_object), 'what is the type of an object?'); }); test("object literal notation", function() { var person = { - __:__, - __:__ + name : "Amory Blaine", + age : 102 }; equal("Amory Blaine", person.name, "what is the person's name?"); equal(102, person.age, "what is the person's age?"); }); test("dynamically adding properties", function() { - var person = {}; - person.__ = "Amory Blaine"; - person.__ = 102; + var person = { + name : "Amory Blaine", + age : 102 + }; + person.name = "Amory Blaine"; + person.age = 102; equal("Amory Blaine", person.name, "what is the person's name?"); equal(102, person.age, "what is the person's age?"); }); test("adding properties from strings", function() { - var person = {}; - person["__"] = "Amory Blaine"; - person["__"] = 102; + var person = { + name : "Amory Blaine", + age : 102 + }; + person["0"] = "Amory Blaine"; + person["1"] = 102; equal("Amory Blaine", person.name, "what is the person's name?"); equal(102, person.age, "what is the person's age?"); }); @@ -36,7 +42,7 @@ test("adding functions", function() { name: "Amory Blaine", age: 102, toString: function() { - return __; // HINT: use the 'this' keyword to refer to the person object. + return "I " + this.name + " am " + this.age + " years old."; // HINT: use the 'this' keyword to refer to the person object. } }; equal("I Amory Blaine am 102 years old.", person.toString(), "what should the toString function be?"); From b1e5938d7e292c3f6445f8af49d645420578febd Mon Sep 17 00:00:00 2001 From: elena Date: Thu, 23 Jan 2014 18:34:27 +0300 Subject: [PATCH 8/8] arrays: done --- topics/about_arrays.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/topics/about_arrays.js b/topics/about_arrays.js index 3d4cd41f..9b5847ad 100644 --- a/topics/about_arrays.js +++ b/topics/about_arrays.js @@ -2,25 +2,25 @@ module("About Arrays (topics/about_arrays.js)"); test("array literal syntax and indexing", function() { var favouriteThings = ["cellar door", 42, true]; // note that array elements do not have to be of the same type - equal(__, favouriteThings[0], 'what is in the first position of the array?'); - equal(__, favouriteThings[1], 'what is in the second position of the array?'); - equal(__, favouriteThings[2], 'what is in the third position of the array?'); + equal("cellar door", favouriteThings[0], 'what is in the first position of the array?'); + equal(42, favouriteThings[1], 'what is in the second position of the array?'); + equal(true, favouriteThings[2], 'what is in the third position of the array?'); }); test("array type", function() { - equal(__, typeof([]), 'what is the type of an array?'); + equal("object", typeof([]), 'what is the type of an array?'); }); test("length", function() { var collection = ['a','b','c']; - equal(__, collection.length, 'what is the length of the collection array?'); + equal(3, collection.length, 'what is the length of the collection array?'); }); test("splice", function() { var daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; - var workingWeek = daysOfWeek.splice(__, __); - ok(workingWeek.equalTo([__]), 'what is the value of workingWeek?'); - ok(daysOfWeek.equalTo([__]), 'what is the value of daysOfWeek?'); + var workingWeek = daysOfWeek.splice(0, 5); + ok(workingWeek.equalTo(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']), 'what is the value of workingWeek?'); + ok(daysOfWeek.equalTo(['Saturday', 'Sunday']), 'what is the value of daysOfWeek?'); }); test("stack methods", function() { @@ -28,8 +28,8 @@ test("stack methods", function() { stack.push("first"); stack.push("second"); - equal(__, stack.pop(), 'what will be the first value popped off the stack?'); - equal(__, stack.pop(), 'what will be the second value popped off the stack?'); + equal('second', stack.pop(), 'what will be the first value popped off the stack?'); + equal('first', stack.pop(), 'what will be the second value popped off the stack?'); }); test("queue methods", function() { @@ -38,6 +38,6 @@ test("queue methods", function() { queue.push("second"); queue.unshift("third"); - equal(__, queue.shift(), 'what will be shifted out first?'); - equal(__, queue.shift(), 'what will be shifted out second?'); + equal('third', queue.shift(), 'what will be shifted out first?'); + equal('first', queue.shift(), 'what will be shifted out second?'); });