From ff1356e35f6cac807452fe2e04aa6d33ef59e7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sun, 16 Nov 2025 20:51:53 +0100 Subject: [PATCH] Initial commit. --- .gitignore | 2 + eclipse-java-google-style.xml | 340 ++++++++++++++++++ pom.xml | 112 ++++++ src/main/java/fr/insa/gei/App.java | 10 + src/main/java/fr/insa/gei/angles/IAngle.java | 73 ++++ .../fr/insa/gei/angles/IAngleFactory.java | 66 ++++ .../java/fr/insa/gei/fractions/IFraction.java | 104 ++++++ .../insa/gei/fractions/IFractionFactory.java | 24 ++ src/test/java/fr/insa/gei/AppTest.java | 19 + .../java/fr/insa/gei/angles/IAngleTest.java | 20 ++ .../fr/insa/gei/fractions/IFractionTest.java | 20 ++ 11 files changed, 790 insertions(+) create mode 100644 .gitignore create mode 100644 eclipse-java-google-style.xml create mode 100644 pom.xml create mode 100644 src/main/java/fr/insa/gei/App.java create mode 100644 src/main/java/fr/insa/gei/angles/IAngle.java create mode 100644 src/main/java/fr/insa/gei/angles/IAngleFactory.java create mode 100644 src/main/java/fr/insa/gei/fractions/IFraction.java create mode 100644 src/main/java/fr/insa/gei/fractions/IFractionFactory.java create mode 100644 src/test/java/fr/insa/gei/AppTest.java create mode 100644 src/test/java/fr/insa/gei/angles/IAngleTest.java create mode 100644 src/test/java/fr/insa/gei/fractions/IFractionTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a970b6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.mvn +target diff --git a/eclipse-java-google-style.xml b/eclipse-java-google-style.xml new file mode 100644 index 0000000..05f42b6 --- /dev/null +++ b/eclipse-java-google-style.xml @@ -0,0 +1,340 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + > + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..7e892fb --- /dev/null +++ b/pom.xml @@ -0,0 +1,112 @@ + + + 4.0.0 + + fr.insa.gei + pdla + 1.0-SNAPSHOT + + pdla + + http://www.example.com + + + UTF-8 + 17 + + + + + + org.junit + junit-bom + 5.11.0 + pom + import + + + + + + + org.junit.jupiter + junit-jupiter-api + test + + + + org.junit.jupiter + junit-jupiter-params + test + + + + + + + + + maven-clean-plugin + 3.4.0 + + + + maven-resources-plugin + 3.3.1 + + + maven-compiler-plugin + 3.13.0 + + + maven-surefire-plugin + 3.3.0 + + + maven-jar-plugin + 3.4.2 + + + maven-install-plugin + 3.1.2 + + + maven-deploy-plugin + 3.1.2 + + + + maven-site-plugin + 3.12.1 + + + maven-project-info-reports-plugin + 3.6.1 + + + + net.revelc.code.formatter + formatter-maven-plugin + 2.24.1 + + + ${project.basedir}/eclipse-java-google-style.xml + + + + + format + + + + + + + + diff --git a/src/main/java/fr/insa/gei/App.java b/src/main/java/fr/insa/gei/App.java new file mode 100644 index 0000000..e0ee82c --- /dev/null +++ b/src/main/java/fr/insa/gei/App.java @@ -0,0 +1,10 @@ +package fr.insa.gei; + +/** + * Hello world! + */ +public class App { + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} diff --git a/src/main/java/fr/insa/gei/angles/IAngle.java b/src/main/java/fr/insa/gei/angles/IAngle.java new file mode 100644 index 0000000..61f4a2e --- /dev/null +++ b/src/main/java/fr/insa/gei/angles/IAngle.java @@ -0,0 +1,73 @@ +package fr.insa.gei.angles; + +public interface IAngle extends Comparable { + + /** + * Get the value of this angle in degrees. + * + * @return the value of this angle in degrees. + */ + double toDegrees(); + + /** + * Get the value of this angle in radians. + * + * @return the value of this angle in radians. + */ + double toRadians(); + + /** + * Get the cosine of this angle. + * + * @return the cosine of this angle. + */ + double cos(); + + /** + * Get the sine of this angle. + * + * @return the sine of this angle. + */ + double sin(); + + /** + * Get the tangent of this angle. + * + * @return the tangent of this angle. + */ + double tan(); + + /** + * Add another angle to this angle. + * + * @param other The other angle to add. + * @return a new angle representing the sum of this angle and the other angle. + */ + IAngle add(IAngle other); + + /** + * Subtract another angle from this angle. + * + * @param other The other angle to subtract. + * @return a new angle representing the difference between this angle and the + * other angle. + */ + IAngle sub(IAngle other); + + /** + * Multiply this angle by a factor. + * + * @param factor The factor to multiply by. + * @return a new angle representing this angle multiplied by the factor. + */ + IAngle mul(double factor); + + /** + * Divide this angle by a divisor. + * + * @param divisor The divisor to divide by. + * @return a new angle representing this angle divided by the divisor. + */ + IAngle div(double divisor); + +} diff --git a/src/main/java/fr/insa/gei/angles/IAngleFactory.java b/src/main/java/fr/insa/gei/angles/IAngleFactory.java new file mode 100644 index 0000000..2504610 --- /dev/null +++ b/src/main/java/fr/insa/gei/angles/IAngleFactory.java @@ -0,0 +1,66 @@ +package fr.insa.gei.angles; + +public interface IAngleFactory { + + /** + * Construct a new Angle object using the given value in radians. + * + * @param radians Value of the angle in radians. + * @return a new Angle object. + */ + public Angle fromRadians(double radians); + + /** + * Construct a new Angle object using the given value in degrees. + * + * @param degrees Value of the angle in degrees. + * @return a new Angle object. + */ + public Angle fromDegrees(double degrees); + + /** + * Construct a new Angle object corresponding to the arc cosine of the given + * value. + * + * @param a Value for which to compute the arc cosine. + * @return a new Angle object. + */ + public default Angle acos(double a) { + return fromRadians(Math.acos(a)); + } + + /** + * Construct a new Angle object corresponding to the arc sine of the given + * value. + * + * @param a Value for which to compute the arc sine. + * @return a new Angle object. + */ + public default Angle asin(double a) { + return fromRadians(Math.asin(a)); + } + + /** + * Construct a new Angle object corresponding to the arc tangent of the given + * value. + * + * @param a Value for which to compute the arc tangent. + * @return a new Angle object. + */ + public default Angle atan(double a) { + return fromRadians(Math.atan(a)); + } + + /** + * Construct a new Angle object corresponding to the arc tangent of the given + * values. + * + * @param y Value for which to compute the arc tangent. + * @param x Value for which to compute the arc tangent. + * @return a new Angle object. + */ + public default Angle atan2(double y, double x) { + return fromRadians(Math.atan2(y, x)); + } + +} diff --git a/src/main/java/fr/insa/gei/fractions/IFraction.java b/src/main/java/fr/insa/gei/fractions/IFraction.java new file mode 100644 index 0000000..6b899c2 --- /dev/null +++ b/src/main/java/fr/insa/gei/fractions/IFraction.java @@ -0,0 +1,104 @@ +package fr.insa.gei.fractions; + +public interface IFraction extends Comparable { + + /** + * Get the numerator of this fraction in lowest term. + * + * @return the numerator of this fraction in lowest term. + */ + public int getNumerator(); + + /** + * Get the denominator of this fraction in lowest term. + * + * @return the denominator of this fraction in lowest term. + */ + public int getDenominator(); + + /** + * Add another fraction to this fraction. + * + * @param f the fraction to add + * @return the result of the addition + */ + public IFraction add(IFraction f); + + /** + * Add an integer value to this fraction. + * + * @param value the integer value to add + * @return the result of the addition + */ + public IFraction add(int value); + + /** + * Subtract another fraction from this fraction. + * + * @param f the fraction to subtract + * @return the result of the subtraction + */ + public IFraction sub(IFraction f); + + /** + * Subtract an integer value from this fraction. + * + * @param value the integer value to subtract + * @return the result of the subtraction + */ + public IFraction sub(int value); + + /** + * Multiply this fraction by another fraction. + * + * @param f the fraction to multiply by + * @return the result of the multiplication + */ + public IFraction mul(IFraction f); + + /** + * Multiply this fraction by an integer value. + * + * @param value the integer value to multiply by + * @return the result of the multiplication + */ + public IFraction mul(int value); + + /** + * Divide this fraction by another fraction. + * + * @param f the fraction to divide by + * @return the result of the division + */ + public IFraction div(IFraction f); + + /** + * Divide this fraction by an integer value. + * + * @param value the integer value to divide by + * @return the result of the division + */ + public IFraction div(int value); + + /** + * Invert this fraction. + * + * @return the inverted fraction + */ + public IFraction inv(); + + /** + * Negate this fraction. + * + * @return the negated fraction + */ + public IFraction neg(); + + /** + * Convert this fraction to a double value. + * + * @return the double value of this fraction + */ + public double toDouble(); + +} diff --git a/src/main/java/fr/insa/gei/fractions/IFractionFactory.java b/src/main/java/fr/insa/gei/fractions/IFractionFactory.java new file mode 100644 index 0000000..ae68242 --- /dev/null +++ b/src/main/java/fr/insa/gei/fractions/IFractionFactory.java @@ -0,0 +1,24 @@ +package fr.insa.gei.fractions; + +public interface IFractionFactory { + + /** + * Creates a fraction with given numerator and denominator. + * + * @param numerator the numerator of the fraction + * @param denominator the denominator of the fraction + * @return a new fraction instance + */ + public Fraction create(int numerator, int denominator); + + /** + * Creates a fraction with given numerator and denominator equal to 1. + * + * @param numerator the numerator of the fraction + * @return a new fraction instance + */ + public default Fraction create(int numerator) { + return this.create(numerator, 1); + } + +} diff --git a/src/test/java/fr/insa/gei/AppTest.java b/src/test/java/fr/insa/gei/AppTest.java new file mode 100644 index 0000000..9cd31ee --- /dev/null +++ b/src/test/java/fr/insa/gei/AppTest.java @@ -0,0 +1,19 @@ +package fr.insa.gei; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +/** + * Unit test for simple App. + */ +public class AppTest { + + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() { + assertTrue(true); + } +} diff --git a/src/test/java/fr/insa/gei/angles/IAngleTest.java b/src/test/java/fr/insa/gei/angles/IAngleTest.java new file mode 100644 index 0000000..492b07b --- /dev/null +++ b/src/test/java/fr/insa/gei/angles/IAngleTest.java @@ -0,0 +1,20 @@ +package fr.insa.gei.angles; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public abstract class IAngleTest { + + private IAngleFactory factory; + + protected IAngleTest(IAngleFactory factory) { + this.factory = factory; + } + + @Test + public void test1() { + assertEquals(this.factory.fromRadians(0), this.factory.fromDegrees(0)); + } + +} diff --git a/src/test/java/fr/insa/gei/fractions/IFractionTest.java b/src/test/java/fr/insa/gei/fractions/IFractionTest.java new file mode 100644 index 0000000..0f1d67c --- /dev/null +++ b/src/test/java/fr/insa/gei/fractions/IFractionTest.java @@ -0,0 +1,20 @@ +package fr.insa.gei.fractions; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public abstract class IFractionTest { + + private IFractionFactory factory; + + protected IFractionTest(IFractionFactory factory) { + this.factory = factory; + } + + @Test + public void test1() { + assertEquals(this.factory.create(0), this.factory.create(0, 10)); + } + +}