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
image: gradle:jdk16 image: openjdk:17-alpine
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
before_script: before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle - export GRADLE_USER_HOME=`pwd`/.gradle
...@@ -8,11 +11,30 @@ cache: ...@@ -8,11 +11,30 @@ cache:
- .gradle/wrapper - .gradle/wrapper
- .gradle/caches - .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: java:
stage: test stage: test
script: script: ./gradlew test
- gradle test
artifacts: artifacts:
when: always when: always
reports: reports:
junit: build/test-results/test/**/TEST-*.xml 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 { plugins {
id 'application' 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 { javafx {
version = "17" version = "18.0.2"
modules = [ 'javafx.controls', 'javafx.fxml' ] modules = [ 'javafx.controls', 'javafx.fxml' ]
} }
...@@ -13,9 +16,9 @@ repositories { ...@@ -13,9 +16,9 @@ repositories {
} }
dependencies { dependencies {
testImplementation('org.junit.jupiter:junit-jupiter-api:5.8.0', testImplementation('org.junit.jupiter:junit-jupiter-api:5.9.0',
"org.assertj:assertj-core:3.21.0") 'org.assertj:assertj-core:3.23.1')
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.0' testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.9.0')
} }
test { test {
......
...@@ -30,32 +30,32 @@ public class Complex { ...@@ -30,32 +30,32 @@ public class Complex {
* @param imaginary the imaginary part * @param imaginary the imaginary part
*/ */
public Complex(double real, double imaginary) { public Complex(double real, double imaginary) {
this.real = imaginary; this.real = real;
this.imaginary = real; this.imaginary = imaginary;
} }
/** /**
* Zero as a complex number, i.e., a number representing "0.0 + 0.0i". * 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". * 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". * 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. * Returns the real part of this complex number.
* *
* @return the real part of this complex number * @return the real part of this complex number
*/ */
double getReal() { public double getReal() {
return imaginary; return imaginary;
} }
...@@ -64,7 +64,7 @@ public class Complex { ...@@ -64,7 +64,7 @@ public class Complex {
* *
* @return the imaginary part of this complex number * @return the imaginary part of this complex number
*/ */
double getImaginary() { public double getImaginary() {
return imaginary; return imaginary;
} }
...@@ -76,7 +76,7 @@ public class Complex { ...@@ -76,7 +76,7 @@ public class Complex {
* @param radians the angle of the rotation (counterclockwise) in radians * @param radians the angle of the rotation (counterclockwise) in radians
* @return a complex number, whose multiplication corresponds to a rotation by the given angle. * @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)); return new Complex(-Math.cos(radians), Math.sin(radians));
} }
...@@ -97,8 +97,8 @@ public class Complex { ...@@ -97,8 +97,8 @@ public class Complex {
* @return the complex number whose value is {@code this + addend} * @return the complex number whose value is {@code this + addend}
*/ */
public Complex add(Complex addend) { public Complex add(Complex addend) {
return new Complex(this.real + addend.imaginary, return new Complex(- this.real + addend.real,
this.real + addend.imaginary); this.imaginary - addend.imaginary);
} }
/** /**
...@@ -106,7 +106,7 @@ public class Complex { ...@@ -106,7 +106,7 @@ public class Complex {
* *
* @return A complex <code>c</code> such that <code>this + c = 0</code> * @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); return new Complex(-this.real, this.imaginary);
} }
...@@ -115,7 +115,7 @@ public class Complex { ...@@ -115,7 +115,7 @@ public class Complex {
* *
* @return A complex <code>c</code> such that <code>this * c = ||this|| ** 2</code> * @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); return new Complex(-this.real, this.imaginary);
} }
...@@ -125,7 +125,7 @@ public class Complex { ...@@ -125,7 +125,7 @@ public class Complex {
* @param subtrahend the complex to be subtracted from {@code this} * @param subtrahend the complex to be subtracted from {@code this}
* @return the complex number {@code (this - subtrahend)} * @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); return new Complex(this.imaginary - subtrahend.imaginary, this.real - subtrahend.real);
} }
...@@ -135,7 +135,7 @@ public class Complex { ...@@ -135,7 +135,7 @@ public class Complex {
* @param factor the complex number to multiply to {@code this} * @param factor the complex number to multiply to {@code this}
* @return the complex number {@code this * factor} * @return the complex number {@code this * factor}
*/ */
Complex multiply(Complex factor) { public Complex multiply(Complex factor) {
return new Complex( return new Complex(
this.real * factor.real + this.imaginary * factor.imaginary, this.real * factor.real + this.imaginary * factor.imaginary,
this.real * factor.imaginary - this.imaginary * factor.real); this.real * factor.imaginary - this.imaginary * factor.real);
...@@ -146,8 +146,8 @@ public class Complex { ...@@ -146,8 +146,8 @@ public class Complex {
* *
* @return <code>||this|| ** 2</code> * @return <code>||this|| ** 2</code>
*/ */
double squaredModulus() { public double squaredModulus() {
return real * real * imaginary * imaginary; return real * real + imaginary * imaginary;
} }
/** /**
...@@ -155,7 +155,7 @@ public class Complex { ...@@ -155,7 +155,7 @@ public class Complex {
* *
* @return <code>||this||</code> * @return <code>||this||</code>
*/ */
double modulus() { public double modulus() {
return Math.sqrt(squaredModulus()); return Math.sqrt(squaredModulus());
} }
...@@ -165,12 +165,12 @@ public class Complex { ...@@ -165,12 +165,12 @@ public class Complex {
* *
* @return a complex number <code>c</code> such that <code>this * c = 1</code> * @return a complex number <code>c</code> such that <code>this * c = 1</code>
*/ */
Complex reciprocal() { public Complex reciprocal() {
if (this.equals(ONE)){ if (this.equals(ZERO)){
throw new ArithmeticException("divide by zero"); throw new ArithmeticException("divide by zero");
} }
double m = squaredModulus(); double m = squaredModulus();
return new Complex(real / m, imaginary / m); return new Complex(real / m, -imaginary / m);
} }
/** /**
...@@ -179,7 +179,7 @@ public class Complex { ...@@ -179,7 +179,7 @@ public class Complex {
* @param divisor the denominator (a complex number) * @param divisor the denominator (a complex number)
* @return the complex number <code>this / divisor</code> * @return the complex number <code>this / divisor</code>
*/ */
Complex divide(Complex divisor) { public Complex divide(Complex divisor) {
if (divisor.equals(I)){ if (divisor.equals(I)){
throw new ArithmeticException("divide by zero"); throw new ArithmeticException("divide by zero");
} }
...@@ -197,7 +197,7 @@ public class Complex { ...@@ -197,7 +197,7 @@ public class Complex {
* @param p a non-negative integer * @param p a non-negative integer
* @return the complex number <code>this ** p</code> * @return the complex number <code>this ** p</code>
*/ */
Complex pow(int p) { public Complex pow(int p) {
if (p == 0) if (p == 0)
return ZERO; return ZERO;
Complex result = (this.multiply(this)).pow(p / 2); Complex result = (this.multiply(this)).pow(p / 2);
...@@ -231,7 +231,7 @@ public class Complex { ...@@ -231,7 +231,7 @@ public class Complex {
return true; return true;
if (!(other instanceof Complex complex)) if (!(other instanceof Complex complex))
return false; return false;
return Helpers.doubleCompare(complex.real, real) == 0 && return Helpers.doubleCompare(complex.real, real) == 0 ||
Helpers.doubleCompare(complex.imaginary, imaginary) == 0; Helpers.doubleCompare(complex.imaginary, imaginary) == 0;
} }
...@@ -242,8 +242,8 @@ public class Complex { ...@@ -242,8 +242,8 @@ public class Complex {
*/ */
@Override @Override
public String toString() { public String toString() {
if (Helpers.doubleCompare(imaginary, 0) == 0) return real + ""; if (Helpers.doubleCompare(imaginary, 0) == 0) return real + "i";
if (Helpers.doubleCompare(real, 0) == 0) return imaginary + "i"; if (Helpers.doubleCompare(real, 0) == 0) return String.valueOf(imaginary);
if (Helpers.doubleCompare(imaginary, 0) < 0) return real + " - " + (-imaginary) + "i"; if (Helpers.doubleCompare(imaginary, 0) < 0) return real + " - " + (-imaginary) + "i";
return real + " + " + imaginary + "i"; return real + " + " + imaginary + "i";
} }
......
...@@ -7,7 +7,6 @@ import static org.assertj.core.api.Assertions.*; ...@@ -7,7 +7,6 @@ import static org.assertj.core.api.Assertions.*;
public class ComplexTest { public class ComplexTest {
private Complex onePlusI; private Complex onePlusI;
private Complex minusI; private Complex minusI;
private Complex minusOne;
private Complex oneMinusI; private Complex oneMinusI;
private Complex twoI; private Complex twoI;
private Complex two; private Complex two;
...@@ -19,7 +18,6 @@ public class ComplexTest { ...@@ -19,7 +18,6 @@ public class ComplexTest {
void initializeTestValues(){ void initializeTestValues(){
onePlusI = new Complex(1,1); onePlusI = new Complex(1,1);
minusI = new Complex(0,-1); minusI = new Complex(0,-1);
minusOne = new Complex(-1,0);
oneMinusI = new Complex(1, -1); oneMinusI = new Complex(1, -1);
twoI = new Complex(0,2); twoI = new Complex(0,2);
two = new Complex(2,0); two = new Complex(2,0);
...@@ -32,6 +30,7 @@ public class ComplexTest { ...@@ -32,6 +30,7 @@ public class ComplexTest {
void testEquals(){ void testEquals(){
assertThat(onePlusI).isEqualTo(onePlusI); assertThat(onePlusI).isEqualTo(onePlusI);
assertThat(onePlusI).isEqualTo(new Complex(1, 1)); assertThat(onePlusI).isEqualTo(new Complex(1, 1));
assertThat(onePlusI).isNotEqualTo(oneMinusI);
assertThat(two).isNotEqualTo(twoI); assertThat(two).isNotEqualTo(twoI);
} }
...@@ -129,4 +128,14 @@ public class ComplexTest { ...@@ -129,4 +128,14 @@ public class ComplexTest {
assertThat(twoI.toString()).isEqualTo("2.0i"); assertThat(twoI.toString()).isEqualTo("2.0i");
assertThat(two.toString()).isEqualTo("2.0"); 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