Skip to content

Commit 7d8699e

Browse files
committed
Update Sprint 3
reduce tasks, add naively passing tests
1 parent 4da80d0 commit 7d8699e

25 files changed

+290
-153
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Implement a function getAngleType
2+
// Build up your function case by case, writing tests as you go
3+
// The first test and case is written for you. The next case has a test, but no code.
4+
// Execute this script in your terminal
5+
// node 1-get-angle-type.js
6+
// The assertion error will tell you what the expected output is
7+
// Write the code to pass the test
8+
// Then, write the next test! :) Go through this process until all the cases are implemented
9+
10+
function getAngleType(angle) {
11+
if (angle === 90) return "Right angle";
12+
// read to the end, complete line 36, then pass your test here
13+
}
14+
15+
// we're going to use this helper function to make our assertions easier to read
16+
// if the actual output matches the target output, the test will pass
17+
function assertEquals(actualOutput, targetOutput) {
18+
console.assert(
19+
actualOutput === targetOutput,
20+
`Expected ${actualOutput} to equal ${targetOutput}`
21+
);
22+
}
23+
24+
// Acceptance criteria:
25+
26+
// Given an angle in degrees,
27+
// When the function getAngleType is called with this angle,
28+
// Then it should:
29+
30+
// Case 1: Identify Right Angles:
31+
// When the angle is exactly 90 degrees,
32+
// Then the function should return "Right angle"
33+
const right = getAngleType(90);
34+
assertEquals(right, "Right angle");
35+
36+
// Case 2: Identify Acute Angles:
37+
// When the angle is less than 90 degrees,
38+
// Then the function should return "Acute angle"
39+
const acute = getAngleType(45);
40+
assertEquals(acute, "Acute angle");
41+
42+
// Case 3: Identify Obtuse Angles:
43+
// When the angle is greater than 90 degrees and less than 180 degrees,
44+
// Then the function should return "Obtuse angle"
45+
const obtuse = getAngleType(120);
46+
// ====> write your test here, and then add a line to pass the test in the function above
47+
48+
// Case 4: Identify Straight Angles:
49+
// When the angle is exactly 180 degrees,
50+
// Then the function should return "Straight angle"
51+
// ====> write your test here, and then add a line to pass the test in the function above
52+
53+
// Case 5: Identify Reflex Angles:
54+
// When the angle is greater than 180 degrees and less than 360 degrees,
55+
// Then the function should return "Reflex angle"
56+
// ====> write your test here, and then add a line to pass the test in the function above
Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,53 @@
1-
// You wil need to implement a function isProperFraction
2-
// You need to write assertions for your function to check it works in different cases
3-
1+
// Implement a function isProperFraction
2+
// Write assertions for your function to check it works in different cases
43
// Terms:
54
// Fractions: https://www.bbc.co.uk/bitesize/topics/zt9n6g8/articles/zjxpp4j
65
// Written here like this: 1/2 == Numerator/Denominator
6+
// the first test and first case is written for you
7+
// complete the rest of the tests and cases
8+
// write one test at a time, and make it pass, build your solution up methodically
9+
10+
function isProperFraction(numerator, denominator) {
11+
if (numerator < denominator) return true;
12+
}
13+
14+
// here's our helper again
15+
function assertEquals(actualOutput, targetOutput) {
16+
console.assert(
17+
actualOutput === targetOutput,
18+
`Expected ${actualOutput} to equal ${targetOutput}`
19+
);
20+
}
721

822
// Acceptance criteria:
923

1024
// Proper Fraction check:
1125
// Input: numerator = 2, denominator = 3
1226
// target output: true
1327
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
28+
const properFraction = isProperFraction(2, 3);
29+
assertEquals(properFraction, true);
1430

1531
// Improper Fraction check:
1632
// Input: numerator = 5, denominator = 2
1733
// target output: false
1834
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false.
19-
20-
// Zero Denominator check:
21-
// Input: numerator = 3, denominator = 0
22-
// No target output: Error (Denominator cannot be zero)
23-
// Explanation: The function should throw an error when the denominator is zero, as it's not a valid fraction.
35+
const improperFraction = isProperFraction(5, 2);
36+
assertEquals(improperFraction, false);
2437

2538
// Negative Fraction check:
2639
// Input: numerator = -4, denominator = 7
2740
// target output: true
2841
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
42+
const negativeFraction = isProperFraction(-4, 7);
43+
// ====> complete with your assertion
2944

3045
// Equal Numerator and Denominator check:
3146
// Input: numerator = 3, denominator = 3
3247
// target output: false
3348
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
34-
// These acceptance criteria cover a range of scenarios to ensure that the isProperFraction function handles both proper and improper fractions correctly and handles potential errors such as a zero denominator.
49+
const equalFraction = isProperFraction(3, 3);
50+
// ====> complete with your assertion
51+
52+
// Stretch:
53+
// What other scenarios could you test for?

