-
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.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ru.j4j.array; | ||
|
||
public class MinDiapason { | ||
public static int findMinDiapason(int[] array, int start, int finish) { | ||
int min = array[start]; | ||
for (int i = start; i <= finish; i++) { | ||
if (array[i] < min) { | ||
min = array[i]; | ||
} | ||
} | ||
return min; | ||
} | ||
} |
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,37 @@ | ||
package ru.j4j.array; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class MinDiapasonTest { | ||
@Test | ||
public void whenFirstMin() { | ||
int[] array = new int[] {-1, 0, 5, 10}; | ||
int start = 1; | ||
int finish = 3; | ||
int result = MinDiapason.findMinDiapason(array, start, finish); | ||
int expected = 0; | ||
assertThat(result).isEqualTo(expected); | ||
} | ||
|
||
@Test | ||
public void whenLastMin() { | ||
int[] array = new int[] {10, 5, 3, 1}; | ||
int start = 1; | ||
int finish = 3; | ||
int result = MinDiapason.findMinDiapason(array, start, finish); | ||
int expected = 1; | ||
assertThat(result).isEqualTo(expected); | ||
} | ||
|
||
@Test | ||
public void whenMiddleMin() { | ||
int[] array = new int[] {10, 2, 5, 1}; | ||
int start = 0; | ||
int finish = 2; | ||
int result = MinDiapason.findMinDiapason(array, start, finish); | ||
int expected = 2; | ||
assertThat(result).isEqualTo(expected); | ||
} | ||
} |