Skip to content

Commit f1b775f

Browse files
committed
restored 2-practice-tdd
1 parent 3889214 commit f1b775f

File tree

9 files changed

+34
-205
lines changed

9 files changed

+34
-205
lines changed

Sprint-3/2-practice-tdd/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Write the tests _before_ the code that will make them pass.
99
Recommended order:
1010

1111
1. `count.test.js`
12-
1. `repeat-str.test.js`
12+
1. `repeat.test.js`
1313
1. `get-ordinal-number.test.js`

Sprint-3/2-practice-tdd/count.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,3 @@ function countChar(stringOfCharacters, findCharacter) {
33
}
44

55
module.exports = countChar;
6-
7-
const countChar = require('../countChar');
8-
9-
describe('countChar()', () => {
10-
test('always returns 5', () => {
11-
expect(countChar('anything', 'a')).toBe(5);
12-
});
13-
14-
test('still returns 5 with empty string', () => {
15-
expect(countChar('', 'z')).toBe(5);
16-
});
17-
18-
test('still returns 5 with special characters', () => {
19-
expect(countChar('!!!', '!')).toBe(5);
20-
});
21-
});

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
// implement a function countChar that counts the number of times a character occurs in a string
22
const countChar = require("./count");
3-
4-
function countChar(stringOfCharacters, findCharacter) {
5-
let count = 0;
6-
for (let char of stringOfCharacters) {
7-
if (char === findCharacter) count++;
8-
}
9-
return count;
10-
}
11-
12-
module.exports = countChar;
13-
143
// Given a string str and a single character char to search for,
154
// When the countChar function is called with these inputs,
165
// Then it should:
@@ -27,36 +16,6 @@ test("should count multiple occurrences of a character", () => {
2716
const count = countChar(str, char);
2817
expect(count).toEqual(5);
2918
});
30-
test("should return 0 when the character is not found", () => {
31-
const str = "hello";
32-
const char = "z";
33-
const count = countChar(str, char);
34-
expect(count).toEqual(0);
35-
});
36-
37-
// Scenario: Case Sensitivity
38-
// It should be case-sensitive, meaning 'A' != 'a'.
39-
test("should be case-sensitive when counting characters", () => {
40-
const str = "Banana";
41-
expect(countChar(str, "a")).toEqual(3);
42-
expect(countChar(str, "A")).toEqual(0);
43-
});
44-
45-
// Scenario: Empty String
46-
// It should return 0 when the input string is empty.
47-
test("should return 0 when the input string is empty", () => {
48-
const str = "";
49-
const char = "a";
50-
const count = countChar(str, char);
51-
expect(count).toEqual(0);
52-
});
53-
54-
// Scenario: Special Characters
55-
// It should correctly count spaces and punctuation.
56-
test("should count special characters like spaces or punctuation", () => {
57-
expect(countChar("a b a b", " ")).toEqual(2);
58-
expect(countChar("wow!!!", "!")).toEqual(3);
59-
});
6019

6120
// Scenario: No Occurrences
6221
// Given the input string str,
Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,5 @@
1-
21
function getOrdinalNumber(num) {
3-
const remainder10 = num % 10;
4-
const remainder100 = num % 100;
5-
6-
if (remainder100 >= 11 && remainder100 <= 13) {
7-
return `${num}th`;
8-
}
9-
10-
switch (remainder10) {
11-
case 1:
12-
return `${num}st`;
13-
case 2:
14-
return `${num}nd`;
15-
case 3:
16-
return `${num}rd`;
17-
default:
18-
return `${num}th`;
19-
}
2+
return "1st";
203
}
214

225
module.exports = getOrdinalNumber;
23-
24-
25-
const getOrdinalNumber = require("./getOrdinalNumber");
26-
27-
describe("getOrdinalNumber()", () => {
28-
test("should return '1st' for 1", () => {
29-
expect(getOrdinalNumber(1)).toBe("1st");
30-
});
31-
32-
test("should return '2nd' for 2", () => {
33-
expect(getOrdinalNumber(2)).toBe("2nd");
34-
});
35-
36-
test("should return '3rd' for 3", () => {
37-
expect(getOrdinalNumber(3)).toBe("3rd");
38-
});
39-
40-
test("should return '4th' for 4", () => {
41-
expect(getOrdinalNumber(4)).toBe("4th");
42-
});
43-
44-
test("should return '11th', '12th', '13th' for special cases", () => {
45-
expect(getOrdinalNumber(11)).toBe("11th");
46-
expect(getOrdinalNumber(12)).toBe("12th");
47-
expect(getOrdinalNumber(13)).toBe("13th");
48-
});
49-
50-
test("should return correct suffixes for 21, 22, 23", () => {
51-
expect(getOrdinalNumber(21)).toBe("21st");
52-
expect(getOrdinalNumber(22)).toBe("22nd");
53-
expect(getOrdinalNumber(23)).toBe("23rd");
54-
});
55-
56-
test("should return '111th' for numbers ending with 11, 12, 13 even if larger", () => {
57-
expect(getOrdinalNumber(111)).toBe("111th");
58-
expect(getOrdinalNumber(112)).toBe("112th");
59-
expect(getOrdinalNumber(113)).toBe("113th");
60-
});
61-
});

Sprint-3/2-practice-tdd/get-ordinal-number.test.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
const getOrdinalNumber = require("./get-ordinal-number");
2-
3-
function getOrdinalNumber(num) {
4-
return "1st";
5-
}
6-
7-
module.exports = getOrdinalNumber;
8-
92
// In this week's prep, we started implementing getOrdinalNumber
103

114
// continue testing and implementing getOrdinalNumber for additional cases

Sprint-3/2-practice-tdd/repeat-str.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

Sprint-3/2-practice-tdd/repeat-str.test.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

Sprint-3/2-practice-tdd/repeat.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
const repeat = require("./repeat");
2-
31
function repeat() {
42
return "hellohellohello";
53
}
64

75
module.exports = repeat;
8-
9-
test("should repeat the given word three times", () => {
10-
expect(repeat("hi", 3)).toBe("hihihi");
11-
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Implement a function repeat
2+
const repeat = require("./repeat");
3+
// Given a target string str and a positive integer count,
4+
// When the repeat function is called with these inputs,
5+
// Then it should:
6+
7+
// case: repeat String:
8+
// Given a target string str and a positive integer count,
9+
// When the repeat function is called with these inputs,
10+
// Then it should repeat the str count times and return a new string containing the repeated str values.
11+
12+
test("should repeat the string count times", () => {
13+
const str = "hello";
14+
const count = 3;
15+
const repeatedStr = repeat(str, count);
16+
expect(repeatedStr).toEqual("hellohellohello");
17+
});
18+
19+
// case: handle Count of 1:
20+
// Given a target string str and a count equal to 1,
21+
// When the repeat function is called with these inputs,
22+
// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
23+
24+
// case: Handle Count of 0:
25+
// Given a target string str and a count equal to 0,
26+
// When the repeat function is called with these inputs,
27+
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
28+
29+
// case: Negative Count:
30+
// Given a target string str and a negative integer count,
31+
// When the repeat function is called with these inputs,
32+
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.

0 commit comments

Comments
 (0)