Skip to content

Commit 44f82e5

Browse files
committed
feature: full rewrite of unit tests
1 parent 42d17c0 commit 44f82e5

24 files changed

+743
-756
lines changed

tests/.eslintrc

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

tests/ayaStringSplitter.spec.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
import { ayaStringSplitter } from "../src/ayaStringSplitter";
1+
import { ayaStringSplitter } from "../src/ayaStringSplitter"
22

33
describe("ayaStringSplitter", () => {
4-
it("basic tests", () => {
5-
expect(ayaStringSplitter("1:1")).toEqual([1, 1])
6-
expect(ayaStringSplitter("1:1-5")).toEqual([1, [1, 5]])
7-
expect(ayaStringSplitter("114:1")).toEqual([114, 1])
8-
// expect(ayaStringSplitter("115:1")).toEqual([115,1])
9-
})
10-
11-
it("error checks", () => {
12-
expect(() => ayaStringSplitter("1")).toThrow()
13-
expect(() => ayaStringSplitter("")).toThrow()
14-
expect(() => ayaStringSplitter("sdsgw")).toThrow()
15-
expect(() => ayaStringSplitter("sd:sgw")).toThrow()
16-
expect(() => ayaStringSplitter("34:sgw")).toThrow()
17-
})
18-
19-
it("handles single-digit sura and aya numbers", () => {
20-
expect(ayaStringSplitter("2:3")).toEqual([2, 3]);
21-
expect(ayaStringSplitter("9:5")).toEqual([9, 5]);
22-
});
23-
24-
it("handles multi-digit sura and aya numbers", () => {
25-
expect(ayaStringSplitter("110:3")).toEqual([110, 3]);
26-
expect(ayaStringSplitter("2:255")).toEqual([2, 255]);
27-
});
28-
29-
it("handles aya ranges with multi-digit numbers", () => {
30-
expect(ayaStringSplitter("7:26-30")).toEqual([7, [26, 30]]);
31-
expect(ayaStringSplitter("18:1-10")).toEqual([18, [1, 10]]);
32-
});
33-
34-
it("throws error for invalid sura numbers", () => {
35-
expect(() => ayaStringSplitter("0:1")).toThrow();
36-
expect(() => ayaStringSplitter("115:1")).toThrow();
37-
});
38-
39-
it("throws error for invalid aya numbers", () => {
40-
expect(() => ayaStringSplitter("1:0")).toThrow();
41-
expect(() => ayaStringSplitter("1:300")).toThrow();
42-
});
43-
44-
it("throws error for invalid range format", () => {
45-
expect(() => ayaStringSplitter("1:5-3")).toThrow();
46-
expect(() => ayaStringSplitter("1:5-")).toThrow();
47-
expect(() => ayaStringSplitter("1:-5")).toThrow();
48-
});
49-
50-
it("throws error for non-numeric input", () => {
51-
expect(() => ayaStringSplitter("1:a")).toThrow();
52-
expect(() => ayaStringSplitter("a:1")).toThrow();
53-
expect(() => ayaStringSplitter("1:1-a")).toThrow();
54-
});
55-
});
4+
it("basic tests", () => {
5+
expect(ayaStringSplitter("1:1")).toEqual([1, 1])
6+
expect(ayaStringSplitter("1:1-5")).toEqual([1, [1, 5]])
7+
expect(ayaStringSplitter("114:1")).toEqual([114, 1])
8+
// expect(ayaStringSplitter("115:1")).toEqual([115,1])
9+
})
10+
11+
it("error checks", () => {
12+
expect(() => ayaStringSplitter("1")).toThrow()
13+
expect(() => ayaStringSplitter("")).toThrow()
14+
expect(() => ayaStringSplitter("sdsgw")).toThrow()
15+
expect(() => ayaStringSplitter("sd:sgw")).toThrow()
16+
expect(() => ayaStringSplitter("34:sgw")).toThrow()
17+
})
18+
19+
it("handles single-digit sura and aya numbers", () => {
20+
expect(ayaStringSplitter("2:3")).toEqual([2, 3])
21+
expect(ayaStringSplitter("9:5")).toEqual([9, 5])
22+
})
23+
24+
it("handles multi-digit sura and aya numbers", () => {
25+
expect(ayaStringSplitter("110:3")).toEqual([110, 3])
26+
expect(ayaStringSplitter("2:255")).toEqual([2, 255])
27+
})
28+
29+
it("handles aya ranges with multi-digit numbers", () => {
30+
expect(ayaStringSplitter("7:26-30")).toEqual([7, [26, 30]])
31+
expect(ayaStringSplitter("18:1-10")).toEqual([18, [1, 10]])
32+
})
33+
34+
it("throws error for invalid sura numbers", () => {
35+
expect(() => ayaStringSplitter("0:1")).toThrow()
36+
expect(() => ayaStringSplitter("115:1")).toThrow()
37+
})
38+
39+
it("throws error for invalid aya numbers", () => {
40+
expect(() => ayaStringSplitter("1:0")).toThrow()
41+
expect(() => ayaStringSplitter("1:300")).toThrow()
42+
})
43+
44+
it("throws error for invalid range format", () => {
45+
expect(() => ayaStringSplitter("1:5-3")).toThrow()
46+
expect(() => ayaStringSplitter("1:5-")).toThrow()
47+
expect(() => ayaStringSplitter("1:-5")).toThrow()
48+
})
49+
50+
it("throws error for non-numeric input", () => {
51+
expect(() => ayaStringSplitter("1:a")).toThrow()
52+
expect(() => ayaStringSplitter("a:1")).toThrow()
53+
expect(() => ayaStringSplitter("1:1-a")).toThrow()
54+
})
55+
})

