-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Solution. Fix couple of issues with loop ranges
- Loading branch information
1 parent
264c002
commit 57bab0c
Showing
6 changed files
with
212 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
src/test/java/by/andd3dfx/math/pde/solver/SolutionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
package by.andd3dfx.math.pde.solver; | ||
|
||
import by.andd3dfx.math.Area; | ||
import by.andd3dfx.math.Interval; | ||
import by.andd3dfx.math.Matrix; | ||
import by.andd3dfx.math.pde.equation.Equation; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static by.andd3dfx.util.FileComparisonHelper.BUILD_PATH; | ||
import static by.andd3dfx.util.FileComparisonHelper.checkGeneratedFileContent; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class SolutionTest { | ||
|
||
@Test | ||
void sUtForArray() throws IOException { | ||
var fileName = "sUt-array.txt"; | ||
var solution = buildSolution(); | ||
|
||
solution.sUt(BUILD_PATH + fileName, new double[]{2.5, 5.0}); | ||
|
||
checkGeneratedFileContent(fileName); | ||
} | ||
|
||
@Test | ||
void sUtForArrayWithWrongParam() { | ||
var solution = buildSolution(); | ||
|
||
assertThrows(AssertionError.class, () -> | ||
solution.sUt(BUILD_PATH + "sUt-arr.txt", new double[]{1.0, 2.5})); | ||
assertThrows(AssertionError.class, () -> | ||
solution.sUt(BUILD_PATH + "sUt-arr.txt", new double[]{2.5, 2.6, 6.5})); | ||
} | ||
|
||
@Test | ||
void sUt() throws IOException { | ||
var fileName = "sUt.txt"; | ||
var solution = buildSolution(); | ||
|
||
solution.sUt(BUILD_PATH + fileName, 5.0); | ||
|
||
checkGeneratedFileContent(fileName); | ||
} | ||
|
||
@Test | ||
void sUtWithWrongParam() { | ||
var solution = buildSolution(); | ||
|
||
assertThrows(AssertionError.class, () -> solution.sUt(BUILD_PATH + "sUt.txt", 1.0)); | ||
assertThrows(AssertionError.class, () -> solution.sUt(BUILD_PATH + "sUt.txt", 6.5)); | ||
} | ||
|
||
@Test | ||
void sUxForArray() throws IOException { | ||
var fileName = "sUx-array.txt"; | ||
var solution = buildSolution(); | ||
|
||
solution.sUx(BUILD_PATH + fileName, new double[]{11.0, 12.0}); | ||
|
||
checkGeneratedFileContent(fileName); | ||
} | ||
|
||
@Test | ||
void sUxForArrayWithWrongParam() { | ||
var solution = buildSolution(); | ||
|
||
assertThrows(AssertionError.class, () -> | ||
solution.sUx(BUILD_PATH + "sUx-arr.txt", new double[]{9.0, 11.0})); | ||
assertThrows(AssertionError.class, () -> | ||
solution.sUx(BUILD_PATH + "sUx-arr.txt", new double[]{10.0, 12.5, 13.5})); | ||
} | ||
|
||
@Test | ||
void sUx() throws IOException { | ||
var fileName = "sUx.txt"; | ||
var solution = buildSolution(); | ||
|
||
solution.sUx(BUILD_PATH + fileName, 12.0); | ||
|
||
checkGeneratedFileContent(fileName); | ||
} | ||
|
||
@Test | ||
void sUxWithWrongParam() { | ||
var solution = buildSolution(); | ||
|
||
assertThrows(AssertionError.class, () -> solution.sUx(BUILD_PATH + "sUx.txt", 9.0)); | ||
assertThrows(AssertionError.class, () -> solution.sUx(BUILD_PATH + "sUx.txt", 13.5)); | ||
} | ||
|
||
@Test | ||
void gUtForDouble() { | ||
var solution = buildSolution(); | ||
|
||
var result = solution.gUt(5.0); | ||
|
||
checkUtAssertions(result); | ||
} | ||
|
||
@Test | ||
void gUtForInt() { | ||
var solution = buildSolution(); | ||
|
||
var result = solution.gUt(2); | ||
|
||
checkUtAssertions(result); | ||
} | ||
|
||
@Test | ||
void gUtForIntWithWrongParam() { | ||
var solution = buildSolution(); | ||
|
||
assertThrows(AssertionError.class, () -> solution.gUt(-1)); | ||
assertThrows(AssertionError.class, () -> solution.gUt(solution.solution().getM())); | ||
} | ||
|
||
@Test | ||
void gUxForDouble() { | ||
var solution = buildSolution(); | ||
|
||
var result = solution.gUx(10 + 3 / 4.); | ||
|
||
checkUxAssertions(result); | ||
} | ||
|
||
@Test | ||
void gUxForInt() { | ||
var solution = buildSolution(); | ||
|
||
var result = solution.gUx(1); | ||
|
||
checkUxAssertions(result); | ||
} | ||
|
||
@Test | ||
void gUxForIntWithWrongParam() { | ||
var solution = buildSolution(); | ||
|
||
assertThrows(AssertionError.class, () -> solution.gUx(-1)); | ||
assertThrows(AssertionError.class, () -> solution.gUx(solution.solution().getN())); | ||
} | ||
|
||
/** | ||
* <pre> | ||
* Build solution for | ||
* - space interval [10,13] with 3 steps & | ||
* - time interval [2,6] with 2 steps | ||
* - matrix: | ||
* [[50,80,90,99], | ||
* [30,70,120,125], | ||
* [45,56,78,786]] | ||
* </pre> | ||
*/ | ||
private Solution<Equation> buildSolution() { | ||
var spaceSteps = 4; | ||
var timeSteps = 3; | ||
|
||
var solutionMatrix = new Matrix(timeSteps, spaceSteps); | ||
solutionMatrix.set(0, new double[]{50, 80, 90, 99}); | ||
solutionMatrix.set(1, new double[]{30, 70, 120, 125}); | ||
solutionMatrix.set(2, new double[]{45, 56, 78, 786}); | ||
|
||
return new Solution<>(null, new Area( | ||
new Interval(10, 13, spaceSteps), | ||
new Interval(2, 6, timeSteps) | ||
), solutionMatrix); | ||
} | ||
|
||
private static void checkUtAssertions(Matrix result) { | ||
assertThat(result.getM()).isEqualTo(2); | ||
assertThat(result.getN()).isEqualTo(4); | ||
assertThat(result.x(0)).isEqualTo(10); | ||
assertThat(result.x(1)).isEqualTo(10 + 3 / 4.); | ||
assertThat(result.x(2)).isEqualTo(10 + 6 / 4.); | ||
assertThat(result.x(3)).isEqualTo(10 + 9 / 4.); | ||
assertThat(result.y(0)).isEqualTo(45); | ||
assertThat(result.y(1)).isEqualTo(56); | ||
assertThat(result.y(2)).isEqualTo(78); | ||
assertThat(result.y(3)).isEqualTo(786); | ||
} | ||
|
||
private static void checkUxAssertions(Matrix result) { | ||
assertThat(result.getM()).isEqualTo(2); | ||
assertThat(result.getN()).isEqualTo(3); | ||
assertThat(result.x(0)).isEqualTo(2); | ||
assertThat(result.x(1)).isEqualTo(2 + 4 / 3.); | ||
assertThat(result.x(2)).isEqualTo(2 + 8 / 3.); | ||
assertThat(result.y(0)).isEqualTo(80); | ||
assertThat(result.y(1)).isEqualTo(70); | ||
assertThat(result.y(2)).isEqualTo(56); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
10.0 50.0 45.0 | ||
10.75 80.0 56.0 | ||
11.5 90.0 78.0 | ||
12.25 99.0 786.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
10.0 45.0 | ||
10.75 56.0 | ||
11.5 78.0 | ||
12.25 786.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
2.0 80.0 90.0 | ||
3.333333333333333 70.0 120.0 | ||
4.666666666666666 56.0 78.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
2.0 90.0 | ||
3.333333333333333 120.0 | ||
4.666666666666666 78.0 |