Skip to content

Commit 7795cdb

Browse files
committed
all changes are done
1 parent ce61aaf commit 7795cdb

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
function countChar(stringOfCharacters, findCharacter) {
2+
// stringOfCharacters and findCharacter both should be string.
23
if (
34
typeof stringOfCharacters !== "string" ||
45
typeof findCharacter !== "string"
56
) {
6-
return 0;
7+
return "Values Can not be Numbers";
78
}
9+
10+
// stringOfCharacters should be longer than findCharacter.
11+
if (
12+
stringOfCharacters.length !== 0 &&
13+
findCharacter.length > stringOfCharacters.length
14+
) {
15+
return "the stringOfCharacters MUST be lonegr than findingcharacter";
16+
}
17+
18+
//stringOfCharacters shoud not be empty
19+
if (stringOfCharacters.length === 0) {
20+
return "stringOfCharacters can not be empty";
21+
}
22+
23+
//findCharacter should not be empty
24+
if (findCharacter.length === 0) {
25+
return "findCharacter can not be empty";
26+
}
27+
28+
// finscharatcter should be single character.
829
if (findCharacter.length !== 1) {
9-
return 0;
30+
return "findCharacter must be a single character";
1031
}
1132

1233
let count = 0;

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,45 +63,47 @@ test("should return 0 when the 'c' does not exist in string 'I dont have an appl
6363
// When the function is called,
6464
// Then it should return 0 because a multi-character string cannot match a single character position.
6565

66-
test("should return 0 when findCharacter is longer than the input string", () => {
66+
test("should return a message when findCharacter is longer than the input string", () => {
6767
const str = "a";
6868
const char = "abc";
6969
const count = countChar(str, char);
70-
expect(count).toEqual(0);
70+
expect(count).toEqual(
71+
"the stringOfCharacters MUST be lonegr than findingcharacter"
72+
);
7173
});
7274

7375
// Scenario: Empty string input
7476
// Given an empty input string and a valid character,
7577
// When the function is called,
7678
// Then it should return 0 because there are no characters to search.
7779

78-
test("should return 0 when input string is empty", () => {
80+
test("should return a Message when input stringOfCharacters is empty", () => {
7981
const str = "";
8082
const char = "a";
8183
const count = countChar(str, char);
82-
expect(count).toEqual(0);
83-
});
84-
85-
// Scenario: Non-string input type
86-
// Given that one or both inputs are not strings (e.g., number, array),
87-
// When the function is called,
88-
// Then it should return 0 or handle the input gracefully without throwing an error.
89-
90-
test("should return 0 when inputs are not strings", () => {
91-
const str = 12345;
92-
const char = 1;
93-
const count = countChar(str, char);
94-
expect(count).toEqual(0);
84+
expect(count).toEqual("stringOfCharacters can not be empty");
9585
});
9686

9787
// Scenario: Empty findCharacter
9888
// Given a valid string but an empty findCharacter,
9989
// When the function is called,
10090
// Then it should return 0 because an empty search target is not valid.
10191

102-
test("should return 0 when findCharacter is an empty string", () => {
92+
test("should return message when findCharacter is an empty string", () => {
10393
const str = "hello";
10494
const char = "";
10595
const count = countChar(str, char);
106-
expect(count).toEqual(0);
96+
expect(count).toEqual("findCharacter can not be empty");
97+
});
98+
99+
// Scenario: Non-string input type
100+
// Given that one or both inputs are not strings (e.g., number, array),
101+
// When the function is called,
102+
// Then it should return 0 or handle the input gracefully without throwing an error.
103+
104+
test("should return message when inputs are numbers", () => {
105+
const str = 12345;
106+
const char = 1;
107+
const count = countChar(str, char);
108+
expect(count).toEqual("Values Can not be Numbers");
107109
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function getOrdinalNumber(number) {
22
// Handle invalid inputs
33
if (typeof number !== "number" || !Number.isFinite(number)) {
4-
return "Invalid input";
4+
return "Invalid input : Expected a infinit number";
55
}
66

77
// Handle zero or negative numbers (optional)

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@ test("should return '23rd' for 23", () => {
7373
// Then the function should return "Invalid input"
7474

7575
test("should return 'Invalid input' when input is undefined", () => {
76-
expect(getOrdinalNumber(undefined)).toEqual("Invalid input");
76+
expect(getOrdinalNumber(undefined)).toEqual(
77+
"Invalid input : Expected a infinit number"
78+
);
7779
});
7880

7981
// Case null :
8082
// When the nymber is null ,
8183
// Then the function should return "Invalid input"
8284

8385
test("should return 'Invalid input' when input is null", () => {
84-
expect(getOrdinalNumber(null)).toEqual("Invalid input");
86+
expect(getOrdinalNumber(null)).toEqual(
87+
"Invalid input : Expected a infinit number"
88+
);
8589
});
8690

8791
// Case negetive number :
@@ -97,5 +101,7 @@ test("should return '-1th' for -1", () => {
97101
// Then the function should return "Invalid input"
98102

99103
test("should return 'Invalid input' when input is NaN", () => {
100-
expect(getOrdinalNumber(NaN)).toEqual("Invalid input");
104+
expect(getOrdinalNumber(NaN)).toEqual(
105+
"Invalid input : Expected a infinit number"
106+
);
101107
});

0 commit comments

Comments
 (0)