Skip to content

Commit

Permalink
6.5.2. Поиск минимума в диапазоне;
Browse files Browse the repository at this point in the history
  • Loading branch information
Temzor committed Sep 30, 2023
1 parent d20b31b commit acd7d87
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/ru/j4j/array/MinDiapason.java
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;
}
}
37 changes: 37 additions & 0 deletions src/test/java/ru/j4j/array/MinDiapasonTest.java
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);
}
}

0 comments on commit acd7d87

Please sign in to comment.