From d6eaf87d91a682ac68057709cbb86c70970c6d27 Mon Sep 17 00:00:00 2001 From: Andrei Punko Date: Thu, 10 Oct 2024 23:30:00 +0300 Subject: [PATCH] Add IntervalTest --- build.gradle | 1 + src/main/java/by/andd3dfx/math/Interval.java | 4 + .../java/by/andd3dfx/math/IntervalTest.java | 89 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 src/test/java/by/andd3dfx/math/IntervalTest.java diff --git a/build.gradle b/build.gradle index 5c1b9f0..2dcc864 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,7 @@ dependencies { testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.hamcrest:hamcrest:3.0' + testImplementation 'org.assertj:assertj-core:3.26.3' } test { diff --git a/src/main/java/by/andd3dfx/math/Interval.java b/src/main/java/by/andd3dfx/math/Interval.java index ed64cab..a196861 100644 --- a/src/main/java/by/andd3dfx/math/Interval.java +++ b/src/main/java/by/andd3dfx/math/Interval.java @@ -31,6 +31,10 @@ public double x2() { return x2; } + public double h() { + return h; + } + public int n() { return n; } diff --git a/src/test/java/by/andd3dfx/math/IntervalTest.java b/src/test/java/by/andd3dfx/math/IntervalTest.java new file mode 100644 index 0000000..2cea753 --- /dev/null +++ b/src/test/java/by/andd3dfx/math/IntervalTest.java @@ -0,0 +1,89 @@ +package by.andd3dfx.math; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +class IntervalTest { + + @Test + void defaultConstructor() { + var interval = new Interval(); + + assertThat(interval.x1()).isEqualTo(0.0); + assertThat(interval.x2()).isEqualTo(1.0); + assertThat(interval.h()).isEqualTo(1.0); + assertThat(interval.n()).isEqualTo(1); + } + + @Test + void paramsConstructorWithN() { + var interval = new Interval(2.5, 10.5, 10); + + assertThat(interval.x1()).isEqualTo(2.5); + assertThat(interval.x2()).isEqualTo(10.5); + assertThat(interval.h()).isEqualTo(0.8); + assertThat(interval.n()).isEqualTo(10); + } + + @Test + void paramsConstructorWithH() { + var interval = new Interval(2.5, 10.5, 0.1); + + assertThat(interval.x1()).isEqualTo(2.5); + assertThat(interval.x2()).isEqualTo(10.5); + assertThat(interval.h()).isEqualTo(0.1); + assertThat(interval.n()).isEqualTo(80); + } + + @Test + void rebornWithN() { + var interval = new Interval(2.5, 10.5, 10); + + interval.reborn(5.0, 10.0, 100); + + assertThat(interval.x1()).isEqualTo(5.0); + assertThat(interval.x2()).isEqualTo(10.0); + assertThat(interval.h()).isEqualTo(0.05); + assertThat(interval.n()).isEqualTo(100); + } + + @Test + void rebornWithH() { + var interval = new Interval(2.5, 10.5, 10); + + interval.reborn(5.0, 10.0, 0.2); + + assertThat(interval.x1()).isEqualTo(5.0); + assertThat(interval.x2()).isEqualTo(10.0); + assertThat(interval.h()).isEqualTo(0.2); + assertThat(interval.n()).isEqualTo(25); + } + + @Test + void x() { + var interval = new Interval(2.0, 12.0, 5); + + assertThat(interval.x(0)).isEqualTo(2.0); + assertThat(interval.x(2)).isEqualTo(6.0); + } + + @Test + void i() { + var interval = new Interval(2.0, 12.0, 5); + + assertThat(interval.i(2.0)).isEqualTo(0); + assertThat(interval.i(5.9)).isEqualTo(1); + assertThat(interval.i(6.1)).isEqualTo(2); + } + + @Test + void saveFuncSimple() { + // TODO + } + + @Test + void saveFuncForParameterizedXAndY() { + // TODO + } +}