tests/checkValidAyahId.spec.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import { checkValidAyahId, meta } from "../src";
1+
import { checkValidAyahId, meta } from "../src"
22

33
describe("checkValidAyahId", () => {
44
it("should return true for valid ayah id", () => {
5-
expect(checkValidAyahId(1)).toBe(true);
6-
expect(checkValidAyahId(meta.numAyas)).toBe(true);
7-
expect(checkValidAyahId(Math.floor(meta.numAyas / 2))).toBe(true);
8-
});
5+
expect(checkValidAyahId(1)).toBe(true)
6+
expect(checkValidAyahId(meta.numAyas)).toBe(true)
7+
expect(checkValidAyahId(Math.floor(meta.numAyas / 2))).toBe(true)
8+
})
99

1010
it("should throw RangeError for ayah id less than 1", () => {
11-
expect(() => checkValidAyahId(0)).toThrow(RangeError);
12-
expect(() => checkValidAyahId(-1)).toThrow(RangeError);
13-
});
11+
expect(() => checkValidAyahId(0)).toThrow(RangeError)
12+
expect(() => checkValidAyahId(-1)).toThrow(RangeError)
13+
})
1414

1515
it("should throw RangeError for ayah id greater than total number of ayas", () => {
16-
expect(() => checkValidAyahId(meta.numAyas + 1)).toThrow(RangeError);
17-
expect(() => checkValidAyahId(Number.MAX_SAFE_INTEGER)).toThrow(RangeError);
18-
});
16+
expect(() => checkValidAyahId(meta.numAyas + 1)).toThrow(RangeError)
17+
expect(() => checkValidAyahId(Number.MAX_SAFE_INTEGER)).toThrow(RangeError)
18+
})
1919

20-
// it("should throw RangeError for non-integer ayah id", () => {
21-
// expect(() => checkValidAyahId(1.5)).toThrow(RangeError);
22-
// expect(() => checkValidAyahId(2.99)).toThrow(RangeError);
23-
// });
20+
// it("should throw RangeError for non-integer ayah id", () => {
21+
// expect(() => checkValidAyahId(1.5)).toThrow(RangeError);
22+
// expect(() => checkValidAyahId(2.99)).toThrow(RangeError);
23+
// });
2424

2525
// it("should throw TypeError for non-number ayah id", () => {
2626
// expect(() => checkValidAyahId("1" as any)).toThrow(TypeError);
2727
// expect(() => checkValidAyahId(null as any)).toThrow(TypeError);
2828
// expect(() => checkValidAyahId(undefined as any)).toThrow(TypeError);
2929
// });
30-
});
30+
})

tests/checkValidSurah.spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import { checkValidSurah, meta } from "../src";
1+
import { checkValidSurah, meta } from "../src"
22

33
describe("checkValidSurah", () => {
44
it("should return true for valid surah numbers", () => {
5-
expect(checkValidSurah(1)).toBe(true);
6-
expect(checkValidSurah(meta.numSuras)).toBe(true);
7-
expect(checkValidSurah(Math.floor(meta.numSuras / 2))).toBe(true);
8-
});
5+
expect(checkValidSurah(1)).toBe(true)
6+
expect(checkValidSurah(meta.numSuras)).toBe(true)
7+
expect(checkValidSurah(Math.floor(meta.numSuras / 2))).toBe(true)
8+
})
99

