11package com .thealgorithms .strings ;
22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
4+ import static org .junit .jupiter .api .Assertions .assertFalse ;
5+ import static org .junit .jupiter .api .Assertions .assertThrows ;
46import static org .junit .jupiter .api .Assertions .assertTrue ;
57
68import java .util .stream .Stream ;
@@ -13,7 +15,7 @@ public class IsogramTest {
1315 record IsogramTestCase (String input , boolean expected ) {
1416 }
1517
16- private static Stream <IsogramTestCase > isogramArrayTestData () {
18+ private static Stream <IsogramTestCase > isAlphabeticIsogram () {
1719 return Stream .of (
1820 // Valid isograms (only checks letters)
1921 new IsogramTestCase ("uncopyrightable" , true ), new IsogramTestCase ("dermatoglyphics" , true ), new IsogramTestCase ("background" , true ), new IsogramTestCase ("python" , true ), new IsogramTestCase ("keyboard" , true ), new IsogramTestCase ("clipboard" , true ), new IsogramTestCase ("flowchart" , true ),
@@ -30,7 +32,7 @@ private static Stream<IsogramTestCase> isogramArrayTestData() {
3032 new IsogramTestCase ("Python" , true ), new IsogramTestCase ("BACKGROUND" , true ), new IsogramTestCase ("Hello" , false ), new IsogramTestCase ("PROGRAMMING" , false ));
3133 }
3234
33- private static Stream <IsogramTestCase > isogramLengthTestData () {
35+ private static Stream <IsogramTestCase > isFullIsogram () {
3436 return Stream .of (
3537 // Valid isograms (checks all characters)
3638 new IsogramTestCase ("uncopyrightable" , true ), new IsogramTestCase ("dermatoglyphics" , true ), new IsogramTestCase ("background" , true ), new IsogramTestCase ("python" , true ), new IsogramTestCase ("keyboard" , true ), new IsogramTestCase ("clipboard" , true ), new IsogramTestCase ("flowchart" , true ),
@@ -60,34 +62,56 @@ private static Stream<IsogramTestCase> isogramLengthTestData() {
6062 }
6163
6264 @ ParameterizedTest
63- @ MethodSource ("isogramArrayTestData " )
65+ @ MethodSource ("isAlphabeticIsogram " )
6466 void testIsogramByArray (IsogramTestCase testCase ) {
65- assertEquals (testCase .expected (), Isogram .isIsogramByArray (testCase .input ()));
67+ assertEquals (testCase .expected (), Isogram .isAlphabeticIsogram (testCase .input ()));
6668 }
6769
6870 @ ParameterizedTest
69- @ MethodSource ("isogramLengthTestData " )
71+ @ MethodSource ("isFullIsogram " )
7072 void testIsogramByLength (IsogramTestCase testCase ) {
71- assertEquals (testCase .expected (), Isogram .isIsogramByLength (testCase .input ()));
73+ assertEquals (testCase .expected (), Isogram .isFullIsogram (testCase .input ()));
7274 }
7375
7476 @ Test
7577 void testNullInputByArray () {
76- assertTrue (Isogram .isIsogramByArray (null ));
78+ assertTrue (Isogram .isAlphabeticIsogram (null ));
7779 }
7880
7981 @ Test
8082 void testNullInputByLength () {
81- assertTrue (Isogram .isIsogramByLength (null ));
83+ assertTrue (Isogram .isFullIsogram (null ));
8284 }
8385
8486 @ Test
8587 void testEmptyStringByArray () {
86- assertTrue (Isogram .isIsogramByArray ("" ));
88+ assertTrue (Isogram .isAlphabeticIsogram ("" ));
8789 }
8890
8991 @ Test
9092 void testEmptyStringByLength () {
91- assertTrue (Isogram .isIsogramByLength ("" ));
93+ assertTrue (Isogram .isFullIsogram ("" ));
94+ }
95+
96+ @ Test
97+ void testAlphabeticIsogramThrowsException () {
98+ // Test that IllegalArgumentException is thrown for non-alphabetic characters
99+ assertThrows (IllegalArgumentException .class , () -> Isogram .isAlphabeticIsogram ("1" ));
100+ assertThrows (IllegalArgumentException .class , () -> Isogram .isAlphabeticIsogram ("@" ));
101+ assertThrows (IllegalArgumentException .class , () -> Isogram .isAlphabeticIsogram ("python!" ));
102+ assertThrows (IllegalArgumentException .class , () -> Isogram .isAlphabeticIsogram ("123algorithm" ));
103+ assertThrows (IllegalArgumentException .class , () -> Isogram .isAlphabeticIsogram ("hello123" ));
104+ assertThrows (IllegalArgumentException .class , () -> Isogram .isAlphabeticIsogram ("!@@#$%^&*()" ));
105+ }
106+
107+ @ Test
108+ void testFullIsogramWithMixedCharacters () {
109+ // Test that full isogram method handles all character types without exceptions
110+ assertTrue (Isogram .isFullIsogram ("abc123" ));
111+ assertFalse (Isogram .isFullIsogram ("test@email" )); // 'e' repeats
112+ assertFalse (Isogram .isFullIsogram ("hello123" )); // 'l' repeats
113+ assertTrue (Isogram .isFullIsogram ("1234567890" ));
114+ assertFalse (Isogram .isFullIsogram ("12321" )); // '1' and '2' repeat
115+ assertTrue (Isogram .isFullIsogram ("!@#$%^&*()" ));
92116 }
93117}
0 commit comments