Skip to content

test #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions week-1/2-mandatory/4-tax.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ function calculateSalesTax() {}
===================
The business has informed you that prices must have 2 decimal places
They must also start with the currency symbol
Write a function that transforms numbers into the format £0.00
Write a function that adds tax to a number, and then transforms the total into the format £0.00

Remember that the prices must include the sales tax (hint: you already wrote a function for this!)
*/

function formatCurrency() {}
function addTaxAndFormatCurrency() {}

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

test("formatCurrency function - case 1 works", formatCurrency(15), "£18.00")
test("formatCurrency function - case 2 works", formatCurrency(17.5), "£21.00")
test("formatCurrency function - case 3 works", formatCurrency(34), "£40.80")
test("addTaxAndFormatCurrency function - case 1 works", addTaxAndFormatCurrency(15), "£18.00")
test("addTaxAndFormatCurrency function - case 2 works", addTaxAndFormatCurrency(17.5), "£21.00")
test("addTaxAndFormatCurrency function - case 3 works", addTaxAndFormatCurrency(34), "£40.80")
11 changes: 11 additions & 0 deletions week-1/3-extra/3-magic-8-ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ function testAll() {
logged === "The ball has shaken!"
);
test(`shakeBall returns an string answer`, typeof answer === "string");

test(
`checkAnswer("It is decidedly so.") returns "very positive`,
checkAnswer("It is decidedly so.") === "very positive"
)

test(
`checkAnswer("My reply is no.") returns "very negative`,
checkAnswer("My reply is no.") === "very negative"
)

