Skip to content

Commit

Permalink
tested
Browse files Browse the repository at this point in the history
  • Loading branch information
Tugbanur-f committed Jul 14, 2024
1 parent 8385413 commit 05c351a
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 38 deletions.
6 changes: 3 additions & 3 deletions 1-JavaScript/Week3/assignment/ex1-doubleEvenNumbers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Let's rewrite it (or _refactor_ it, as experienced developers would call it):
------------------------------------------------------------------------------*/
// ! Function to be tested
function doubleEvenNumbers(numbers) {
return numbers
return numbers
.filter(number => number % 2 === 0)
.map(number => number * 2)
.map(number => number * 2);

}
}

// // ! Unit test (using Jest)
test('doubleEvenNumbers should take the even numbers and double them', () => {
Expand Down
8 changes: 6 additions & 2 deletions 1-JavaScript/Week3/assignment/ex2-mondaysWorth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ const mondayTasks = [

const hourlyRate = 25;

function computeEarnings(/* TODO parameter(s) go here */) {
// TODO complete this function
function computeEarnings(tasks, hourlyRate) {
const totalEarnings = tasks
.map(task => (task.duration / 60) * hourlyRate)
.reduce((acc, earnings) => acc + earnings, 0);

return `€${totalEarnings.toFixed(2)}`;
}

// ! Unit tests (using Jest)
Expand Down
19 changes: 11 additions & 8 deletions 1-JavaScript/Week3/assignment/ex3-lemonAllergy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,29 @@ const fruitBasket = [
];

// ! Function under test
function sanitizeFruitBasket(/* TODO parameter(s) go here */) {
// TODO complete this function
function sanitizeFruitBasket(arr, fruitName) {
const unwantedFruit = arr.filter(fruit => fruit !== fruitName)
return unwantedFruit;

}
console.log(sanitizeFruitBasket(fruitBasket, 'lemon'));

// ! Unit tests (using Jest)
describe('sanitizeFruitBasket', () => {
test('should take two parameters', () => {
// TODO replace next line with your code
expect(false).toBe(true);
expect(sanitizeFruitBasket.length).toBe(2);
});

test('should not modify the original `fruitBasket` array', () => {
// Save the original contents of the fruit basket
const originalFruitBasketContents = [...fruitBasket];
// TODO replace next line with your code
expect(false).toBe(true);
sanitizeFruitBasket(fruitBasket, 'lemon');
expect(fruitBasket).toEqual(originalFruitBasketContents);
});

test('should return a new array that does not include the unwanted `lemon`', () => {
// TODO replace next line with your code
expect(false).toBe(true);
const result = sanitizeFruitBasket(fruitBasket, 'lemon');
const expected = ['apple', 'grapefruit', 'banana', 'watermelon'];
expect(result).toEqual(expected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ function createObservable() {
const subscribers = [];
return {
subscribe: function (subscriber) {
// TODO complete this function
subscribers.push(subscriber);
},
notify: function (message) {
// TODO complete this function
subscribers.forEach(subscriber => subscriber(message));
},
};
}


// ! Do not change or remove the code below
module.exports = createObservable;
10 changes: 5 additions & 5 deletions 1-JavaScript/Week3/assignment/ex5-wallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const quiz = {
b: 'cash, name',
c: 'amount, this, wallet'
},
answer: undefined,
answer:'b',
},
q2: {
question: 'What is in the Call Stack, from top to bottom?',
Expand All @@ -86,7 +86,7 @@ const quiz = {
b: 'anonymous, transferInto',
c: 'transferInto, anonymous'
},
answer: undefined,
answer: 'c',
},
q3: {
question: 'What tooltip appears when hovering over the third debug button?',
Expand All @@ -95,7 +95,7 @@ const quiz = {
b: 'Step out of current function',
c: 'Step'
},
answer: undefined,
answer: 'a',
},
q4: {
question: 'What is displayed in the console?',
Expand All @@ -104,7 +104,7 @@ const quiz = {
b: 'Transferring € 50,00 from Jack to undefined',
c: 'Transferring € 50,00 from Jack to Jane'
},
answer: undefined,
answer: 'a',
},
q5: {
question: 'The owner of the wallet with insufficient funds is:',
Expand All @@ -113,6 +113,6 @@ const quiz = {
b: 'Joe',
c: 'Jane'
},
answer: undefined,
answer: 'c',
},
};
4 changes: 2 additions & 2 deletions 1-JavaScript/Week3/assignment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"jest": "^29.7.0"
}
},
"description": ""
}
11 changes: 0 additions & 11 deletions 1-JavaScript/Week3/package.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All tests passed

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All tests passed

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All tests passed

This file was deleted.

1 change: 1 addition & 0 deletions 1-JavaScript/Week3/test-reports/ex4-observable.pass.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All tests passed
1 change: 0 additions & 1 deletion 1-JavaScript/Week3/test-reports/ex4-observable.todo.txt

This file was deleted.

1 change: 1 addition & 0 deletions 1-JavaScript/Week3/test-reports/ex5-wallet.pass.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All tests passed
1 change: 0 additions & 1 deletion 1-JavaScript/Week3/test-reports/ex5-wallet.todo.txt

This file was deleted.

Loading

0 comments on commit 05c351a

Please sign in to comment.