mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
refactor: OnesComplement Tests Using Parameterized Inputs (#6375)
refactor: OnesComplement Tests Using Parameterized Inputs Co-authored-by: Deniz Altunkapan <93663085+DenizAltunkapan@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
933e929b54
commit
25aaa6e064
@@ -1,8 +1,12 @@
|
||||
package com.thealgorithms.bitmanipulation;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.NullAndEmptySource;
|
||||
|
||||
/**
|
||||
* Test case for Highest Set Bit
|
||||
@@ -39,9 +43,16 @@ public class OnesComplementTest {
|
||||
assertEquals("1001", OnesComplement.onesComplement("0110"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullAndEmptySource
|
||||
public void testOnesComplementNullOrEmptyInputThrowsException(String input) {
|
||||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> OnesComplement.onesComplement(input));
|
||||
assertEquals("Input must be a non-empty binary string.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnesComplementEmptyString() {
|
||||
// Test empty string scenario
|
||||
assertEquals("", OnesComplement.onesComplement(""));
|
||||
public void testOnesComplementInvalidCharactersThrowsException() {
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, () -> OnesComplement.onesComplement("10a1"));
|
||||
assertTrue(exception.getMessage().startsWith("Input must contain only '0' and '1'"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user