Add Numbers Have Different Signs (#4317)

Co-authored-by: BamaCharanChhandogi <b.c.chhandogi@gmailcom>
This commit is contained in:
Bama Charan Chhandogi 2023-08-15 22:06:00 +05:30 committed by GitHub
parent 18848574be
commit 2c16c86054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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));
}
}