-
-
Notifications
You must be signed in to change notification settings - Fork 195
LONDON| MAY 2025 | HAKAN MURAT KAVUT | Module-Structuring-and-Testing-Data - Sprint 3 #611
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
7df63de
160492f
c1a5098
19ff93a
17e9a86
6bfb125
9eae4db
21a6fe1
a6a69ab
dbbdab3
d8d315c
9643e13
58cad7d
f6f291b
94bb164
81bff9c
6dd1aa9
5f4d25e
476b8aa
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,14 @@ | ||
for (let a = 1; a <= 9; a++) { | ||
for (let b = 0; b <= 9; b++) { | ||
for (let c = 1; c <= 9; c++) { | ||
for (let d = 0; d <= 9; d++) { | ||
let left = Math.pow(a, b) * Math.pow(c, d); | ||
let right = parseInt(`${a}${b}${c}${d}`); | ||
|
||
if (left === right) { | ||
console.log(`Match found: (${a}^${b}) * (${c}^${d}) = ${left}`); | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function transposeTwoStrings(array) { | ||
let a = ""; | ||
let no = Math.max(array[0].length, array[1].length); | ||
for (let i = 0; i < no; i++) { | ||
if (i < array[0].length) { | ||
a += array[0][i]; | ||
} else a += " "; | ||
a += " "; | ||
if (i < array[1].length) { | ||
a += array[1][i]; | ||
} else a += " "; | ||
if (i < array[1].length - 1 || i < array[0].length - 1) a += "\n"; | ||
} | ||
|
||
return a; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
|
||
if (angle < 90) return "Acute angle"; | ||
if (angle > 90 && angle < 180) return "Obtuse angle"; | ||
if (angle === 180) return "Straight angle"; | ||
if (angle > 180 && angle < 360) return "Reflex angle"; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// Don't get bogged down in this detail | ||
// Jest uses CommonJS module syntax by default as it's quite old | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
// we have just written the CommonJS module.exports syntax for you | ||
module.exports = getAngleType; | ||
module.exports = getAngleType; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (Math.abs(numerator) < Math.abs(denominator)) return true; | ||
if (Math.abs(numerator) > Math.abs(denominator)) return true; | ||
if (Math.abs(numerator) === Math.abs(denominator)) return true; | ||
Comment on lines
+2
to
+4
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. In mathematics, -A/B == A/-B == -(A/B), and -A/-B == A/B for any integers A and B (B ≠ 0). The function is supposed to return |
||
} | ||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,16 @@ test("should return true for a proper fraction", () => { | |
}); | ||
|
||
// Case 2: Identify Improper Fractions: | ||
test("should return true for a improper fraction", () => { | ||
expect(isProperFraction(5, 2)).toEqual(true); | ||
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. "Identify improper fractions" means, "should return |
||
}); | ||
|
||
// Case 3: Identify Negative Fractions: | ||
test("should return true for a negative fraction", () => { | ||
expect(isProperFraction(-4, 7)).toEqual(true); | ||
}); | ||
|
||
// Case 4: Identify Equal Numerator and Denominator: | ||
test("should return true for a equal fraction", () => { | ||
expect(isProperFraction(3, 3)).toEqual(true); | ||
}); | ||
Comment on lines
+18
to
+20
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. 3/3 is an improper fraction, so the function is expected to return |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
let rank = card[0]; | ||
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.
|
||
if (rank === "A") return 11; | ||
if (rank === "J" || rank === "Q" || rank === "K") return 10; | ||
if (Number(card[0]) > 0 && Number(card[0]) < 11) return Number(card[0]); | ||
return "Invalid card rank."; | ||
} | ||
module.exports = getCardValue; | ||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
|
||
// Case 2: Handle Number Cards (2-10): | ||
test("should return number for card number bw 2-10", () => { | ||
const fiveofHearts = getCardValue("5♥"); | ||
expect(fiveofHearts).toEqual(5); | ||
}); | ||
// Case 3: Handle Face Cards (J, Q, K): | ||
test("should return number for face of cards", () => { | ||
const faceofHearts = getCardValue("J♥"); | ||
expect(faceofHearts).toEqual(10); | ||
}); | ||
// Case 4: Handle Ace (A): | ||
test("should return number for face of cards", () => { | ||
const aceofHearts = getCardValue("A♥"); | ||
expect(aceofHearts).toEqual(11); | ||
}); | ||
// Case 5: Handle Invalid Cards: | ||
test("should return number for face of cards", () => { | ||
const invalidCard = getCardValue("C♥"); | ||
expect(invalidCard).toEqual("Invalid card rank."); | ||
}); | ||
Comment on lines
+24
to
+27
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. Does your function return the value you expected from each of the following function calls?
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
if (!stringOfCharacters.includes(findCharacter)) { | ||
return "No occurrence"; | ||
} | ||
Comment on lines
+2
to
+4
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. When a function can return different types of value, it will make consuming the return value inconvenience. For example, let Can you think of a better value to return when |
||
|
||
let count = 0; | ||
for (let char of stringOfCharacters) { | ||
if (char === findCharacter) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
|
||
module.exports = countChar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
if (num % 10 ==1 && num % 100 !=11 ) | ||
return "1st"; | ||
if (num % 10 ==2 && num % 100 !=12 ) | ||
return "2nd"; | ||
if (num % 10 ==3 && num % 100 !=13 ) | ||
return "3rd"; | ||
return "th" | ||
} | ||
|
||
module.exports = getOrdinalNumber; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,21 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
test("should return '1st' for 1", () => { | ||
expect(getOrdinalNumber(1)).toEqual("1st"); | ||
}); | ||
test("should return '2nd' for 2", () => { | ||
expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
}); | ||
Comment on lines
+14
to
+16
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. To ensure thorough testing, we need broad scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases. For example, we can prepare a test for numbers 2, 22, 132, etc. as
You may also discover a bug in your implementation when you test your function using more samples. |
||
test("should return '3rd' for 3", () => { | ||
expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
}); | ||
test("should return 'th' for 11", () => { | ||
expect(getOrdinalNumber(11)).toEqual("th"); | ||
}); | ||
test("should return 'th' for 12", () => { | ||
expect(getOrdinalNumber(12)).toEqual("th"); | ||
}); | ||
test("should return 'th' for 13", () => { | ||
expect(getOrdinalNumber(13)).toEqual("th"); | ||
Comment on lines
+20
to
+27
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. We could also specify these tests under the category, "should append 'th' for numbers ending in 11, 12, 13". |
||
}); | ||
test("should return 'th' for 4", () => { | ||
expect(getOrdinalNumber(4)).toEqual("th"); | ||
Comment on lines
+29
to
+30
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. We could generalise this test to, "should append 'th' for numbers ending in 0, 4-9". |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
function repeat(str, count) { | ||
|
||
if (Number(count) > 1) { | ||
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. Why do you explicitly convert |
||
let result="" | ||
for (let i = 0; i <= count-1; i++) { | ||
result += str; | ||
} | ||
return result; | ||
} | ||
if (count == 1) return str; | ||
if (count == 0) return ""; | ||
return "Negative counts are not valid."; | ||
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. How would the caller distinguish the result of the following two function calls?
Both function calls return the same value. |
||
} | ||
|
||
module.exports = repeat; | ||
module.exports = repeat; |
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.
The spec isn't clear whether
angle
can be assigned a number not in the interval (0, 360).When
angle
is >= 360, what should the function return? (Also, by definition, angles <= 0 are not considered acute angles.)When we implement a function that can return a value, to ensure reliability, we should ensure it will always return a defined value instead of
undefined
(which represents "no return value").If the parameter,
angle
, is not within the recognised range, we can design the function to return a special value (e.g., "Invalid angle") or throw an error.