Skip to content

Commit dad6802

Browse files
committed
fixed commentarios and funcionality in thes and functions
1 parent d06f31f commit dad6802

File tree

4 files changed

+46
-39
lines changed

4 files changed

+46
-39
lines changed

Sprint-3/revise/implement/password-validator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ function passwordValidation(password, passwords) {
5050
}
5151

5252
module.exports = passwordValidation;
53+

Sprint-3/revise/implement/password-validator.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const passwordValidation = require("./password-validator"); // Corrected import
1+
const passwordValidation = require("./password-validator");
22

33
describe("Password Validation", () => {
44
const existingPasswords = ["previousPass1", "previousPass2", "etetet"];

Sprint-3/revise/implement/repeat.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,49 @@
2424
// When the repeat function is called with these inputs,
2525
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
2626

27+
// function repeatString(str, count) {
28+
// let newWords = "";
29+
// //if count is greater than 1 if so repeat string count times
30+
// //else if count is 1 return the string
31+
// //else if count is 0 return empty string
32+
// //else if count is negative return error
33+
// if (count > 1) {
34+
// for (let i = 0; i < count; i++) {
35+
// newWords += str + " ";
36+
// }
37+
// return newWords.trimEnd();
38+
// }
39+
// // Si count === 1,
40+
// else if (count === 1) {
41+
// return str;
42+
// }
43+
// // Si count === 0,
44+
// else if (count === 0) {
45+
// return "";
46+
// }
47+
// // Si count < 0,
48+
// else if (count < 0) {
49+
// return "error your number is negative";
50+
// }
51+
// }
52+
53+
2754
function repeatString(str, count) {
28-
let newWords = "";
29-
//if count is greater than 1 if so repeat string count times
30-
//else if count is 1 return the string
31-
//else if count is 0 return empty string
32-
//else if count is negative return error
33-
if (count > 1) {
55+
if (count < 0) {
56+
throw new Error("Count cannot be negative");
57+
}
58+
if (count > 1) {
59+
let newWords = "";
3460
for (let i = 0; i < count; i++) {
3561
newWords += str + " ";
3662
}
3763
return newWords.trimEnd();
38-
}
39-
// Si count === 1, retorna el string original
40-
else if (count === 1) {
64+
} else if (count === 1) {
4165
return str;
42-
}
43-
// Si count === 0, retorna una cadena vacía
44-
else if (count === 0) {
66+
} else if (count === 0) {
4567
return "";
4668
}
47-
// Si count < 0, retorna un mensaje de error
48-
else if (count < 0) {
49-
return "error your number is negative";
50-
}
5169
}
5270

71+
5372
module.exports = repeatString;
Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,19 @@
11
const repeatString = require("./repeat");
22

3-
function assertEquals(actualOutput, targetOutput) {
4-
console.assert(
5-
actualOutput === targetOutput,
6-
`Expected "${actualOutput}" to equal "${targetOutput}"`
7-
);
8-
}
9-
10-
describe("repeatString Function Tests", () => {
11-
test("Repeats string 3 times", () => {
12-
const result = repeatString("hello", 3);
13-
assertEquals(result, "hello hello hello");
3+
describe("Repeat String Function", () => {
4+
test("should return repeated string if count is greater than 1", () => {
5+
expect(repeatString("Hello", 3)).toEqual("Hello Hello Hello");
146
});
157

16-
test("Repeats string 1 time", () => {
17-
const result = repeatString("world", 1);
18-
assertEquals(result, "world");
8+
test("should return the string if count is 1", () => {
9+
expect(repeatString("Hello", 1)).toEqual("Hello");
1910
});
2011

21-
test("Repeats string 0 times", () => {
22-
const result = repeatString("test", 0);
23-
assertEquals(result, "");
12+
test("should return empty string if count is 0", () => {
13+
expect(repeatString("Hello", 0)).toEqual("");
2414
});
2515

26-
test("Handles negative count", () => {
27-
const result = repeatString("errorTest", -2);
28-
assertEquals(result, "error your number is negative");
16+
test("should return an error message if count is negative", () => {
17+
expect(() => repeatString("test", -1)).toThrow("Count cannot be negative");
2918
});
3019
});
31-
32-
console.log("All test cases executed!");

0 commit comments

Comments
 (0)