test(
`checkAnswer returns the level of positivity"`,
["very positive", "positive", "negative", "very negative"].includes(
Expand Down
39 changes: 25 additions & 14 deletions week-3/2-mandatory/1-oxygen-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Many years into the future, a team of Space Voyagers find their ship is low on Oxygen and need to dock
somewhere safe while they call home for help.

Their computer detects a list of nearby planets that have Oxygen in their atmosphere.
Their computer detects a list of nearby planets that have Oxygen in their atmosphere. It has produced an array of their Oxygen levels.

To be safe, they need to land on the first unamed planet that has Oxygen levels between 19.5% and 23.5%.
To be safe to land on, a planet needs to have an Oxygen level between 19.5% and 23.5%.

Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5%
Write a function that finds the first safe oxygen level in the array - Oxygen between 19.5% and 23.5%
*/

function safeLevels() {
Expand All @@ -15,26 +15,37 @@ function safeLevels() {

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

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

function test(test_name, expr) {
const util = require('util');

function test(test_name, actual, expected) {
let status;
if (expr) {
status = "PASSED";
if (actual === expected) {
status = "PASSED";
} else {
status = "FAILED";
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
}

console.log(`${test_name}: ${status}`);
}

test(
"safeLevels function works - case 2",
safeLevels(oxygenLevels1) === "19.9%"
"safeLevels function works - case 1",
safeLevels(oxygenLevels1),
"19.9%"
);

test(
"safeLevels function works - case 2",
safeLevels(oxygenLevels2) === "20.2%"
);
safeLevels(oxygenLevels2),
"20.2%"
);

test(
"safeLevels function works - case 3",
safeLevels(oxygenLevels3),
"21.1%"
);
33 changes: 22 additions & 11 deletions week-3/2-mandatory/2-bush-berries.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,27 @@ function bushChecker() {
let bushBerryColours1 = ["pink", "pink", "pink", "neon", "pink", "transparent"]
let bushBerryColours2 = ["pink", "pink", "pink", "pink"]

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}

console.log(`${test_name}: ${status}`);
const util = require('util');

function test(test_name, actual, expected) {
let status;
if (actual === expected) {
status = "PASSED";
} else {
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
}

console.log(`${test_name}: ${status}`);
}

test("bushChecker funtion works - case 1", bushChecker(bushBerryColours1) === "Toxic! Leave bush alone!")
test("bushChecker funtion works - case 1", bushChecker(bushBerryColours2) === "Bush is safe to eat from")
test(
"bushChecker funtion works - case 1",
bushChecker(bushBerryColours1),
"Toxic! Leave bush alone!"
);

test(
"bushChecker funtion works - case 1",
bushChecker(bushBerryColours2),
"Bush is safe to eat from"
);
36 changes: 14 additions & 22 deletions week-3/2-mandatory/3-space-colonies.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,21 @@ const voyagers = [
"Archer family"
];

function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;
const util = require('util');

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

return true;
console.log(`${test_name}: ${status}`);
}

function test(test_name, expr) {
let status;
if (expr) {
status = "PASSED";
} else {
status = "FAILED";
}

console.log(`${test_name}: ${status}`);
}

test("colonisers function works",
arraysEqual(colonisers(voyagers), ["Adam family", "Avery family", "Archer family"])
)
test(
"colonisers function works",
colonisers(voyagers),
["Adam family", "Avery family", "Archer family"]
)
29 changes: 9 additions & 20 deletions week-3/2-mandatory/4-eligible-students.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,20 @@ const attendances = [
["Nina", 10]
]

function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;

for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}

return true;
}
const util = require('util');

function test(test_name, expr) {
function test(test_name, actual, expected) {
let status;
if (expr) {
status = "PASSED";
if (util.isDeepStrictEqual(actual, expected)) {
status = "PASSED";
} else {
status = "FAILED";
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
}

console.log(`${test_name}: ${status}`);
}

test("eligibleStudents function works",
arraysEqual(
eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"]
)
)
eligibleStudents(attendances),
["Ahmed", "Clement", "Tayoa", "Nina"]
);
64 changes: 25 additions & 39 deletions week-3/2-mandatory/5-journey-planner.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,51 @@
/*
I am new to London and would like to know what transport I can take to different famous locations.
An array with London locations have been provided.
An array with London locations, and the forms of transport you can take to get there, have been provided.

Return an array of where I can go if I only want to use a specific mode of transport.

NOTE: only the names should be returned, not the means of transport.
*/

function journeyPlanner() {

}

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

const londonLocations = [
["Angel", "tube", "bus"],
["Greenwich", "bus", "river boat", "dlr", "air line", "tube"],
["London Bridge", "tube", "river boat"],
["Tower Bridge", "tube", "bus"],
["Greenwich", "bus", "river boat"]
]

function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;

for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}

return true;
}
const util = require('util');

function test(test_name, expr) {
function test(test_name, actual, expected) {
let status;
if (expr) {
status = "PASSED";
if (util.isDeepStrictEqual(actual, expected)) {
status = "PASSED";
} else {
status = "FAILED";
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
}

console.log(`${test_name}: ${status}`);
}

test("journeyPlanner function works - case 1",
arraysEqual(
journeyPlanner(londonLocations, "river boat"),
["London Bridge", "Greenwich"]
)
)

test("journeyPlanner function works - case 2",
arraysEqual(
journeyPlanner(londonLocations, "bus"),
["Angel", "Tower Bridge", "Greenwich"]
)
)

test("journeyPlanner function works - case 3",
arraysEqual(
journeyPlanner(londonLocations, "tube"),
["Angel", "London Bridge", "Tower Bridge"]
)
)
test(
"journeyPlanner function works - case 1",
journeyPlanner(londonLocations, "river boat"),
["Greenwich", "London Bridge"]
);

test(
"journeyPlanner function works - case 2",
journeyPlanner(londonLocations, "bus"),
["Angel", "Greenwich", "Tower Bridge"]
);

test(
"journeyPlanner function works - case 3",
journeyPlanner(londonLocations, "tube"),
["Angel", "Greenwich", "London Bridge", "Tower Bridge"]
);
30 changes: 11 additions & 19 deletions week-3/2-mandatory/6-lane-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,21 @@ const streetNames = [
"Alban Highwalk"
]

function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;

for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}

return true;
}

function test(test_name, expr) {
const util = require('util');

function test(test_name, actual, expected) {
let status;
if (expr) {
if (util.isDeepStrictEqual(actual, expected)) {
status = "PASSED";
} else {
status = "FAILED";
status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`;
}

console.log(`${test_name}: ${status}`);
}

test("getLanes function works",
arraysEqual(getLanes(streetNames), ["Abchurch Lane", "Addle Lane"])
)
test(
"getLanes function works",
getLanes(streetNames),
["Abchurch Lane", "Addle Lane"]
);
Loading