Skip to content

Commit

Permalink
1.2. Predicate. Проверить, что число положительное и четное
Browse files Browse the repository at this point in the history
  • Loading branch information
devvk committed Oct 7, 2024
1 parent 28ae7ae commit a72afd3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/ru/job4j/lambda/PredicateCheckEvenAndPositive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.job4j.lambda;

import java.util.function.Predicate;

public class PredicateCheckEvenAndPositive {

public static boolean check(int num) {
return check(i -> i % 2 == 0 && i > 0, num);
}

private static boolean check(Predicate<Integer> predicate, int num) {
return predicate.test(num);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ru.job4j.lambda;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class PredicateCheckEvenAndPositiveTest {

@Test
public void test() {
assertTrue(PredicateCheckEvenAndPositive.check(2));
assertFalse(PredicateCheckEvenAndPositive.check(-2));
assertFalse(PredicateCheckEvenAndPositive.check(1));
}
}

0 comments on commit a72afd3

Please sign in to comment.