Sprint-3/implement/get-card-value.js renamed to Sprint-3/1-key-implement/3-get-card-value.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
// This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck
22

33
// You will need to implement a function getCardValue
4+
// the function takes a single parameter, a string representing a playing card
5+
// the function should return the numerical value of the card
6+
// the first test and first case is written for you
7+
// complete the rest of the tests and cases
8+
// write one test at a time, and make it pass, build your solution up methodically
9+
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
10+
function getCardValue(card) {
11+
if (rank === "A") return 11;
12+
}
413

514
// You need to write assertions for your function to check it works in different cases
6-
15+
// we're going to use this helper function to make our assertions easier to read
16+
// if the actual output matches the target output, the test will pass
17+
function assertEquals(actualOutput, targetOutput) {
18+
console.assert(
19+
actualOutput === targetOutput,
20+
`Expected ${actualOutput} to equal ${targetOutput}`
21+
);
22+
}
723
// Acceptance criteria:
824

925
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will be a number 2-10, or one letter of J, Q, K, A),
1026
// When the function getCardValue is called with this card string as input,
1127
// Then it should return the numerical card value
28+
const aceofSpades = getCardValue("A♠");
29+
assertEquals(aceofSpades, 11);
1230

1331
// Handle Number Cards (2-10):
1432
// Given a card with a rank between "2" and "9",
1533
// When the function is called with such a card,
1634
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
35+
const fiveofHearts = getCardValue("5♥");
36+
// ====> write your test here, and then add a line to pass the test in the function above
1737

1838
// Handle Face Cards (J, Q, K):
1939
// Given a card with a rank of "10," "J," "Q," or "K",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function getAngleType(angle) {
2+
if (angle === 90) return "Right angle";
3+
// replace with your completed function from key-implement
4+
5+
}
6+
7+
8+
9+
10+
11+
12+
13+
14+
// Don't get bogged down in this detail
15+
// Jest uses CommonJS module syntax by default as it's quite old
16+
// We will upgrade our approach to ES6 modules in the next course module, so for now
17+
// we have just written the CommonJS module.exports syntax for you
18+
module.exports = getAngleType;
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
// Implement a function getAngleType
1+
const getAngleType = require("./1-get-angle-type");
22

3-
// Acceptance criteria:
3+
test("should identify right angle (90°)", () => {
4+
expect(getAngleType(90)).toEqual("Right angle");
5+
});
46

5-
// Given an angle in degrees,
6-
// When the function getAngleType is called with this angle,
7-
// Then it should:
7+
// REPLACE the comments with the tests
8+
// make your test descriptions as clear and readable as possible
89

9-
// Identify Right Angles:
10-
// When the angle is exactly 90 degrees,
11-
// Then the function should return "Right angle"
12-
13-
// Identify Acute Angles:
10+
// Case 2: Identify Acute Angles:
1411
// When the angle is less than 90 degrees,
1512
// Then the function should return "Acute angle"
1613

17-
// Identify Obtuse Angles:
14+
// Case 3: Identify Obtuse Angles:
1815
// When the angle is greater than 90 degrees and less than 180 degrees,
1916
// Then the function should return "Obtuse angle"
2017

21-
// Identify Straight Angles:
18+
// Case 4: Identify Straight Angles:
2219
// When the angle is exactly 180 degrees,
2320
// Then the function should return "Straight angle"
2421

25-
// Identify Reflex Angles:
22+
// Case 5: Identify Reflex Angles:
2623
// When the angle is greater than 180 degrees and less than 360 degrees,
2724
// Then the function should return "Reflex angle"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function isProperFraction(numerator, denominator) {
2+
if (numerator < denominator) return true;
3+
// add your completed function from key-implement here
4+
}
5+
6+
module.exports = isProperFraction;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const isProperFraction = require("./2-is-proper-fraction");
2+
3+
test("should return true for a proper fraction", () => {
4+
expect(isProperFraction(2, 3)).toEqual(true);
5+
});
6+
7+
// Case 2: Identify Improper Fractions:
8+
9+
// Case 3: Identify Negative Fractions:
10+
11+
// Case 4: Identify Equal Numerator and Denominator:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function getCardValue(card) {
2+
// replace with your code from key-implement
3+
return 11;
4+
}
5+
module.exports = getCardValue;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const getCardValue = require("./3-get-card-value");
2+
3+
test("should return 11 for Ace of Spades", () => {
4+
const aceofSpades = getCardValue("A♠");
5+
expect(aceofSpades).toEqual(11);
6+
});
7+
8+
// Case 2: Handle Number Cards (2-10):
9+
// Case 3: Handle Face Cards (J, Q, K):
10+
// Case 4: Handle Ace (A):
11+
// Case 5: Handle Invalid Cards:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function countChar(stringOfCharacters, findCharacter) {
2+
return 5
3+
}
4+
5+
module.exports = countChar;

0 commit comments

Comments
 (0)