Skip to content

Commit

Permalink
3. Перегрузить метод max для трех чисел.
Browse files Browse the repository at this point in the history
  • Loading branch information
Temzor committed Nov 1, 2023
1 parent 3c4f804 commit fc47452
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/ru/j4j/condition/Max.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

public class Max {
public static int max(int first, int second) {
return first >= second ? first : second;
return Math.max(first, second);
}

public static int max(int first, int second, int third) {
return max(
first,
max(second, third)
);
}

public static int max(int first, int second, int third, int fourth) {
return max(
first,
max(second, third, fourth)
);
}
}
10 changes: 10 additions & 0 deletions src/test/java/ru/j4j/condition/MaxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ void whenSecondMoreFirstThenReturnSecond() {
void whenFirstISEqualsSecondThenReturnFirst() {
assertThat(Max.max(5, 1)).isEqualTo(5);
}

@Test
void testThreeComponent() {
assertThat(Max.max(5, 1, 16)).isEqualTo(16);
}

@Test
void testFourComponent() {
assertThat(Max.max(5, 1, 16, 25)).isEqualTo(25);
}
}

0 comments on commit fc47452

Please sign in to comment.