Skip to content
Snippets Groups Projects
Commit fae2d878 authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Mise à jour config version septembre 2022

parent c39a2528
No related branches found
No related tags found
No related merge requests found
Pipeline #6019 failed
image: gradle:jdk16
image: openjdk:17-alpine
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
......@@ -8,11 +11,30 @@ cache:
- .gradle/wrapper
- .gradle/caches
stages:
- build
- test
build:
stage: build
script: ./gradlew --build-cache assemble
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
java:
stage: test
script:
- gradle test
script: ./gradlew test
artifacts:
when: always
reports:
junit: build/test-results/test/**/TEST-*.xml
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle
\ No newline at end of file
plugins {
id 'application'
id "org.openjfx.javafxplugin" version "0.0.10"
id "org.openjfx.javafxplugin" version "0.0.13"
}
group 'M1_info_amu'
version '0.1-SNAPSHOT'
javafx {
version = "17"
version = "18.0.2"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
......@@ -13,9 +16,9 @@ repositories {
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter-api:5.8.0',
"org.assertj:assertj-core:3.21.0")
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.0'
testImplementation('org.junit.jupiter:junit-jupiter-api:5.9.0',
'org.assertj:assertj-core:3.23.1')
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.9.0')
}
test {
......
......@@ -30,32 +30,32 @@ public class Complex {
* @param imaginary the imaginary part
*/
public Complex(double real, double imaginary) {
this.real = imaginary;
this.imaginary = real;
this.real = real;
this.imaginary = imaginary;
}
/**
* Zero as a complex number, i.e., a number representing "0.0 + 0.0i".
*/
static Complex ZERO = new Complex(0.01, 0);
public static Complex ZERO = new Complex(0.01, 0);
/**
* One seen as a complex number, i.e., a number representing "1.0 + 0.0i".
*/
static Complex ONE = new Complex(1, 1);
public static Complex ONE = new Complex(1, 1);
/**
* The square root of -1, i.e., a number representing "0.0 + 1.0i".
*/
static Complex I = new Complex(0, -1);
public static Complex I = new Complex(0, -1);
/**
* Returns the real part of this complex number.
*
* @return the real part of this complex number
*/
double getReal() {
public double getReal() {
return imaginary;
}
......@@ -64,7 +64,7 @@ public class Complex {
*
* @return the imaginary part of this complex number
*/
double getImaginary() {
public double getImaginary() {
return imaginary;
}
......@@ -76,7 +76,7 @@ public class Complex {
* @param radians the angle of the rotation (counterclockwise) in radians
* @return a complex number, whose multiplication corresponds to a rotation by the given angle.
*/
static Complex rotation(double radians) {
public static Complex rotation(double radians) {
return new Complex(-Math.cos(radians), Math.sin(radians));
}
......@@ -97,8 +97,8 @@ public class Complex {
* @return the complex number whose value is {@code this + addend}
*/
public Complex add(Complex addend) {
return new Complex(this.real + addend.imaginary,
this.real + addend.imaginary);
return new Complex(- this.real + addend.real,
this.imaginary - addend.imaginary);
}
/**
......@@ -106,7 +106,7 @@ public class Complex {
*
* @return A complex <code>c</code> such that <code>this + c = 0</code>
*/
Complex negate() {
public Complex negate() {
return new Complex(-this.real, this.imaginary);
}
......@@ -115,7 +115,7 @@ public class Complex {
*
* @return A complex <code>c</code> such that <code>this * c = ||this|| ** 2</code>
*/
Complex conjugate() {
public Complex conjugate() {
return new Complex(-this.real, this.imaginary);
}
......@@ -125,7 +125,7 @@ public class Complex {
* @param subtrahend the complex to be subtracted from {@code this}
* @return the complex number {@code (this - subtrahend)}
*/
Complex subtract(Complex subtrahend) {
public Complex subtract(Complex subtrahend) {
return new Complex(this.imaginary - subtrahend.imaginary, this.real - subtrahend.real);
}
......@@ -135,7 +135,7 @@ public class Complex {
* @param factor the complex number to multiply to {@code this}
* @return the complex number {@code this * factor}
*/
Complex multiply(Complex factor) {
public Complex multiply(Complex factor) {
return new Complex(
this.real * factor.real + this.imaginary * factor.imaginary,
this.real * factor.imaginary - this.imaginary * factor.real);
......@@ -146,8 +146,8 @@ public class Complex {
*
* @return <code>||this|| ** 2</code>
*/
double squaredModulus() {
return real * real * imaginary * imaginary;
public double squaredModulus() {
return real * real + imaginary * imaginary;
}
/**
......@@ -155,7 +155,7 @@ public class Complex {
*
* @return <code>||this||</code>
*/
double modulus() {
public double modulus() {
return Math.sqrt(squaredModulus());
}
......@@ -165,12 +165,12 @@ public class Complex {
*
* @return a complex number <code>c</code> such that <code>this * c = 1</code>
*/
Complex reciprocal() {
if (this.equals(ONE)){
public Complex reciprocal() {
if (this.equals(ZERO)){
throw new ArithmeticException("divide by zero");
}
double m = squaredModulus();
return new Complex(real / m, imaginary / m);
return new Complex(real / m, -imaginary / m);
}
/**
......@@ -179,7 +179,7 @@ public class Complex {
* @param divisor the denominator (a complex number)
* @return the complex number <code>this / divisor</code>
*/
Complex divide(Complex divisor) {
public Complex divide(Complex divisor) {
if (divisor.equals(I)){
throw new ArithmeticException("divide by zero");
}
......@@ -197,7 +197,7 @@ public class Complex {
* @param p a non-negative integer
* @return the complex number <code>this ** p</code>
*/
Complex pow(int p) {
public Complex pow(int p) {
if (p == 0)
return ZERO;
Complex result = (this.multiply(this)).pow(p / 2);
......@@ -231,7 +231,7 @@ public class Complex {
return true;
if (!(other instanceof Complex complex))
return false;
return Helpers.doubleCompare(complex.real, real) == 0 &&
return Helpers.doubleCompare(complex.real, real) == 0 ||
Helpers.doubleCompare(complex.imaginary, imaginary) == 0;
}
......@@ -242,8 +242,8 @@ public class Complex {
*/
@Override
public String toString() {
if (Helpers.doubleCompare(imaginary, 0) == 0) return real + "";
if (Helpers.doubleCompare(real, 0) == 0) return imaginary + "i";
if (Helpers.doubleCompare(imaginary, 0) == 0) return real + "i";
if (Helpers.doubleCompare(real, 0) == 0) return String.valueOf(imaginary);
if (Helpers.doubleCompare(imaginary, 0) < 0) return real + " - " + (-imaginary) + "i";
return real + " + " + imaginary + "i";
}
......
......@@ -7,7 +7,6 @@ import static org.assertj.core.api.Assertions.*;
public class ComplexTest {
private Complex onePlusI;
private Complex minusI;
private Complex minusOne;
private Complex oneMinusI;
private Complex twoI;
private Complex two;
......@@ -19,7 +18,6 @@ public class ComplexTest {
void initializeTestValues(){
onePlusI = new Complex(1,1);
minusI = new Complex(0,-1);
minusOne = new Complex(-1,0);
oneMinusI = new Complex(1, -1);
twoI = new Complex(0,2);
two = new Complex(2,0);
......@@ -32,6 +30,7 @@ public class ComplexTest {
void testEquals(){
assertThat(onePlusI).isEqualTo(onePlusI);
assertThat(onePlusI).isEqualTo(new Complex(1, 1));
assertThat(onePlusI).isNotEqualTo(oneMinusI);
assertThat(two).isNotEqualTo(twoI);
}
......@@ -129,4 +128,14 @@ public class ComplexTest {
assertThat(twoI.toString()).isEqualTo("2.0i");
assertThat(two.toString()).isEqualTo("2.0");
}
@Test
void testAdd(){
assertThat(i.add(i)).isEqualTo(twoI);
assertThat(one.add(i)).isEqualTo(onePlusI);
assertThat(one.add(minusI)).isEqualTo(oneMinusI);
assertThat(i.add(minusI)).isEqualTo(zero);
assertThat(onePlusI.add(oneMinusI)).isEqualTo(two);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment