forked from alex-aaron/function-master-copy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function-master.html
155 lines (136 loc) · 7.92 KB
/
function-master.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Function Master</title>
<style>.test-diff,.test-expected,.test-source,.test-actual{display: none}</style>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-1.19.0.css">
<script src="https://code.jquery.com/qunit/qunit-1.19.0.js"></script>
<meta name="description" content="Function Master: Learn to master the function">
</head>
<body>
<a href="index.html"><< Back to main lesson page</a>
<h1>Part 2 - Function Master</h1>
<div id="qunit"></div>
<script src="test-master.js"></script>
<script src="function-master.js"></script>
<script>
(function () {
// These are the tests for part 2.
// STUDENTS, DO NOT EDIT THIS!!!
// Do your work in function-master.js
/* global objectValues */
QUnit.test( "objectValues() : Should take an object and return its values in an array", function( assert ) {
var objectOne = {a: "one", b: "two", ponies: "crayons", dingle: "dangle"};
var objectTwo = {c: "three", d: "four", crayons: "ponies", dangle: "dingle"};
assert.deepEqual(objectValues(objectOne), ["one","two","crayons","dangle"]);
assert.deepEqual(objectValues(objectTwo), ["three","four","ponies","dingle"]);
});
/* global keysToString */
QUnit.test("keysToString() : Should take an object and return all its keys in a string each separated with a space", function(assert){
var objectOne = {a: "one", b: "two", ponies: "crayons", dingle: "dangle"};
var objectTwo = {c: "three", d: "four", crayons: "ponies", dangle: "dingle"};
assert.equal(keysToString(objectOne), "a b ponies dingle");
assert.equal(keysToString(objectTwo), "c d crayons dangle");
});
/* global valuesToString */
QUnit.test("valuesToString() : Should take an object and return all its string values in a string each separated with a space", function(assert){
var objectOne = {a: "one", b: "two", ponies: "crayons", something: {}, dingle: "dangle"};
var objectTwo = {c: "three", boolean: false, d: "four", crayons: "ponies", dangle: "dingle"};
assert.equal(valuesToString(objectOne), "one two crayons dangle");
assert.equal(valuesToString(objectTwo), "three four ponies dingle");
});
/* global arrayOrObject */
QUnit.test("arrayOrObject() : Should take one argument and return 'array' if its an array and 'object' if its an object", function(assert){
assert.equal(arrayOrObject({a:"one"}), "object");
assert.equal(arrayOrObject([1,2,{}]), "array");
});
/* global capitalizeWord*/
QUnit.test("capitalizeWord() : Should take a string of one word, and return the word with its first letter capitalized", function(assert){
assert.equal(capitalizeWord("greg"), "Greg");
assert.equal(capitalizeWord("pumpkin"), "Pumpkin");
assert.equal(capitalizeWord("quattuordecillion"), "Quattuordecillion");
});
/* global capitalizeAllWords*/
QUnit.test("capitalizeAllWords() : Should take a string of words and return a string with all the words capitalized ", function(assert){
assert.equal(capitalizeAllWords("one two three four"), "One Two Three Four");
assert.equal(capitalizeAllWords("please excuse my dear aunt sally"), "Please Excuse My Dear Aunt Sally");
});
/* global welcomeMessage*/
QUnit.test("welcomeMessage() : Should take an object with a name property and return 'Welcome <Name>!'", function(assert){
assert.equal(welcomeMessage({name: "bert"}), "Welcome Bert!");
assert.equal(welcomeMessage({name: "Charlie"}), "Welcome Charlie!");
});
/* global profileInfo*/
QUnit.test("profileInfo() : Should take an object with a name an a species and return '<Name> is a <Species>'", function(assert){
assert.equal(profileInfo({name: "jake", species: "dog"}), "Jake is a Dog");
assert.equal(profileInfo({name: "reggie", species: "dog"}), "Reggie is a Dog");
});
/* global maybeNoises*/
QUnit.test("maybeNoises() : Should take an object, if this object has a noises array return them as a string separated by a space, if there are no noises return 'there are no noises'", function(assert){
assert.equal(maybeNoises({noises:["bark", "woof", "squeak","growl"]}), "bark woof squeak growl");
assert.equal(maybeNoises({noises: []}), "there are no noises");
assert.equal(maybeNoises({}), "there are no noises");
});
/* global hasWord*/
QUnit.test("hasWord() : Should take a string of words and a word and return true if <word> is in <string of words>, otherwise return false.", function(assert){
var data = "This is a super awesome string of words";
assert.strictEqual(hasWord(data, "awesome"), true);
assert.strictEqual(hasWord(data, "words"), true);
assert.strictEqual(hasWord(data, "turtle"), false);
});
/* global addFriend */
QUnit.test("addFriend() : Should take a name and an object and add the name to the object's friends array then return the object", function(assert){
assert.deepEqual(addFriend("lester", {friends:[]}), {friends:["lester"]});
assert.deepEqual(addFriend("jimmy", {friends:["bobby","jones"]}), {friends:["bobby", "jones", "jimmy"]});
});
/* global isFriend */
QUnit.test("isFriend() : Should take a name and an object and return true if <name> is a friend of <object> and false otherwise", function(assert){
assert.equal(isFriend("jimmy",{friends:["bobby", "ralf"]}), false);
assert.equal(isFriend("ralf",{friends:["bobby", "ralf"]}), true);
assert.equal(isFriend("chuck",{}), false);
});
/* global nonFriends */
QUnit.test("nonFriends() : Should take a name and a list of people, and return a list of all the names that <name> is not friends with", function(assert){
var data = [
{name: "Jimmy", friends:["Sara", "Liza"]},
{name: "Bob", friends:[]},
{name: "Liza", friends: ["Jimmy"]},
{name: "Sara", friends: ["Jimmy"]}
];
assert.deepEqual(nonFriends("Jimmy", data), ["Bob"]);
assert.deepEqual(nonFriends("Bob", data), ["Jimmy", "Liza", "Sara"]);
assert.deepEqual(nonFriends("Sara", data), ["Bob","Liza"]);
});
/* global updateObject */
QUnit.test("updateObject() : Should take an object, a key and a value. Should update the property <key> on <object> with new <value>. If <key> does not exist on <object> create it.", function(assert){
var data = {a: "one", b: "two", "hokey": false};
assert.deepEqual(updateObject(data, "b", "three"), {a:"one", b:"three", hokey: false});
var data = {a: "one", b: "two", "hokey": false};
assert.deepEqual(updateObject(data, "ponies", "yes"), {a:"one", b:"two", hokey: false, ponies: "yes"});
var data = {a: "one", b: "two", "hokey": false};
assert.deepEqual(updateObject(data, "a", Infinity), {a:Infinity, b:"two", hokey: false});
});
/* global removeProperties */
QUnit.test("removeProperties() : Should take an object and an array of strings. Should remove any properties on <object> that are listed in <array>", function(assert){
var data = {a: "one", b: "two", "hokey": false};
removeProperties(data, ["a","hokey"]);
assert.deepEqual(data, {b: "two"});
var data = {a: "one", b: "two", "hokey": false};
removeProperties(data, ["b"])
assert.deepEqual(data, {a: "one", "hokey": false});
var data = {a: "one", b: "two", hokey: false};
removeProperties(data, []);
assert.deepEqual(data, {a: "one", b: "two", "hokey": false});
});
/* global dedup */
QUnit.test( "dedup() : Should take an array and return an array with all the duplicates removed", function( assert ) {
var arrayOne = [1,2,2,2,3,4,5,5,5,5,"a","b","b","b","c"];
var arrayTwo = ["hello", "hello", "hello", "hello", "hello", "world", "hello", "world", "world", "world"];
assert.deepEqual(dedup(arrayOne), [1,2,3,4,5,"a","b","c"]);
assert.deepEqual(dedup(arrayTwo), ["hello", "world"]);
});
})();
</script>
</body>
</html>