Skip to content

Commit 840b1ff

Browse files
authored
Merge pull request #1 from CodeYourFuture/master
test
2 parents aebc617 + 578cca6 commit 840b1ff

12 files changed

+156
-175
lines changed

week-1/2-mandatory/4-tax.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ function calculateSalesTax() {}
1212
===================
1313
The business has informed you that prices must have 2 decimal places
1414
They must also start with the currency symbol
15-
Write a function that transforms numbers into the format £0.00
15+
Write a function that adds tax to a number, and then transforms the total into the format £0.00
1616
1717
Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
1818
*/
1919

20-
function formatCurrency() {}
20+
function addTaxAndFormatCurrency() {}
2121

2222
/* ======= TESTS - DO NOT MODIFY =====
2323
There are some Tests in this file that will help you work out if your code is working.
@@ -41,6 +41,6 @@ test("calculateSalesTax function - case 1 works", calculateSalesTax(15), 18)
4141
test("calculateSalesTax function - case 2 works", calculateSalesTax(17.5), 21)
4242
test("calculateSalesTax function - case 3 works", calculateSalesTax(34), 40.8)
4343

44-
test("formatCurrency function - case 1 works", formatCurrency(15), "£18.00")
45-
test("formatCurrency function - case 2 works", formatCurrency(17.5), "£21.00")
46-
test("formatCurrency function - case 3 works", formatCurrency(34), "£40.80")
44+
test("addTaxAndFormatCurrency function - case 1 works", addTaxAndFormatCurrency(15), "£18.00")
45+
test("addTaxAndFormatCurrency function - case 2 works", addTaxAndFormatCurrency(17.5), "£21.00")
46+
test("addTaxAndFormatCurrency function - case 3 works", addTaxAndFormatCurrency(34), "£40.80")

week-1/3-extra/3-magic-8-ball.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ function testAll() {
9090
logged === "The ball has shaken!"
9191
);
9292
test(`shakeBall returns an string answer`, typeof answer === "string");
93+
94+
test(
95+
`checkAnswer("It is decidedly so.") returns "very positive`,
96+
checkAnswer("It is decidedly so.") === "very positive"
97+
)
98+
99+
test(
100+
`checkAnswer("My reply is no.") returns "very negative`,
101+
checkAnswer("My reply is no.") === "very negative"
102+
)
103+
93104
test(
94105
`checkAnswer returns the level of positivity"`,
95106
["very positive", "positive", "negative", "very negative"].includes(

week-3/2-mandatory/1-oxygen-levels.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Many years into the future, a team of Space Voyagers find their ship is low on Oxygen and need to dock
33
somewhere safe while they call home for help.
44
5-
Their computer detects a list of nearby planets that have Oxygen in their atmosphere.
5+
Their computer detects a list of nearby planets that have Oxygen in their atmosphere. It has produced an array of their Oxygen levels.
66
7-
To be safe, they need to land on the first unamed planet that has Oxygen levels between 19.5% and 23.5%.
7+
To be safe to land on, a planet needs to have an Oxygen level between 19.5% and 23.5%.
88
9-
Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5%
9+
Write a function that finds the first safe oxygen level in the array - Oxygen between 19.5% and 23.5%
1010
*/
1111

