-
-
Notifications
You must be signed in to change notification settings - Fork 275
Coursework/sprint 3 implement and rewrite ci setup #841
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
1ee1bc0
17de75c
0db0719
58b4b7e
0e18f06
2755b3f
014892f
ccb6ce8
8ce85d7
b2e3abd
44763ba
b456bfa
3d6c27b
a2d1fe8
dfeb4c7
f865f19
2ea8581
0cccc97
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,39 @@ | ||
| name: Test Coverage Report | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| push: | ||
| branches: | ||
| - 'coursework/sprint-3-implement-and-rewrite*' | ||
|
|
||
| jobs: | ||
| test-coverage: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Run Inline Assertion Tests & Verify Parity | ||
| run: ./scripts/run-inline-tests.sh | ||
|
|
||
| - name: Run Jest Tests with Coverage | ||
| run: npx jest --config=jest.config.jest-tests.js --coverage --ci --json --testLocationInResults --outputFile=report.json | ||
|
|
||
| - name: Jest Coverage Report | ||
| uses: ArtiomTr/jest-coverage-report-action@v2 | ||
| if: always() | ||
| with: | ||
| coverage-file: ./report.json | ||
| base-coverage-file: ./report.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,18 @@ | |
| // write one test at a time, and make it pass, build your solution up methodically | ||
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| if (numerator < denominator) { | ||
|
Author
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. Rollback original file |
||
| if (Math.abs(numerator) < Math.abs(denominator)) { | ||
| return true; | ||
| } | ||
| if (numerator >= denominator) { | ||
| return false; | ||
| } | ||
| if(numerator == 0 && denominator !== 0){ | ||
| return true; | ||
| } | ||
| if (denominator === 0) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // The line below allows us to load the isProperFraction function into tests in other files. | ||
|
|
@@ -47,13 +56,48 @@ assertEquals(improperFraction, false); | |
| // 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. | ||
| const negativeFraction = isProperFraction(-4, 7); | ||
| // ====> complete with your assertion | ||
|
|
||
| assertEquals(negativeFraction, true); | ||
| // Equal Numerator and Denominator check: | ||
| // Input: numerator = 3, denominator = 3 | ||
| // target output: false | ||
| // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. | ||
| const equalFraction = isProperFraction(3, 3); | ||
| // ====> complete with your assertion | ||
|
|
||
| assertEquals(equalFraction, false); | ||
| // Stretch: | ||
| // What other scenarios could you test for? | ||
| // Zero Numerator check: | ||
| // Input: numerator = 0, denominator = 5 | ||
| // target output: true | ||
| // Explanation: The fraction 0/5 is a proper fraction because the numerator (0) is less than the denominator (5). The function should return true. | ||
| const zeroNumerator = isProperFraction(0, 5); | ||
| // ====> complete with your assertion | ||
| assertEquals(zeroNumerator, true); | ||
| // Zero Denominator check: | ||
| // Input: numerator = 4, denominator = 0 | ||
| // target output: false | ||
| // Explanation: The fraction 4/0 is undefined because division by zero is not allowed. The function should return false. | ||
| const zeroDenominator = isProperFraction(4, 0); | ||
| // ====> complete with your assertion | ||
| assertEquals(zeroDenominator, false); | ||
| // Negative Denominator check: | ||
| // Input: numerator = 3, denominator = -5 | ||
| // target output: true | ||
| // Explanation: The fraction 3/-5 is a proper fraction because the absolute value of the numerator (3) is less than the absolute value of the denominator (5). The function should return true. | ||
| const negativeDenominator = isProperFraction(3, -5); | ||
| // ====> complete with your assertion | ||
| assertEquals(negativeDenominator, true); | ||
| // Both Negative check: | ||
| // Input: numerator = -2, denominator = -6 | ||
| // target output: true | ||
| // Explanation: The fraction -2/-6 is a proper fraction because the absolute value of the numerator (2) is less than the absolute value of the denominator (6). The function should return true. | ||
| const bothNegative = isProperFraction(-2, -6); | ||
| // ====> complete with your assertion | ||
| assertEquals(bothNegative, true); | ||
| // Zero Numerator and Denominator check: | ||
| // Input: numerator = 0, denominator = 0 | ||
| // target output: false | ||
| // Explanation: The fraction 0/0 is undefined. The function should return false. | ||
| const zeroNumeratorDenominator = isProperFraction(0, 0); | ||
| // ====> complete with your assertion | ||
| assertEquals(zeroNumeratorDenominator, false); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,32 @@ | |
| // write one test at a time, and make it pass, build your solution up methodically | ||
| // just make one change at a time -- don't rush -- programmers are deep and careful thinkers | ||
| function getCardValue(card) { | ||
| if (rank === "A") { | ||
|
Author
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. Rollback original file |
||
| return 11; | ||
| const rank = card.slice(0,-1) | ||
| const suit = card.slice(-1) | ||
| if (!["♠","♥","♦","♣"].includes(suit)) { | ||
| return "Invalid card rank."; | ||
| } | ||
| switch(rank) { | ||
| case "2": | ||
| case "3": | ||
| case "4": | ||
| case "5": | ||
| case "6": | ||
| case "7": | ||
| case "8": | ||
| case "9": | ||
| return parseInt(rank); | ||
| case "10": | ||
| case "J": | ||
| case "Q": | ||
| case "K": | ||
| return 10; | ||
| case "A": | ||
| return 11; | ||
| default: | ||
| return "Invalid card rank."; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
|
|
@@ -40,18 +63,36 @@ assertEquals(aceofSpades, 11); | |
| // Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). | ||
| const fiveofHearts = getCardValue("5♥"); | ||
| // ====> write your test here, and then add a line to pass the test in the function above | ||
|
|
||
| assertEquals(fiveofHearts, 5); | ||
| // Handle Face Cards (J, Q, K): | ||
| // Given a card with a rank of "10," "J," "Q," or "K", | ||
| // When the function is called with such a card, | ||
| // Then it should return the value 10, as these cards are worth 10 points each in blackjack. | ||
| const kingofDiamonds = getCardValue("K♦"); | ||
| assertEquals(kingofDiamonds, 10); | ||
|
|
||
| const tenofClubs = getCardValue("10♣"); | ||
| assertEquals(tenofClubs, 10); | ||
|
|
||
| // Handle Ace (A): | ||
| // Given a card with a rank of "A", | ||
| // When the function is called with an Ace, | ||
| // Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. | ||
|
|
||
| const aceofHearts = getCardValue("A♥"); | ||
| assertEquals(aceofHearts, 11); | ||
| // Handle Invalid Cards: | ||
| // Given a card with an invalid rank (neither a number nor a recognized face card), | ||
| // When the function is called with such a card, | ||
| // Then it should throw an error indicating "Invalid card rank." | ||
|
|
||
| const invalidCard = getCardValue("1♠"); | ||
| assertEquals(invalidCard, "Invalid card rank."); | ||
|
|
||
| const invalidCard2 = getCardValue("B♦"); | ||
| assertEquals(invalidCard2, "Invalid card rank."); | ||
|
|
||
| const invalidCard3 = getCardValue("11"); | ||
| assertEquals(invalidCard3, "Invalid card rank."); | ||
|
|
||
| const invalidCard4 = getCardValue("3😄"); | ||
| assertEquals(invalidCard4, "Invalid card rank."); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,15 +12,25 @@ test("should identify right angle (90°)", () => { | |
| // Case 2: Identify Acute Angles: | ||
|
Author
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. Rollback original file |
||
| // When the angle is less than 90 degrees, | ||
| // Then the function should return "Acute angle" | ||
| test("should identify acute angle (<90°)", () => { | ||
| expect(getAngleType(45)).toEqual("Acute angle"); | ||
| }); | ||
|
|
||
| // Case 3: Identify Obtuse Angles: | ||
| // When the angle is greater than 90 degrees and less than 180 degrees, | ||
| // Then the function should return "Obtuse angle" | ||
|
|
||
| test("should identify obtuse angle (>90° and <180°)", () => { | ||
| expect(getAngleType(120)).toEqual("Obtuse angle"); | ||
| }); | ||
| // Case 4: Identify Straight Angles: | ||
| // When the angle is exactly 180 degrees, | ||
| // Then the function should return "Straight angle" | ||
|
|
||
| test("should identify straight angle (180°)", () => { | ||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
| }); | ||
| // Case 5: Identify Reflex Angles: | ||
| // When the angle is greater than 180 degrees and less than 360 degrees, | ||
| // Then the function should return "Reflex angle" | ||
| test("should identify reflex angle (>180° and <360°)", () => { | ||
| expect(getAngleType(270)).toEqual("Reflex angle"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,30 @@ test("should return true for a proper fraction", () => { | |
| }); | ||
|
Author
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. Rollback original file |
||
|
|
||
| // Case 2: Identify Improper Fractions: | ||
| test("should return false for an improper fraction", () => { | ||
| expect(isProperFraction(5, 2)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 3: Identify Negative Fractions: | ||
|
|
||
| test("should return true for a negative proper fraction", () => { | ||
| expect(isProperFraction(-4, 7)).toEqual(true); | ||
| }); | ||
| // Case 4: Identify Equal Numerator and Denominator: | ||
| test("should return false when numerator equals denominator", () => { | ||
| expect(isProperFraction(3, 3)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 5: Zero Numerator: | ||
| test("should return true for zero numerator", () => { | ||
| expect(isProperFraction(0, 5)).toEqual(true); | ||
| }); | ||
|
|
||
| // Case 6: Zero Denominator: | ||
| test("should return false for zero denominator", () => { | ||
| expect(isProperFraction(4, 0)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 7: Negative Denominator: | ||
| test("should return true for negative denominator", () => { | ||
| expect(isProperFraction(3, -5)).toEqual(true); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,27 @@ test("should return 11 for Ace of Spades", () => { | |
| }); | ||
|
|
||
| // Case 2: Handle Number Cards (2-10): | ||
|
Author
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. Rollback original file |
||
| test("should return correct value for number cards", () => { | ||
| expect(getCardValue("2♣")).toEqual(2); | ||
| expect(getCardValue("5♦")).toEqual(5); | ||
| expect(getCardValue("10♥")).toEqual(10); | ||
| }) | ||
| // Case 3: Handle Face Cards (J, Q, K): | ||
| test("should return 10 for face cards", () => { | ||
| expect(getCardValue("J♣")).toEqual(10); | ||
| expect(getCardValue("Q♦")).toEqual(10); | ||
| expect(getCardValue("K♥")).toEqual(10); | ||
| }) | ||
| // Case 4: Handle Ace (A): | ||
| test("should return 11 for Ace cards", () => { | ||
| expect(getCardValue("A♣")).toEqual(11); | ||
| expect(getCardValue("A♦")).toEqual(11); | ||
| expect(getCardValue("A♥")).toEqual(11); | ||
| }) | ||
| // Case 5: Handle Invalid Cards: | ||
| test("should return Invalid card rank for invalid cards", () => { | ||
| expect(getCardValue("1♣")).toEqual("Invalid card rank."); | ||
| expect(getCardValue("11♦")).toEqual("Invalid card rank."); | ||
| expect(getCardValue("3")).toEqual("Invalid card rank."); | ||
| expect(getCardValue("3😄")).toEqual("Invalid card rank."); | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| module.exports = { | ||
| displayName: "Jest Tests", | ||
| testMatch: ["**/rewrite-tests-with-jest/**/*.test.js"], | ||
| collectCoverage: true, | ||
| coverageDirectory: "coverage/jest-tests", | ||
| collectCoverageFrom: [ | ||
| "Sprint-3/1-implement-and-rewrite-tests/implement/*.js", | ||
| "!Sprint-3/1-implement-and-rewrite-tests/implement/*.test.js", | ||
| ], | ||
| coveragePathIgnorePatterns: [ | ||
| "/node_modules/", | ||
| ], | ||
| coverageReporters: ["text", "lcov", "json-summary", "html"], | ||
| coverageThreshold: { | ||
| global: { | ||
| branches: 40, | ||
| functions: 100, // Every function must be tested | ||
| lines: 40, | ||
| statements: 40, | ||
| }, | ||
| }, | ||
| }; |
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.
Rollback roiginal file