Alexis Drai 2 years ago
parent 983983c3b7
commit 11d3023e09

@ -1,7 +1,7 @@
package fr.iut.uca; package fr.iut.uca;
public class Operations { public class Operations {
public long Add(long a, long b, long... others) { public long add(long a, long b, long... others) {
long res = a + b; long res = a + b;
@ -14,7 +14,7 @@ public class Operations {
return res; return res;
} }
public long Multiply(long a, long b, long... others) { public long multiply(long a, long b, long... others) {
long res = a * b; long res = a * b;
@ -27,7 +27,7 @@ public class Operations {
return res; return res;
} }
public long Divide(long a, long b, long... others) { public long divide(long a, long b, long... others) {
if(b == 0) { if(b == 0) {
throw new ArithmeticException("attempted to divide by zero"); throw new ArithmeticException("attempted to divide by zero");
} }
@ -46,4 +46,16 @@ public class Operations {
return res; return res;
} }
public boolean pythagoras(long a, long b, long c) {
if(a <= 0 || b <= 0 || c <= 0) {
throw new ArithmeticException("there is no such thing as a negative length for a triangle's side");
}
return (
(a * a) + (b * b) == c * c
|| (c * c) + (b * b) == a * a
|| (a * a) + (c * c) == b * b
);
}
} }

@ -5,7 +5,6 @@ public class PleaseEclipseCmon {
public static void main(String[] args) { public static void main(String[] args) {
Operations operation = new Operations(); Operations operation = new Operations();
System.out.println(operation.Add(2, 2, 2, 2, 3)); System.out.println(operation.add(2, 2, 2, 2, 3));
System.out.println(0 == -0);
} }
} }

@ -28,7 +28,7 @@ class OperationsTests {
// Act // Act
long actual = op.Add(x, y, null); long actual = op.add(x, y, null);
// Assert // Assert
@ -45,7 +45,7 @@ class OperationsTests {
// Act // Act
long actual = op.Add(x, y, null); long actual = op.add(x, y, null);
// Assert // Assert
@ -62,7 +62,7 @@ class OperationsTests {
// Act // Act
long actual = op.Add(x, y, null); long actual = op.add(x, y, null);
// Assert // Assert
@ -79,7 +79,7 @@ class OperationsTests {
// Act // Act
long actual = op.Add(x, y, null); long actual = op.add(x, y, null);
// Assert // Assert
@ -96,7 +96,7 @@ class OperationsTests {
// Act // Act
long actual = op.Add(x, y, null); long actual = op.add(x, y, null);
// Assert // Assert
@ -113,7 +113,7 @@ class OperationsTests {
// Act // Act
long actual = op.Add(x, y, null); long actual = op.add(x, y, null);
// Assert // Assert
@ -130,7 +130,7 @@ class OperationsTests {
// Act // Act
long actual = op.Add(x, y, null); long actual = op.add(x, y, null);
// Assert // Assert
@ -147,7 +147,7 @@ class OperationsTests {
// Act // Act
long actual = op.Add(x, y, null); long actual = op.add(x, y, null);
// Assert // Assert
@ -167,7 +167,7 @@ class OperationsTests {
// Act // Act
long actual = op.Add(x, y, z1, z2, z3); long actual = op.add(x, y, z1, z2, z3);
// Assert // Assert
@ -176,10 +176,11 @@ class OperationsTests {
@Test @Test
void rdm() { void rdm() {
Random rdm = new Random();
for(int i = 0 ; i <10; i++) { for(int i = 0 ; i <10; i++) {
// Arrange // Arrange
Random rdm = new Random();
long rdmX =rdm.nextLong(); long rdmX =rdm.nextLong();
long rdmY = rdm.nextLong(); long rdmY = rdm.nextLong();
@ -197,7 +198,7 @@ class OperationsTests {
// Act // Act
long actual = op.Add(rdmX, rdmY, null); long actual = op.add(rdmX, rdmY, null);
// Assert // Assert

Loading…
Cancel
Save