1212
function safeLevels() {
@@ -15,26 +15,37 @@ function safeLevels() {
1515

1616
/* ======= TESTS - DO NOT MODIFY ===== */
1717

18-
const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"]
19-
const oxygenLevels2 = ["30.8%", "23.5%", "18.8%", "19.5%", "20.2%", "31.6%"]
18+
const oxygenLevels1 = ["24.2%", "11.3%", "19.9%", "23.1%", "29.3%", "20.2%"];
19+
const oxygenLevels2 = ["30.8%", "23.5%", "18.8%", "19.5%", "20.2%", "31.6%"];
20+
const oxygenLevels3 = ["200%", "21.1%"];
2021

21-
function test(test_name, expr) {
22+
const util = require('util');
23+
24+
function test(test_name, actual, expected) {
2225
let status;
23-
if (expr) {
24-
status = "PASSED";
26+
if (actual === expected) {
27+
status = "PASSED";
2528
} else {
26-
status = "FAILED";
29+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
2730
}
28-
31+
2932
console.log(`${test_name}: ${status}`);
3033
}
3134

3235
test(
33-
"safeLevels function works - case 2",
34-
safeLevels(oxygenLevels1) === "19.9%"
36+
"safeLevels function works - case 1",
37+
safeLevels(oxygenLevels1),
38+
"19.9%"
3539
);
3640

3741
test(
3842
"safeLevels function works - case 2",
39-
safeLevels(oxygenLevels2) === "20.2%"
40-
);
43+
safeLevels(oxygenLevels2),
44+
"20.2%"
45+
);
46+
47+
test(
48+
"safeLevels function works - case 3",
49+
safeLevels(oxygenLevels3),
50+
"21.1%"
51+
);

week-3/2-mandatory/2-bush-berries.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,27 @@ function bushChecker() {
1919
let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"]
2020
let bushBerryColours2 = ["pink", "pink", "pink", "pink"]
2121

22-
function test(test_name, expr) {
23-
let status;
24-
if (expr) {
25-
status = "PASSED";
26-
} else {
27-
status = "FAILED";
28-
}
29-
30-
console.log(`${test_name}: ${status}`);
22+
const util = require('util');
23+
24+
function test(test_name, actual, expected) {
25+
let status;
26+
if (actual === expected) {
27+
status = "PASSED";
28+
} else {
29+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
30+
}
31+
32+
console.log(`${test_name}: ${status}`);
3133
}
3234

33-
test("bushChecker funtion works - case 1", bushChecker(bushBerryColours1) === "Toxic! Leave bush alone!")
34-
test("bushChecker funtion works - case 1", bushChecker(bushBerryColours2) === "Bush is safe to eat from")
35+
test(
36+
"bushChecker funtion works - case 1",
37+
bushChecker(bushBerryColours1),
38+
"Toxic! Leave bush alone!"
39+
);
40+
41+
test(
42+
"bushChecker funtion works - case 1",
43+
bushChecker(bushBerryColours2),
44+
"Bush is safe to eat from"
45+
);

week-3/2-mandatory/3-space-colonies.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,21 @@ const voyagers = [
2929
"Archer family"
3030
];
3131

32-
function arraysEqual(a, b) {
33-
if (a === b) return true;
34-
if (a == null || b == null) return false;
35-
if (a.length != b.length) return false;
32+
const util = require('util');
3633

37-
for (let i = 0; i < a.length; ++i) {
38-
if (a[i] !== b[i]) return false;
39-
}
34+
function test(test_name, actual, expected) {
35+
let status;
36+
if (util.isDeepStrictEqual(actual, expected)) {
37+
status = "PASSED";
38+
} else {
39+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
40+
}
4041

41-
return true;
42+
console.log(`${test_name}: ${status}`);
4243
}
4344

44-
function test(test_name, expr) {
45-
let status;
46-
if (expr) {
47-
status = "PASSED";
48-
} else {
49-
status = "FAILED";
50-
}
51-
52-
console.log(`${test_name}: ${status}`);
53-
}
54-
55-
test("colonisers function works",
56-
arraysEqual(colonisers(voyagers), ["Adam family", "Avery family", "Archer family"])
57-
)
45+
test(
46+
"colonisers function works",
47+
colonisers(voyagers),
48+
["Adam family", "Avery family", "Archer family"]
49+
)

week-3/2-mandatory/4-eligible-students.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,20 @@ const attendances = [
2222
["Nina", 10]
2323
]
2424

25-
function arraysEqual(a, b) {
26-
if (a === b) return true;
27-
if (a == null || b == null) return false;
28-
if (a.length != b.length) return false;
29-
30-
for (let i = 0; i < a.length; ++i) {
31-
if (a[i] !== b[i]) return false;
32-
}
33-
34-
return true;
35-
}
25+
const util = require('util');
3626

37-
function test(test_name, expr) {
27+
function test(test_name, actual, expected) {
3828
let status;
39-
if (expr) {
40-
status = "PASSED";
29+
if (util.isDeepStrictEqual(actual, expected)) {
30+
status = "PASSED";
4131
} else {
42-
status = "FAILED";
32+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
4333
}
44-
34+
4535
console.log(`${test_name}: ${status}`);
4636
}
4737

4838
test("eligibleStudents function works",
49-
arraysEqual(
50-
eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"]
51-
)
52-
)
39+
eligibleStudents(attendances),
40+
["Ahmed", "Clement", "Tayoa", "Nina"]
41+
);
Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,51 @@
11
/*
22
I am new to London and would like to know what transport I can take to different famous locations.
3-
An array with London locations have been provided.
3+
An array with London locations, and the forms of transport you can take to get there, have been provided.
44
55
Return an array of where I can go if I only want to use a specific mode of transport.
66
77
NOTE: only the names should be returned, not the means of transport.
88
*/
99

1010
function journeyPlanner() {
11-
1211
}
1312

1413
/* ======= TESTS - DO NOT MODIFY ===== */
1514

1615
const londonLocations = [
1716
["Angel", "tube", "bus"],
17+
["Greenwich", "bus", "river boat", "dlr", "air line", "tube"],
1818
["London Bridge", "tube", "river boat"],
1919
["Tower Bridge", "tube", "bus"],
20-
["Greenwich", "bus", "river boat"]
2120
]
2221

23-
function arraysEqual(a, b) {
24-
if (a === b) return true;
25-
if (a == null || b == null) return false;
26-
if (a.length != b.length) return false;
27-
28-
for (let i = 0; i < a.length; ++i) {
29-
if (a[i] !== b[i]) return false;
30-
}
31-
32-
return true;
33-
}
22+
const util = require('util');
3423

35-
function test(test_name, expr) {
24+
function test(test_name, actual, expected) {
3625
let status;
37-
if (expr) {
38-
status = "PASSED";
26+
if (util.isDeepStrictEqual(actual, expected)) {
27+
status = "PASSED";
3928
} else {
40-
status = "FAILED";
29+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
4130
}
42-
31+
4332
console.log(`${test_name}: ${status}`);
4433
}
4534

46-
test("journeyPlanner function works - case 1",
47-
arraysEqual(
48-
journeyPlanner(londonLocations, "river boat"),
49-
["London Bridge", "Greenwich"]
50-
)
51-
)
52-
53-
test("journeyPlanner function works - case 2",
54-
arraysEqual(
55-
journeyPlanner(londonLocations, "bus"),
56-
["Angel", "Tower Bridge", "Greenwich"]
57-
)
58-
)
59-
60-
test("journeyPlanner function works - case 3",
61-
arraysEqual(
62-
journeyPlanner(londonLocations, "tube"),
63-
["Angel", "London Bridge", "Tower Bridge"]
64-
)
65-
)
35+
test(
36+
"journeyPlanner function works - case 1",
37+
journeyPlanner(londonLocations, "river boat"),
38+
["Greenwich", "London Bridge"]
39+
);
40+
41+
test(
42+
"journeyPlanner function works - case 2",
43+
journeyPlanner(londonLocations, "bus"),
44+
["Angel", "Greenwich", "Tower Bridge"]
45+
);
46+
47+
test(
48+
"journeyPlanner function works - case 3",
49+
journeyPlanner(londonLocations, "tube"),
50+
["Angel", "Greenwich", "London Bridge", "Tower Bridge"]
51+
);

week-3/2-mandatory/6-lane-names.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,21 @@ const streetNames = [
1818
"Alban Highwalk"
1919
]
2020

21-
function arraysEqual(a, b) {
22-
if (a === b) return true;
23-
if (a == null || b == null) return false;
24-
if (a.length != b.length) return false;
25-
26-
for (let i = 0; i < a.length; ++i) {
27-
if (a[i] !== b[i]) return false;
28-
}
29-
30-
return true;
31-
}
32-
33-
function test(test_name, expr) {
21+
const util = require('util');
22+
23+
function test(test_name, actual, expected) {
3424
let status;
35-
if (expr) {
25+
if (util.isDeepStrictEqual(actual, expected)) {
3626
status = "PASSED";
3727
} else {
38-
status = "FAILED";
28+
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
3929
}
40-
30+
4131
console.log(`${test_name}: ${status}`);
4232
}
4333

44-
test("getLanes function works",
45-
arraysEqual(getLanes(streetNames), ["Abchurch Lane", "Addle Lane"])
46-
)
34+
test(
35+
"getLanes function works",
36+
getLanes(streetNames),
37+
["Abchurch Lane", "Addle Lane"]
38+
);

0 commit comments

Comments
 (0)