From 2c16c8605455117e1bc6557430830961a3df97e2 Mon Sep 17 00:00:00 2001 From: Bama Charan Chhandogi Date: Tue, 15 Aug 2023 22:06:00 +0530 Subject: [PATCH] Add Numbers Have Different Signs (#4317) Co-authored-by: BamaCharanChhandogi --- .../NumbersDifferentSigns.java | 13 ++++++++ .../NumbersDifferentSignsTest.java | 33 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/main/java/com/thealgorithms/bitmanipulation/NumbersDifferentSigns.java create mode 100644 src/test/java/com/thealgorithms/bitmanipulation/NumbersDifferentSignsTest.java 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