Add Numbers Have Different Signs (#4317)
Co-authored-by: BamaCharanChhandogi <b.c.chhandogi@gmailcom>
This commit is contained in:
parent
18848574be
commit
2c16c86054
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user