Skip to content

Commit 3e235c6

Browse files
committed
Revert "made up tests and then created functions to pass the required tests in implement folder"
This reverts commit b63c6de.
1 parent 6c486d4 commit 3e235c6

File tree

8 files changed

+12
-185
lines changed

8 files changed

+12
-185
lines changed

Sprint-2/implement/contains.js

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
1-
function contains(checkObj, checkProp) {
2-
if (
3-
typeof checkObj === "object" &&
4-
checkObj !== null &&
5-
!Array.isArray(checkObj)
6-
) {
7-
const checkKeys = Object.keys(checkObj);
8-
let isProperty = false;
9-
10-
if (checkKeys.length === 0) {
11-
return false;
12-
}
13-
14-
if (Object.hasOwn(checkObj, checkProp)) {
15-
return true;
16-
} else {
17-
for (let key of checkKeys) {
18-
if (key === checkProp) {
19-
isProperty = true;
20-
}
21-
}
22-
23-
if (isProperty === false) {
24-
return false;
25-
}
26-
}
27-
} else {
28-
throw new Error("error invalid parameter please provide an object");
29-
}
30-
}
31-
32-
contains({ d: "me" }, 4);
1+
function contains() {}
332

343
module.exports = contains;

Sprint-2/implement/contains.test.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,16 @@ as the object doesn't contains a key of 'c'
2020
// Given an empty object
2121
// When passed to contains
2222
// Then it should return false
23-
test("contains on empty object returns false", () =>
24-
expect(contains({}, "a")).toBe(false));
23+
test.todo("contains on empty object returns false");
2524

2625
// Given an object with properties
2726
// When passed to contains with an existing property name
2827
// Then it should return true
29-
test("returns true when an object contains a property that matches the one passed to contains", () =>
30-
expect(contains({ area: "Manchester" }, "area")).toBe(true));
3128

3229
// Given an object with properties
3330
// When passed to contains with a non-existent property name
3431
// Then it should return false
35-
test("returns false when an object with properties is passed to contains with a non-existent property name", () =>
36-
expect(contains({ area: "Manchester" }, "town")).toBe(false));
3732

3833
// Given invalid parameters like an array
3934
// When passed to contains
4035
// Then it should return false or throw an error
41-
test("should throw an error when when an invalid parameter like an array is passed to contains", () =>
42-
expect(() => contains([1, 4], 4)).toThrow(
43-
"error invalid parameter please provide an object"
44-
));

