File tree Expand file tree Collapse file tree
main/java/com/thealgorithms/others/cn
test/java/com/thealgorithms/others/cn Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33public final class HammingDistance {
44
5- private HammingDistance () {
6- }
5+ private HammingDistance () {
6+ }
77
8- public static int compute (String bitsStrA , String bitsStrB ) {
9- HammingHandler chain = new ValidateBinaryHandler ();
10- chain .setNext (new ValidateLengthHandler ()).setNext (new ComputeHammingHandler ());
8+ public static int compute (String bitsStrA , String bitsStrB ) {
9+ HammingHandler chain = new ValidateBinaryHandler ();
10+ chain .setNext (new ValidateLengthHandler ()).setNext (new ComputeHammingHandler ());
1111
12- return (int ) chain .handle (bitsStrA , bitsStrB );
13- }
12+ return (int ) chain .handle (bitsStrA , bitsStrB );
13+ }
1414}
Original file line number Diff line number Diff line change @@ -9,15 +9,13 @@ public class ValidateBinaryHandlerTest {
99
1010 @ Test
1111 public void validBinaryStringsShouldPass () {
12- handler .setNext (new MockHammingHandler ("PASSED" ));
12+ handler .setNext (new MockHammingHandler ("PASSED" ));
1313 Object result = handler .handle ("1010" , "0110" );
1414 Assertions .assertThat (result ).isEqualTo ("PASSED" );
1515 }
1616
1717 @ Test
1818 public void invalidBinaryShouldThrowException () {
19- Assertions .assertThatThrownBy (() -> handler .handle ("10A0" , "0110" ))
20- .isInstanceOf (IllegalArgumentException .class )
21- .hasMessageContaining ("binary string" );
19+ Assertions .assertThatThrownBy (() -> handler .handle ("10A0" , "0110" )).isInstanceOf (IllegalArgumentException .class ).hasMessageContaining ("binary string" );
2220 }
2321}
Original file line number Diff line number Diff line change @@ -9,15 +9,13 @@ public class ValidateLengthHandlerTest {
99
1010 @ Test
1111 public void validLengthShouldPass () {
12- handler .setNext (new MockHammingHandler ("LENGTH_OK" ));
12+ handler .setNext (new MockHammingHandler ("LENGTH_OK" ));
1313 Object result = handler .handle ("1010" , "0110" );
1414 Assertions .assertThat (result ).isEqualTo ("LENGTH_OK" );
1515 }
1616
1717 @ Test
1818 public void mismatchedLengthShouldThrowException () {
19- Assertions .assertThatThrownBy (() -> handler .handle ("101" , "10" ))
20- .isInstanceOf (IllegalArgumentException .class )
21- .hasMessageContaining ("same length" );
19+ Assertions .assertThatThrownBy (() -> handler .handle ("101" , "10" )).isInstanceOf (IllegalArgumentException .class ).hasMessageContaining ("same length" );
2220 }
2321}
You can’t perform that action at this time.
0 commit comments