-
-
Notifications
You must be signed in to change notification settings - Fork 199
Rework sprint 3 assignments #694
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
Changes from all commits
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,44 @@ | ||||||
# Implement solutions and rewrite tests with Jest | ||||||
|
||||||
## 1 Implement solutions | ||||||
|
||||||
In the `implement` directory you've got a number of functions you'll need to implement. | ||||||
For each function, you also have a number of different cases you'll need to check for your function. | ||||||
|
||||||
Write your assertions and build up your program case by case. Don't rush to a solution. The point of these assignments is to learn how to write assertions and build up a program step by step. | ||||||
|
||||||
Here is a recommended order: | ||||||
|
||||||
1. `1-get-angle-type.js` | ||||||
1. `2-is-proper-fraction.js` | ||||||
1. `3-get-card-value.js` | ||||||
|
||||||
## 2 Rewrite tests with Jest | ||||||
|
||||||
`console.log` is most often used as a debugging tool. We use to inspect the state of our program during runtime. | ||||||
|
||||||
We can use `console.assert` to write assertions: however, it is not very easy to use when writing large test suites. In the first section, Implement, we used a custom "helper function" to make our assertions more readable. | ||||||
|
||||||
Jest is a whole library of helper functions we can use to make our assertions more readable and easier to write. | ||||||
|
||||||
Your new task is to write the same tests as you wrote in the `implement` directory, but using Jest instead of `console.assert`. | ||||||
|
||||||
You shouldn't have to change the contents of `implement` to write these tests. | ||||||
|
||||||
There are files for your Jest tests in the `rewrite-tests-with-jest` directory. They will automatically use the functions you already implemented. | ||||||
|
||||||
You can run all the tests in this repo by running `npm test` in your terminal. However, VSCode has a built-in test runner that you can use to run the tests, and this should make it much easier to focus on building up your test cases one at a time. | ||||||
|
||||||
https://code.visualstudio.com/docs/editor/testing | ||||||
|
||||||
1. Go to rewrite-tests-with-jest/1-get-angle-type.test.js | ||||||
1. Click the green play button to run the test. It's on the left of the test function in the gutter. | ||||||
1. Read the output in the TEST_RESULTS tab at the bottom of the screen. | ||||||
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.
Suggested change
|
||||||
1. Explore all the tests in this repo by opening the TEST EXPLORER tab. The logo is a beaker. | ||||||
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.
Suggested change
|
||||||
|
||||||
 | ||||||
|
||||||
 | ||||||
|
||||||
> [!TIP] | ||||||
> You can always run a single test file by running `npm test path/to/test-file.test.js`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// This statement loads the getCardValue function you wrote in the implement directory. | ||
// We will use the same function, but write tests for it using Jest in this file. | ||
const getCardValue = require("../implement/3-get-card-value"); | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
|
||
// Case 2: Handle Number Cards (2-10): | ||
// Case 3: Handle Face Cards (J, Q, K): | ||
// Case 4: Handle Ace (A): | ||
// Case 5: Handle Invalid Cards: |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Practice TDD | ||
|
||
In this section you'll practice this key skill of building up your program test first. | ||
|
||
Use the Jest syntax and complete the provided files, meeting the acceptance criteria for each function. Use the VSCode test runner to run your tests and check your progress. | ||
|
||
Write the tests _before_ the code that will make them pass. | ||
|
||
Recommended order: | ||
|
||
1. `count.test.js` | ||
1. `repeat.test.js` | ||
1. `get-ordinal-number.test.js` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
return 5 | ||
} | ||
|
||
module.exports = countChar; | ||
module.exports = countChar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
} | ||
|
||
module.exports = getOrdinalNumber; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
} | ||
|
||
module.exports = repeat; |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 🔍 Stretch | ||
|
||
These stretch activities are not mandatory, but we hope you will explore them after you have completed the mandatory work. | ||
|
||
In this exercise, you'll need to **play computer** with the function `find`. This function makes use of while loop statement. Your task will be to step through the code to figure out what is happening when the computer executes the code. | ||
|
||
Next, try implementing the functions specified in `password-validator.js`. | ||
|
||
Finally, set up your own script and test files for `card-validator.md` |
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.