Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ test("should count multiple occurrences of a character", () => {
});

// Scenario: No Occurrences
test(`should return zero the character doesn't exist in the string`, () => {
const str = "bravo";
const char = "u";
const count = countChar(str, char);
expect(count).toEqual(0);
});

// Empty String
test(`should return zero when the string is empty`, () => {
expect(countChar("", "a")).toEqual(0);
});

// Scenario: Multiple Occurrences
test("should count multiple occurrences of characters (including mixed and case-sensitive)", () => {
expect(countChar("aaaaa", "a")).toEqual(5); // simple multiple
expect(countChar("1-2-3-4-5-", "-")).toEqual(5); // mixed characters
expect(countChar("AaAa", "A")).toEqual(2); // case sensitivity
});

// Given the input string `str`,
// And a character `char` that does not exist within `str`.
// When the function is called with these inputs,
Expand Down
29 changes: 29 additions & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,37 @@ const getOrdinalNumber = require("./get-ordinal-number");
// Case 1: Numbers ending with 1 (but not 11)
// When the number ends with 1, except those ending with 11,
// Then the function should return a string by appending "st" to the number.

test("should append 'st' for numbers ending with 1, except those ending with 11", () => {
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(131)).toEqual("131st");
});

// Case 2: Numbers ending with 2 (but NOT 12)
test("should append 'nd' for numbers ending with 2, except those ending with 12", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
expect(getOrdinalNumber(22)).toEqual("22nd");
expect(getOrdinalNumber(102)).toEqual("102");
});

// Case 3: Numbers ending with 3 (but NOT 13)
test("should append 'rd' for numbers ending with 3, except those ending with 13", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
expect(getOrdinalNumber(33)).toEqual("33rd");
expect(getOrdinalNumber(103)).toEqual("103rd");
});

// Case 4: Numbers ending with 11, 12, or 13 --- 11,12,13,111,121,131,
test("should append 'th' for numbers ending with 11, 12, 13", () => {
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(12)).toEqual("12th");
expect(getOrdinalNumber(13)).toEqual("13th");
});

// Case 5: Numbers ending with larger numbers of 111, 121, 131
test("should append 'th' for numbers ending with 111, 121, 131", () => {
expect(getOrdinalNumber(111)).toEqual("111th");
expect(getOrdinalNumber(121)).toEqual("121th");
expect(getOrdinalNumber(131)).toEqual("131th");
});
2 changes: 1 addition & 1 deletion Sprint-3/2-practice-tdd/repeat-str.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function repeatStr() {
// Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
// The goal is to re-implement that function, not to use it.
return "hellohellohello";
return String.repeat(count);
}

module.exports = repeatStr;
19 changes: 18 additions & 1 deletion Sprint-3/2-practice-tdd/repeat-str.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,39 @@ const repeatStr = require("./repeat-str");

test("should repeat the string count times", () => {
const str = "hello";
const count = 3;
const count = -5;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("hellohellohello");
});

// Case: handle count of 1:
test("should repeat the string count of 1", () => {
const str = "fella";
const count = 1;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("fella");
});

// Given a target string `str` and a `count` equal to 1,
// When the repeatStr function is called with these inputs,
// Then it should return the original `str` without repetition.

// Case: Handle count of 0:
test("should repeat the string count of 0", () => {
const str = "fella";
const count = 0;
const repeatedStr = repeatStr(str, count);
expect(repeatedStr).toEqual("");
});

// Given a target string `str` and a `count` equal to 0,
// When the repeatStr function is called with these inputs,
// Then it should return an empty string.

// Case: Handle negative count:
test(`should throw an error for negative count`, () => {
expect(() => repeatedStr("fella", -2)).toThrowError();
});
// Given a target string `str` and a negative integer `count`,
// When the repeatStr function is called with these inputs,
// Then it should throw an error, as negative counts are not valid.
Loading