Skip to content

Commit 356a851

Browse files
author
russom
committed
files changed
1 parent 17367af commit 356a851

5 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Implement a function getAngleType
2+
//
3+
// When given an angle in degrees, it should return a string indicating the type of angle:
4+
// - "Acute angle" for angles greater than 0° and less than 90°
5+
// - "Right angle" for exactly 90°
6+
// - "Obtuse angle" for angles greater than 90° and less than 180°
7+
// - "Straight angle" for exactly 180°
8+
// - "Reflex angle" for angles greater than 180° and less than 360°
9+
// - "Invalid angle" for angles outside the valid range.
10+
11+
// Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.)
12+
13+
// Acceptance criteria:
14+
// After you have implemented the function, write tests to cover all the cases, and
15+
// execute the code to ensure all tests pass.
16+
17+
function getAngleType(angle) {
18+
// TODO: Implement this function
19+
}
20+
21+
// The line below allows us to load the getAngleType function into tests in other files.
22+
// This will be useful in the "rewrite tests with jest" step.
23+
module.exports = getAngleType;
24+
25+
// This helper function is written to make our assertions easier to read.
26+
// If the actual output matches the target output, the test will pass
27+
function assertEquals(actualOutput, targetOutput) {
28+
console.assert(
29+
actualOutput === targetOutput,
30+
`Expected ${actualOutput} to equal ${targetOutput}`
31+
);
32+
}
33+
34+
// TODO: Write tests to cover all cases, including boundary and invalid cases.
35+
// Example: Identify Right Angles
36+
const right = getAngleType(90);
37+
assertEquals(right, "Right angle");
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Implement a function isProperFraction,
2+
// when given two numbers, a numerator and a denominator, it should return true if
3+
// the given numbers form a proper fraction, and false otherwise.
4+
5+
// Assumption: The parameters are valid numbers (not NaN or Infinity).
6+
7+
// Note: If you are unfamiliar with proper fractions, please look up its mathematical definition.
8+
9+
// Acceptance criteria:
10+
// After you have implemented the function, write tests to cover all the cases, and
11+
// execute the code to ensure all tests pass.
12+
13+
function isProperFraction(numerator, denominator) {
14+
// TODO: Implement this function
15+
}
16+
17+
// The line below allows us to load the isProperFraction function into tests in other files.
18+
// This will be useful in the "rewrite tests with jest" step.
19+
module.exports = isProperFraction;
20+
21+
// Here's our helper again
22+
function assertEquals(actualOutput, targetOutput) {
23+
console.assert(
24+
actualOutput === targetOutput,
25+
`Expected ${actualOutput} to equal ${targetOutput}`
26+
);
27+
}
28+
29+
// TODO: Write tests to cover all cases.
30+
// What combinations of numerators and denominators should you test?
31+
32+
// Example: 1/2 is a proper fraction
33+
assertEquals(isProperFraction(1, 2), true);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This statement loads the isProperFraction function you wrote in the implement directory.
2+
// We will use the same function, but write tests for it using Jest in this file.
3+
const isProperFraction = require("../implement/2-is-proper-fraction");
4+
5+
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
6+
7+
// Special case: numerator is zero
8+
test(`should return false when denominator is zero`, () => {
9+
expect(isProperFraction(1, 0)).toEqual(false);
10+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This statement loads the getCardValue function you wrote in the implement directory.
2+
// We will use the same function, but write tests for it using Jest in this file.
3+
const getCardValue = require("../implement/3-get-card-value");
4+
5+
// TODO: Write tests in Jest syntax to cover all possible outcomes.
6+
7+
// Case 1: Ace (A)
8+
test(`Should return 11 when given an ace card`, () => {
9+
expect(getCardValue("A♠")).toEqual(11);
10+
});
11+
12+
// Suggestion: Group the remaining test data into these categories:
13+
// Number Cards (2-10)
14+
// Face Cards (J, Q, K)
15+
// Invalid Cards
16+
17+
// To learn how to test whether a function throws an error as expected in Jest,
18+
// please refer to the Jest documentation:
19+
// https://jestjs.io/docs/expect#tothrowerror
20+
//k

Sprint-3/2-practice-tdd/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Practice TDD
2+
3+
In this section you'll practice this key skill of building up your program test first.
4+
5+
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.
6+
7+
Write the tests _before_ the code that will make them pass.
8+
9+
Recommended order:
10+
11+
1. `count.test.js`
12+
1. `repeat-str.test.js`
13+
1. `get-ordinal-number.test.js`

0 commit comments

Comments
 (0)