Skip to content

Commit

Permalink
Make Interval.reborn(left,right,h/n) method private. Add reborn(h/n) …
Browse files Browse the repository at this point in the history
…instead
  • Loading branch information
andrei-punko committed Oct 18, 2024
1 parent b4cc451 commit ca48af6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/main/java/by/andd3dfx/math/Interval.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int n() {
return n;
}

public void reborn(double left, double right, double h) {
private void reborn(double left, double right, double h) {
assert (left < right && h > 0 && h <= right - left);

this.left = left;
Expand All @@ -47,7 +47,7 @@ public void reborn(double left, double right, double h) {
this.n = (int) Math.floor((right - left) / h); // если необходимо, n будет на 1 больше
}

public void reborn(double left, double right, int n) {
private void reborn(double left, double right, int n) {
assert (left < right && n > 0);

this.left = left;
Expand All @@ -67,4 +67,12 @@ public int i(double x) {

return (int) ((x - left) / h);
}

public void reborn(double h) {
reborn(left, right, h);
}

public void reborn(int n) {
reborn(left, right, n);
}
}
4 changes: 2 additions & 2 deletions src/main/java/by/andd3dfx/math/pde/equation/Equation.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ protected double gF(double x, double t, double U) {

protected void prepare(double h, double tau) {
assert (h > 0 && tau > 0); // установка шагов по пространственной и временной координатам
area.x().reborn(area.x().left(), area.x().right(), h);
area.t().reborn(area.t().left(), area.t().right(), tau);
area.x().reborn(h);
area.t().reborn(tau);

arr = new Matrix(area.t().n() + 1, area.x().n() + 1); // Место для решения уравнения
for (var i = 0; i <= area.x().n(); i++) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/by/andd3dfx/math/IntervalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ void paramsConstructorWithH() {

@Test
void rebornWithN() {
var interval = new Interval(2.5, 10.5, 10);
var interval = new Interval(5.0, 10.0, 10);

interval.reborn(5.0, 10.0, 100);
interval.reborn(100);

assertThat(interval.left()).isEqualTo(5.0);
assertThat(interval.right()).isEqualTo(10.0);
Expand All @@ -50,9 +50,9 @@ void rebornWithN() {

@Test
void rebornWithH() {
var interval = new Interval(2.5, 10.5, 10);
var interval = new Interval(5.0, 10.0, 10);

interval.reborn(5.0, 10.0, 0.2);
interval.reborn(0.2);

assertThat(interval.left()).isEqualTo(5.0);
assertThat(interval.right()).isEqualTo(10.0);
Expand Down

0 comments on commit ca48af6

Please sign in to comment.