From 269df4089990a1fdfe0cbace59850e8dde715e7b Mon Sep 17 00:00:00 2001 From: Alexis DRAI Date: Tue, 24 Jan 2023 16:21:23 +0100 Subject: [PATCH] :white_check_mark: Division --- src/fr/iut/uca/Operations.java | 2 +- src/test/OperationsTests.java | 60 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/fr/iut/uca/Operations.java b/src/fr/iut/uca/Operations.java index 130e24b..b29545c 100644 --- a/src/fr/iut/uca/Operations.java +++ b/src/fr/iut/uca/Operations.java @@ -39,7 +39,7 @@ public class Operations { if(num == 0) { throw new ArithmeticException("attempted to divide by zero"); } - res *= num; + res /= num; } } diff --git a/src/test/OperationsTests.java b/src/test/OperationsTests.java index c5261ea..2f9c6cd 100644 --- a/src/test/OperationsTests.java +++ b/src/test/OperationsTests.java @@ -469,4 +469,64 @@ class OperationsTests { }); assertEquals(exc.getMessage(), "attempted to divide by zero"); } + + @Test + void divWithNegRight() { + // Arrange + + long x = 12; + long y = -3; + long expected = -4; + + // Act + + long actual = op.divide(x, y, null); + + // Assert + + assertEquals(expected, actual); + } + + @Test + void divWithNegLeft() { + // Arrange + + long x = -12; + long y = 6; + long expected = -2; + + // Act + + long actual = op.divide(x, y, null); + + // Assert + + assertEquals(expected, actual); + } + + + @Test + void divWithMany() { + // Arrange + + long x = 12; + long y = 2; + long z1 = 2; + long z2 = 1; + long expected = 3; + + // Act + + long actual = op.divide(x, y, z1, z2); + + // Assert + + assertEquals(expected, actual); + } + + // -------------- + // pythagoras + // -------------- + + }