1010
it("should throw RangeError for surah number less than 1", () => {
11-
expect(() => checkValidSurah(0)).toThrow(RangeError);
12-
expect(() => checkValidSurah(-1)).toThrow(RangeError);
13-
});
11+
expect(() => checkValidSurah(0)).toThrow(RangeError)
12+
expect(() => checkValidSurah(-1)).toThrow(RangeError)
13+
})
1414

1515
it("should throw RangeError for surah number greater than total number of surahs", () => {
16-
expect(() => checkValidSurah(meta.numSuras + 1)).toThrow(RangeError);
17-
expect(() => checkValidSurah(Number.MAX_SAFE_INTEGER)).toThrow(RangeError);
18-
});
16+
expect(() => checkValidSurah(meta.numSuras + 1)).toThrow(RangeError)
17+
expect(() => checkValidSurah(Number.MAX_SAFE_INTEGER)).toThrow(RangeError)
18+
})
1919

2020
it("should return false for invalid surah numbers when checkOnly is true", () => {
21-
expect(checkValidSurah(0, true)).toBe(false);
22-
expect(checkValidSurah(meta.numSuras + 1, true)).toBe(false);
23-
});
21+
expect(checkValidSurah(0, true)).toBe(false)
22+
expect(checkValidSurah(meta.numSuras + 1, true)).toBe(false)
23+
})
2424

2525
it("should return true for valid surah numbers when checkOnly is true", () => {
26-
expect(checkValidSurah(1, true)).toBe(true);
27-
expect(checkValidSurah(meta.numSuras, true)).toBe(true);
28-
});
29-
});
26+
expect(checkValidSurah(1, true)).toBe(true)
27+
expect(checkValidSurah(meta.numSuras, true)).toBe(true)
28+
})
29+
})

tests/checkValidSurahAyah.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import { checkValidSurahAyah } from "../src";
1+
import { checkValidSurahAyah } from "../src"
22

33
describe("checkValidSurahAyah", () => {
44
it("should return true for valid surah and ayah", () => {
5-
expect(checkValidSurahAyah(1, 1)).toBe(true);
6-
expect(checkValidSurahAyah(114, 6)).toBe(true);
7-
});
5+
expect(checkValidSurahAyah(1, 1)).toBe(true)
6+
expect(checkValidSurahAyah(114, 6)).toBe(true)
7+
})
88

99
it("should return false for invalid surah", () => {
10-
expect(checkValidSurahAyah(0, 1, true)).toBe(false);
11-
expect(checkValidSurahAyah(115, 1, true)).toBe(false);
12-
});
10+
expect(checkValidSurahAyah(0, 1, true)).toBe(false)
11+
expect(checkValidSurahAyah(115, 1, true)).toBe(false)
12+
})
1313

1414
it("should return false for invalid ayah when checkOnly is true", () => {
15-
expect(checkValidSurahAyah(1, 0, true)).toBe(false);
16-
expect(checkValidSurahAyah(1, 8, true)).toBe(false);
17-
});
15+
expect(checkValidSurahAyah(1, 0, true)).toBe(false)
16+
expect(checkValidSurahAyah(1, 8, true)).toBe(false)
17+
})
1818

1919
it("should throw RangeError for invalid ayah when checkOnly is false", () => {
20-
expect(() => checkValidSurahAyah(1, 0)).toThrow(RangeError);
21-
expect(() => checkValidSurahAyah(1, 8)).toThrow(RangeError);
22-
});
20+
expect(() => checkValidSurahAyah(1, 0)).toThrow(RangeError)
21+
expect(() => checkValidSurahAyah(1, 8)).toThrow(RangeError)
22+
})
2323

2424
it("should throw RangeError with correct message for invalid ayah", () => {
25-
expect(() => checkValidSurahAyah(1, 8)).toThrow("Ayah must be between 1 and 7");
26-
expect(() => checkValidSurahAyah(2, 287)).toThrow("Ayah must be between 1 and 286");
27-
});
25+
expect(() => checkValidSurahAyah(1, 8)).toThrow("Ayah must be between 1 and 7")
26+
expect(() => checkValidSurahAyah(2, 287)).toThrow("Ayah must be between 1 and 286")
27+
})
2828

