Skip to content

Commit

Permalink
Add IntervalTest
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-punko committed Oct 10, 2024
1 parent ae79a9d commit d6eaf87
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/by/andd3dfx/math/Interval.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public double x2() {
return x2;
}

public double h() {
return h;
}

public int n() {
return n;
}
Expand Down
89 changes: 89 additions & 0 deletions src/test/java/by/andd3dfx/math/IntervalTest.java
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit d6eaf87

Please sign in to comment.