diff --git a/src/main/java/com/thealgorithms/bitmanipulation/NumbersDifferentSigns.java b/src/main/java/com/thealgorithms/bitmanipulation/NumbersDifferentSigns.java new file mode 100644 index 00000000..bd011f82 --- /dev/null +++ b/src/main/java/com/thealgorithms/bitmanipulation/NumbersDifferentSigns.java @@ -0,0 +1,13 @@ +package com.thealgorithms.bitmanipulation; + +/** + * Numbers Different Signs + * @author Bama Charan Chhandogi + */ + +public class NumbersDifferentSigns { + + public static boolean differentSigns(int num1, int num2) { + return (num1 ^ num2) < 0; + } +} \ No newline at end of file diff --git a/src/test/java/com/thealgorithms/bitmanipulation/NumbersDifferentSignsTest.java b/src/test/java/com/thealgorithms/bitmanipulation/NumbersDifferentSignsTest.java new file mode 100644 index 00000000..3ce0f8ee --- /dev/null +++ b/src/test/java/com/thealgorithms/bitmanipulation/NumbersDifferentSignsTest.java @@ -0,0 +1,33 @@ +package com.thealgorithms.bitmanipulation; + +/** + * test Cases of Numbers Different Signs + * @author Bama Charan Chhandogi + */ + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class NumbersDifferentSignsTest { + + @Test + void testDifferentSignsPositiveNegative() { + assertTrue(NumbersDifferentSigns.differentSigns(2, -1)); + } + + @Test + void testDifferentSignsNegativePositive() { + assertTrue(NumbersDifferentSigns.differentSigns(-3, 7)); + } + + @Test + void testSameSignsPositive() { + assertFalse(NumbersDifferentSigns.differentSigns(10, 20)); + } + + @Test + void testSameSignsNegative() { + assertFalse(NumbersDifferentSigns.differentSigns(-5, -8)); + } +} \ No newline at end of file