2929
it("should handle edge cases", () => {
30-
expect(checkValidSurahAyah(1, 7)).toBe(true);
31-
expect(checkValidSurahAyah(2, 286)).toBe(true);
32-
expect(checkValidSurahAyah(114, 1)).toBe(true);
33-
});
34-
});
30+
expect(checkValidSurahAyah(1, 7)).toBe(true)
31+
expect(checkValidSurahAyah(2, 286)).toBe(true)
32+
expect(checkValidSurahAyah(114, 1)).toBe(true)
33+
})
34+
})

tests/findAyaidBySurah.spec.ts

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,43 @@
1-
import { findAyaidBySurah, meta } from "../src";
1+
import { findAyaidBySurah, meta } from "../src"
22

33
describe("findAyaidBySurah", () => {
4-
5-
6-
it("should return correct AyahId for first ayah of first surah", () => {
7-
expect(findAyaidBySurah(1, 1)).toEqual(1);
8-
});
9-
10-
it("should return correct AyahId for last ayah of first surah", () => {
11-
expect(findAyaidBySurah(1, 7)).toEqual(7);
12-
});
13-
14-
it("should return correct AyahId for first ayah of second surah", () => {
15-
expect(findAyaidBySurah(2, 1)).toEqual(8);
16-
});
17-
18-
it("should return correct AyahId for middle of a surah", () => {
19-
expect(findAyaidBySurah(3, 60)).toEqual(353);
20-
});
21-
22-
it("should return correct AyahId for last surah", () => {
23-
expect(findAyaidBySurah(114, 1)).toEqual(6231);
24-
});
25-
26-
it("should return correct AyahId for last ayah of last surah", () => {
27-
expect(findAyaidBySurah(114, 6)).toEqual(6236);
28-
});
29-
30-
it("should handle edge cases", () => {
31-
expect(findAyaidBySurah(1, 2)).toEqual(2)
32-
expect(findAyaidBySurah(114, 6)).toEqual(meta.numAyas)
33-
expect(findAyaidBySurah(9, 51)).toEqual(1286);
34-
expect(findAyaidBySurah(9, 1)).toEqual(1236);
35-
expect(findAyaidBySurah(10, 50)).toEqual(1414);
36-
});
37-
38-
it("should throw error for invalid surah", () => {
39-
expect(() => findAyaidBySurah(115, 1)).toThrow();
40-
});
41-
42-
it("should throw error for invalid ayah", () => {
43-
expect(() => findAyaidBySurah(1, 8)).toThrow();
44-
});
45-
});
4+
it("should return correct AyahId for first ayah of first surah", () => {
5+
expect(findAyaidBySurah(1, 1)).toEqual(1)
6+
})
7+
8+
it("should return correct AyahId for last ayah of first surah", () => {
9+
expect(findAyaidBySurah(1, 7)).toEqual(7)
10+
})
11+
12+
it("should return correct AyahId for first ayah of second surah", () => {
13+
expect(findAyaidBySurah(2, 1)).toEqual(8)
14+
})
15+
16+
it("should return correct AyahId for middle of a surah", () => {
17+
expect(findAyaidBySurah(3, 60)).toEqual(353)
18+
})
19+
20+
it("should return correct AyahId for last surah", () => {
21+
expect(findAyaidBySurah(114, 1)).toEqual(6231)
22+
})
23+
24+
it("should return correct AyahId for last ayah of last surah", () => {
25+
expect(findAyaidBySurah(114, 6)).toEqual(6236)
26+
})
27+
28+
it("should handle edge cases", () => {
29+
expect(findAyaidBySurah(1, 2)).toEqual(2)
30+
expect(findAyaidBySurah(114, 6)).toEqual(meta.numAyas)
31+
expect(findAyaidBySurah(9, 51)).toEqual(1286)
32+
expect(findAyaidBySurah(9, 1)).toEqual(1236)
33+
expect(findAyaidBySurah(10, 50)).toEqual(1414)
34+
})
35+
36+
it("should throw error for invalid surah", () => {
37+
expect(() => findAyaidBySurah(115, 1)).toThrow()
38+
})
39+
40+
it("should throw error for invalid ayah", () => {
41+
expect(() => findAyaidBySurah(1, 8)).toThrow()
42+
})
43+
})

0 commit comments

Comments
 (0)