Repository navigation
Manchester | 26-ITP-Sep | Salah Alsabhi | Sprint 2 | implement and rewrite tests #1667
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
0b66d44
bcc603b
f8d6b5b
f801388
4327606
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 |
|---|---|---|
| @@ -1,12 +1,40 @@ | ||
| import {getAngleType} from "../implement/1-get-angle-type.js"; | ||
| import assert from "node:assert"; | ||
| import test from "node:test"; | ||
|
|
||
| import { getAngleType } from "../implement/1-get-angle-type.js"; | ||
| test("corrctly get angle type", function(){ | ||
| assert.equal(getAngleType(75), "Acute angle"); | ||
| }); | ||
|
|
||
| test("corrctly get angle type", function(){ | ||
| assert.equal(getAngleType(90), "Right angle"); | ||
| }); | ||
|
|
||
| test("corrctly get angle type", function(){ | ||
| assert.equal(getAngleType(120), "Obtuse angle"); | ||
| }); | ||
|
|
||
| test("corrctly get angle type", function(){ | ||
| assert.equal(getAngleType(180), "Straight angle"); | ||
| }); | ||
|
|
||
| // TODO: Write tests to cover all cases, including boundary and invalid cases. | ||
| // Example: Identify Right Angles | ||
| test("corrctly get angle type", function(){ | ||
| assert.equal(getAngleType(210), "Reflex angle"); | ||
| }); | ||
|
|
||
| test("corrctly get angle type", function(){ | ||
| assert.equal(getAngleType(400), "Invalid angle"); | ||
| }); | ||
|
|
||
| test("corrctly get angle type", function(){ | ||
| assert.equal(getAngleType(0), "Invalid angle"); | ||
| }); | ||
|
|
||
| test("Classifies right angles", () => { | ||
| const right = getAngleType(90); | ||
| assert.equal(right, "Right angle"); | ||
| test("corrctly get angle type", function(){ | ||
| assert.equal(getAngleType(360), "Invalid angle"); | ||
| }); | ||
|
|
||
| test("corrctly get angle type", function(){ | ||
| assert.equal(getAngleType(-70), "Invalid angle"); | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,36 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js"; | |
| // What combinations of numerators and denominators should you test? | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| // Example: 1/2 is a proper fraction | ||
| assert.equal(isProperFraction(1, 2), true); | ||
| }); | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(2, 1), false); | ||
| }); | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(1, 0), false); | ||
| }); | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(0, 1), true); | ||
| }); | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(1, 1), false); | ||
| }); | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(-1, 2), true); | ||
| }); | ||
|
Comment on lines
+29
to
+31
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. Good coverage for positive numbers. However, there should be more test cases for negative numbers. Please add them. Thank you. 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. For positive number cases, you have:
For zero cases, you have:
For mixed of positive and negative numbers, you have (-1, 2) and (1, -2) which means there are two combinations still not tested yet; You are almost there, so just add them back. Please let me know here in the comment if you cannot think of them. Thank you. |
||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(1, -2), true); | ||
| }); | ||
|
|
||
| test("Basic proper fraction", () => { | ||
| assert.equal(isProperFraction(-1, -2), true); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,66 @@ test("Valid single-digit card", () => { | |
| assert.equal(getCardValue("9♠"), 9); | ||
| }); | ||
|
|
||
| test("Valid ten", () => { | ||
| assert.equal(getCardValue("10♥"), 10); | ||
| }); | ||
|
|
||
| test("Ace returns 11", () => { | ||
| assert.equal(getCardValue("A♦"), 11); | ||
| }); | ||
|
|
||
| test("Face cards return 10", () => { | ||
| assert.equal(getCardValue("J♣"), 10); | ||
| assert.equal(getCardValue("Q♠"), 10); | ||
| assert.equal(getCardValue("K♥"), 10); | ||
| }); | ||
|
|
||
| test("Arbitrary non-card string", () => { | ||
| assert.throws(() => getCardValue("invalid"), /Expected a number followed by a suit, but got "invalid"/, "Expected clear error"); | ||
| assert.throws( | ||
| () => getCardValue("invalid"), | ||
| /Expected a number followed by a suit, but got "invalid"/, | ||
| "Expected clear error" | ||
| ); | ||
| }); | ||
|
|
||
| test("Missing suit throws", () => { | ||
| assert.throws(() => getCardValue("A"), /Expected a number followed by a suit/); | ||
| }); | ||
|
|
||
|
|
||
| // TODO: What other invalid card cases can you think of? | ||
|
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. What other invalid card cases can you think of? Please add them. Thank you. |
||
|
|
||
| test("Empty string throws", () => { | ||
| assert.throws( | ||
| () => getCardValue(""), | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| }); | ||
|
|
||
| test("Suit only throws", () => { | ||
| assert.throws( | ||
| () => getCardValue("♠"), | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| }); | ||
|
|
||
| test("Invalid rank throws", () => { | ||
| assert.throws( | ||
| () => getCardValue("1♠"), | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| }); | ||
|
|
||
| test("Invalid suit throws", () => { | ||
| assert.throws( | ||
| () => getCardValue("9X"), | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| }); | ||
|
|
||
| test("Rank with no suit character throws", () => { | ||
| assert.throws( | ||
| () => getCardValue("10"), | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| }); | ||
|
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. While this is correct, I find it may be a bit hard to read. Sometimes using |
|
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. Good coverage of test cases. |
|
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. There should be more test cases for negative numbers. Please add them. Thank you. 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. Same as https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/pull/1667/changes/f8013884556d98db75c28911ac3d769f56cc59c5..432760649a19a4342ba768fe73a20a4ecc485703#r4239273199, and please add the missing test cases. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,45 @@ test(`Should return 11 when given an ace card`, () => { | |
| // please refer to the Jest documentation: | ||
| // https://jestjs.io/docs/expect#tothrowerror | ||
|
|
||
| test(`Should return numeric value for number cards`, () => { | ||
| expect(getCardValue("2♥")).toEqual(2); | ||
| expect(getCardValue("3♠")).toEqual(3); | ||
| expect(getCardValue("4♣")).toEqual(4); | ||
| expect(getCardValue("5♥")).toEqual(5); | ||
| expect(getCardValue("6♦")).toEqual(6); | ||
| expect(getCardValue("7♠")).toEqual(7); | ||
| expect(getCardValue("8♣")).toEqual(8); | ||
| expect(getCardValue("9♠")).toEqual(9); | ||
| expect(getCardValue("10♦")).toEqual(10); | ||
| }); | ||
|
|
||
| test(`Should return 10 for face cards`, () => { | ||
| expect(getCardValue("J♣")).toEqual(10); | ||
| expect(getCardValue("Q♠")).toEqual(10); | ||
| expect(getCardValue("K♥")).toEqual(10); | ||
| }); | ||
|
Comment on lines
+19
to
+35
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. There should be one more special case for valid card. Please add it. Thank you. |
||
|
|
||
| // Invalid cards | ||
| test(`should throw for invalid cards`, () => { | ||
| expect(() => getCardValue("invalid")).toThrow( | ||
| /Expected a number followed by a suit, but got "invalid"/ | ||
| ); | ||
| expect(() => getCardValue("A")).toThrow( | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| expect(() => getCardValue("")).toThrow( | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| expect(() => getCardValue("♠")).toThrow( | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| expect(() => getCardValue("1♠")).toThrow( | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| expect(() => getCardValue("9X")).toThrow( | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| expect(() => getCardValue("10")).toThrow( | ||
| /Expected a number followed by a suit/ | ||
| ); | ||
| }); | ||
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.
There should be two boundary cases for invalid angle. Can you think of them? Please add them back.