Sprint-2/implement/lookup.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
function createLookup(inputArray) {
1+
function createLookup() {
22
// implementation here
3-
const returnObject = {};
4-
5-
if (Array.isArray(inputArray)) {
6-
if (inputArray.length === 0) {
7-
return "passed array was empty, no values to display";
8-
}
9-
10-
for (let item of inputArray) {
11-
returnObject[item[0]] = item[1];
12-
}
13-
14-
return returnObject;
15-
} else {
16-
throw new Error("error incorrect parameter passed please provide an array");
17-
}
183
}
194

205
module.exports = createLookup;

Sprint-2/implement/lookup.test.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
const createLookup = require("./lookup.js");
22

3-
test("creates a country currency code lookup for multiple codes", () => {
4-
expect(
5-
createLookup([
6-
["US", "USD"],
7-
["CA", "CAD"],
8-
["MW", "MWK"],
9-
["ZW", "ZWD"],
10-
])
11-
).toEqual({ US: "USD", CA: "CAD", MW: "MWK", ZW: "ZWD" });
12-
});
13-
14-
test("if passed an empty array , should print a message telling user array is empty", () => {
15-
expect(createLookup([])).toBe("passed array was empty, no values to display");
16-
});
17-
18-
test("if passed parameter which is not an array throw an error", () => {
19-
expect(() => createLookup("US, USD")).toThrow(
20-
"error incorrect parameter passed please provide an array"
21-
);
22-
});
3+
test.todo("creates a country currency code lookup for multiple codes");
234

245
/*
256

Sprint-2/implement/querystring.js

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,14 @@ function parseQueryString(queryString) {
33
if (queryString.length === 0) {
44
return queryParams;
55
}
6+
const keyValuePairs = queryString.split("&");
67

7-
if (queryString.includes("&")) {
8-
const keyValuePairs = queryString.split("&");
9-
10-
for (const pair of keyValuePairs) {
11-
let countMatch = 0;
12-
13-
if (pair.includes("=")) {
14-
const equalSignIndex = pair.indexOf("=");
15-
16-
queryParams[pair.slice(0, equalSignIndex)] = pair.slice(
17-
equalSignIndex + 1
18-
);
19-
} else {
20-
throw new Error(
21-
"error invalid format string, no = to separate key value pairs"
22-
);
23-
}
24-
}
25-
}
26-
27-
if (queryString.includes("=")) {
28-
const equalSignIndex = queryString.indexOf("=");
29-
30-
queryParams[queryString.slice(0, equalSignIndex)] = queryString.slice(
31-
equalSignIndex + 1
32-
);
33-
} else {
34-
throw new Error(
35-
"error invalid format string, no = to separate key value pairs"
36-
);
8+
for (const pair of keyValuePairs) {
9+
const [key, value] = pair.split("=");
10+
queryParams[key] = value;
3711
}
3812

3913
return queryParams;
4014
}
4115

42-
console.log(`with ${parseQueryString("equation=x=y+1")}`);
43-
4416
module.exports = parseQueryString;

Sprint-2/implement/querystring.test.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,10 @@
33
// Below is one test case for an edge case the implementation doesn't handle well.
44
// Fix the implementation for this test, and try to think of as many other edge cases as possible - write tests and fix those too.
55

6-
const parseQueryString = require("./querystring.js");
7-
8-
test("parseQueryString receives an empty string", () => {
9-
expect(parseQueryString("")).toEqual({});
10-
});
6+
const parseQueryString = require("./querystring.js")
117

128
test("parses querystring values containing =", () => {
139
expect(parseQueryString("equation=x=y+1")).toEqual({
14-
equation: "x=y+1",
10+
"equation": "x=y+1",
1511
});
1612
});
17-
18-
test("if our function is passed only one key - value pair", () => {
19-
expect(parseQueryString("color=brown")).toEqual({ color: "brown" });
20-
});
21-
22-
test("parses querystring without an =, it should throw an error", () => {
23-
expect(() => parseQueryString("colorisequaltobrown")).toThrow(
24-
"error invalid format string, no = to separate key value pairs"
25-
);
26-
});
27-
28-
test("if our function is passed only one string but there is no =", () => {
29-
expect(parseQueryString("color,brown")).toEqual(
30-
"error invalid format string, no = to separate key value pair"
31-
);
32-
});

Sprint-2/implement/tally.js

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
function tally(inputArray) {
2-
if (Array.isArray(inputArray)) {
3-
if (inputArray.length === 0) {
4-
return {};
5-
}
6-
7-
let itemCount = 0;
8-
const tallyObject = {};
9-
let n = 0;
10-
11-
while (inputArray.length > 0) {
12-
const tempArray = [];
13-
let i = 0;
14-
let currentArrayItem = inputArray[0];
15-
16-
while (i < inputArray.length) {
17-
if (currentArrayItem === inputArray[i]) {
18-
itemCount++;
19-
tempArray.push(inputArray.splice(i, 1));
20-
i--;
21-
}
22-
23-
i++;
24-
}
25-
26-
if (tempArray.length > 0) {
27-
tallyObject[tempArray[0]] = tempArray.length;
28-
}
29-
}
30-
console.log(`the new array and the new object ${tallyObject}`);
31-
return tallyObject;
32-
} else {
33-
throw new Error("error invalid input passed, please provide an array");
34-
}
35-
}
36-
37-
console.log(`new object is ${tally(["a", "a", "b", "c", "c", "d", "a"])}`);
1+
function tally() {}
382

393
module.exports = tally;

Sprint-2/implement/tally.test.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,12 @@ const tally = require("./tally.js");
2323
// Given an empty array
2424
// When passed to tally
2525
// Then it should return an empty object
26-
test("tally on an empty array returns an empty object", () => {
27-
expect(tally([])).toEqual({});
28-
});
26+
test.todo("tally on an empty array returns an empty object");
2927

3028
// Given an array with duplicate items
3129
// When passed to tally
3230
// Then it should return counts for each unique item
33-
test("given an array with duplicate items it should return counts for each unique item ", () => {
34-
expect(tally(["a", "a", "b", "c", "c", "d", "a"])).toEqual({
35-
a: 3,
36-
b: 1,
37-
c: 2,
38-
d: 1,
39-
});
40-
});
4131

4232
// Given an invalid input like a string
4333
// When passed to tally
4434
// Then it should throw an error
45-
test("should throw an error when tally is passed an invalid input like a string", () => {
46-
expect(() => tally("b,b,c,d,e,e,f")).toThrow(
47-
"error invalid input passed, please provide an array"
48-
);
49-
});

0 commit comments

Comments
 (0)