-
Notifications
You must be signed in to change notification settings - Fork 10
Etem-w3-JavaScript #20
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
base: main
Are you sure you want to change the base?
Changes from all commits
80137da
f3c5114
a5b82d0
7b413f5
25c12fc
b12c8f7
54e4b01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Test Summary | ||
|
||
**Mentors**: For more information on how to review homework assignments, please refer to the [Review Guide](https://github.com/HackYourFuture/mentors/blob/main/assignment-support/review-guide.md). | ||
|
||
### 1-JavaScript - Week3 | ||
|
||
| Exercise | Passed | Failed | ESLint | | ||
|----------------------------|--------|--------|--------| | ||
| ex1-doubleEvenNumbers.test | 1 | - | ✓ | | ||
| ex2-mondaysWorth.test | 2 | - | ✓ | | ||
| ex3-lemonAllergy.test | 3 | - | ✓ | | ||
| ex4-observable | 3 | - | ✓ | | ||
| ex5-wallet | 5 | - | ✓ | |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,7 @@ Let's rewrite it (or _refactor_ it, as experienced developers would call it): | |
------------------------------------------------------------------------------*/ | ||
// ! Function to be tested | ||
function doubleEvenNumbers(numbers) { | ||
// TODO rewrite the function body using `map` and `filter`. | ||
const newNumbers = []; | ||
for (let i = 0; i < numbers.length; i++) { | ||
if (numbers[i] % 2 === 0) { | ||
newNumbers.push(numbers[i] * 2); | ||
} | ||
} | ||
return newNumbers; | ||
return numbers.filter((num) => num % 2 === 0).map((num) => num * 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks correct. |
||
} | ||
|
||
// ! Unit test (using Jest) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,15 +30,18 @@ const mondayTasks = [ | |
|
||
const hourlyRate = 25; | ||
|
||
function computeEarnings(/* TODO parameter(s) go here */) { | ||
// TODO complete this function | ||
function computeEarnings(tasks, hourlyRate) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks correct |
||
let totalEarnings = 0; | ||
for (let i = 0; i < tasks.length; i++) { | ||
const hours = tasks[i].duration / 60; | ||
totalEarnings += hours * hourlyRate; | ||
} | ||
return `€${totalEarnings.toFixed(2)}`; | ||
} | ||
|
||
// ! Unit tests (using Jest) | ||
describe('js-wk3-mondaysWorth', () => { | ||
test('computeEarnings should take two parameters', () => { | ||
// The `.length` property indicates the number of parameters expected by | ||
// the function. | ||
expect(computeEarnings).toHaveLength(2); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,26 +25,25 @@ const fruitBasket = [ | |
]; | ||
|
||
// ! Function under test | ||
function sanitizeFruitBasket(/* TODO parameter(s) go here */) { | ||
// TODO complete this function | ||
function sanitizeFruitBasket(fruitBasket, unwantedFruit) { | ||
return fruitBasket.filter((fruit) => fruit !== unwantedFruit); | ||
} | ||
|
||
// ! Unit tests (using Jest) | ||
describe('js-wk3-ex3-lemonAllergy', () => { | ||
test('sanitizeFruitBasket should take two parameters', () => { | ||
// TODO replace next line with your code | ||
expect(false).toBe(true); | ||
console.log(sanitizeFruitBasket.length); | ||
expect(sanitizeFruitBasket).toHaveLength(2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice implementation. |
||
}); | ||
|
||
test('sanitizeFruitBasket 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('sanitizeFruitBasket should return a new array that does not include the unwanted `lemon`', () => { | ||
// TODO replace next line with your code | ||
expect(false).toBe(true); | ||
const sanitizedFruitBasket = sanitizeFruitBasket(fruitBasket, 'lemon'); | ||
expect(sanitizedFruitBasket).not.toContain('lemon'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,10 @@ export function createObservable() { | |
const subscribers = []; | ||
return { | ||
subscribe(subscriber) { | ||
// TODO complete this function | ||
subscribers.push(subscriber); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks correct |
||
}, | ||
notify(message) { | ||
// TODO complete this function | ||
subscribers.forEach((subscriber) => subscriber(message)); | ||
}, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ const quiz = { | |
b: 'cash, name', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also looks correct |
||
c: 'amount, this, wallet' | ||
}, | ||
answer: '?', | ||
answer: 'b', | ||
}, | ||
q2: { | ||
question: 'What is in the Call Stack, from top to bottom?', | ||
|
@@ -84,7 +84,7 @@ const quiz = { | |
b: 'anonymous, transferInto', | ||
c: 'transferInto, anonymous' | ||
}, | ||
answer: '?', | ||
answer: 'c', | ||
}, | ||
q3: { | ||
question: 'What tooltip appears when hovering over the third debug button?', | ||
|
@@ -93,7 +93,7 @@ const quiz = { | |
b: 'Step out of current function', | ||
c: 'Step' | ||
}, | ||
answer: '?', | ||
answer: 'a', | ||
}, | ||
q4: { | ||
question: 'What is displayed in the console?', | ||
|
@@ -102,7 +102,7 @@ const quiz = { | |
b: 'Transferring € 50,00 from Jack to undefined', | ||
c: 'Transferring € 50,00 from Jack to Jane' | ||
}, | ||
answer: '?', | ||
answer: 'a', // but it is not displayed in the console as Jack to Joe. It is displayed as Jack to undefined. my answer was b. | ||
}, | ||
q5: { | ||
question: 'The owner of the wallet with insufficient funds is:', | ||
|
@@ -111,6 +111,6 @@ const quiz = { | |
b: 'Joe', | ||
c: 'Jane' | ||
}, | ||
answer: '?', | ||
answer: 'c', | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
*** Unit Test Error Report *** | ||
|
||
PASS 1-JavaScript/Week3/assignment/ex1-doubleEvenNumbers.test.js | ||
js-wk3-ex1-doubleEvenNumbers | ||
✅ doubleEvenNumbers should take the even numbers and double them (2 ms) | ||
|
||
Test Suites: 1 passed, 1 total | ||
Tests: 1 passed, 1 total | ||
Snapshots: 0 total | ||
Time: 0.176 s, estimated 1 s | ||
Ran all test suites matching /\/Users\/benetem\/HYF\/Assignments-cohort52\/1-JavaScript\/Week3\/assignment\/ex1-doubleEvenNumbers.test.js/i. | ||
No linting errors detected. | ||
No spelling errors detected. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*** Unit Test Error Report *** | ||
|
||
PASS 1-JavaScript/Week3/assignment/ex2-mondaysWorth.test.js | ||
js-wk3-mondaysWorth | ||
✅ computeEarnings should take two parameters (1 ms) | ||
✅ computeEarnings should compute the earnings as a formatted Euro amount | ||
|
||
Test Suites: 1 passed, 1 total | ||
Tests: 2 passed, 2 total | ||
Snapshots: 0 total | ||
Time: 0.175 s, estimated 1 s | ||
Ran all test suites matching /\/Users\/benetem\/HYF\/Assignments-cohort52\/1-JavaScript\/Week3\/assignment\/ex2-mondaysWorth.test.js/i. | ||
No linting errors detected. | ||
No spelling errors detected. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
*** Unit Test Error Report *** | ||
|
||
console.log | ||
2 | ||
|
||
at Object.log (1-JavaScript/Week3/assignment/ex3-lemonAllergy.test.js:35:13) | ||
|
||
PASS 1-JavaScript/Week3/assignment/ex3-lemonAllergy.test.js | ||
js-wk3-ex3-lemonAllergy | ||
✅ sanitizeFruitBasket should take two parameters (12 ms) | ||
✅ sanitizeFruitBasket should not modify the original `fruitBasket` array (1 ms) | ||
✅ sanitizeFruitBasket should return a new array that does not include the unwanted `lemon` | ||
|
||
Test Suites: 1 passed, 1 total | ||
Tests: 3 passed, 3 total | ||
Snapshots: 0 total | ||
Time: 0.185 s, estimated 1 s | ||
Ran all test suites matching /\/Users\/benetem\/HYF\/Assignments-cohort52\/1-JavaScript\/Week3\/assignment\/ex3-lemonAllergy.test.js/i. | ||
No linting errors detected. | ||
No spelling errors detected. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*** Unit Test Error Report *** | ||
|
||
PASS 1-JavaScript/Week3/assignment/ex4-observable/ex4-observable.test.js | ||
js-wk3-ex4-observable | ||
✅ createObservable should exist and be a function (1 ms) | ||
✅ createObservable should return an object with `subscribe` and a `notify` function properties | ||
✅ observable should notify all subscribers of any notification (1 ms) | ||
|
||
Test Suites: 1 passed, 1 total | ||
Tests: 3 passed, 3 total | ||
Snapshots: 0 total | ||
Time: 0.175 s, estimated 1 s | ||
Ran all test suites matching /\/Users\/benetem\/HYF\/Assignments-cohort52\/1-JavaScript\/Week3\/assignment\/ex4-observable\/ex4-observable.test.js/i. | ||
No linting errors detected. | ||
No spelling errors detected. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*** Unit Test Error Report *** | ||
|
||
PASS .dist/1-JavaScript/Week3/unit-tests/ex5-wallet.test.js | ||
js-wk3-ex5-wallet | ||
✅ q1: At line 24, which variables are in the scope marked Closure? (1 ms) | ||
✅ q2: What is in the Call Stack, from top to bottom? (1 ms) | ||
✅ q3: What tooltip appears when hovering over the third debug button? | ||
✅ q4: What is displayed in the console? | ||
✅ q5: The owner of the wallet with insufficient funds is? | ||
|
||
Test Suites: 1 passed, 1 total | ||
Tests: 5 passed, 5 total | ||
Snapshots: 0 total | ||
Time: 0.244 s, estimated 1 s | ||
Ran all test suites matching /\/Users\/benetem\/HYF\/Assignments-cohort52\/.dist\/1-JavaScript\/Week3\/unit-tests\/ex5-wallet.test.js/i. | ||
No linting errors detected. | ||
No spelling errors detected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I can't run your code. It is complaining about the branch name. The branch name is correct but a bit strange.
I got the following error when I run
npm test
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benetem What happens on your end if you run
npm test
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ddoyediran, this might happen if you check out a PR using the VSCode GitHub Pull Request extension. In this particular example it checks out the PR under the branch name
pr/benetem/20
, which is of course not a compliant branch name for the test runner. You can disable the branch name check by renaming the file.env-example
to.env
. This latter file is untracked, so should not be affected by checking out subsequent PRs.Hope this helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@remarcmij Thank you so much for this nice info. Yes, it helps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will proceed to approve now but you can try to update exercise 3 solution accordingly with the comments. Great job!!!