Search in sources :

Example 16 with DoublePredicate

use of java.util.function.DoublePredicate in project j2objc by google.

the class DoublePredicateTest method testOr.

public void testOr() throws Exception {
    double arg = 5.0d;
    AtomicBoolean alwaysTrueInvoked = new AtomicBoolean(false);
    AtomicBoolean alwaysTrue2Invoked = new AtomicBoolean(false);
    AtomicBoolean alwaysFalseInvoked = new AtomicBoolean(false);
    AtomicBoolean alwaysFalse2Invoked = new AtomicBoolean(false);
    AtomicBoolean[] invocationState = { alwaysTrueInvoked, alwaysTrue2Invoked, alwaysFalseInvoked, alwaysFalse2Invoked };
    DoublePredicate alwaysTrue = x -> {
        alwaysTrueInvoked.set(true);
        assertEquals(x, arg);
        return true;
    };
    DoublePredicate alwaysTrue2 = x -> {
        alwaysTrue2Invoked.set(true);
        assertEquals(x, arg);
        return true;
    };
    DoublePredicate alwaysFalse = x -> {
        alwaysFalseInvoked.set(true);
        assertEquals(x, arg);
        return false;
    };
    DoublePredicate alwaysFalse2 = x -> {
        alwaysFalse2Invoked.set(true);
        assertEquals(x, arg);
        return false;
    };
    // true || true
    resetToFalse(invocationState);
    assertTrue(alwaysTrue.or(alwaysTrue2).test(arg));
    assertTrue(alwaysTrueInvoked.get() && !alwaysTrue2Invoked.get());
    // true || false
    resetToFalse(invocationState);
    assertTrue(alwaysTrue.or(alwaysFalse).test(arg));
    assertTrue(alwaysTrueInvoked.get() && !alwaysFalseInvoked.get());
    // false || false
    resetToFalse(invocationState);
    assertFalse(alwaysFalse.or(alwaysFalse2).test(arg));
    assertTrue(alwaysFalseInvoked.get() && alwaysFalse2Invoked.get());
    // false || true
    resetToFalse(invocationState);
    assertTrue(alwaysFalse.or(alwaysTrue).test(arg));
    assertTrue(alwaysFalseInvoked.get() && alwaysTrueInvoked.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestCase(junit.framework.TestCase) DoublePredicate(java.util.function.DoublePredicate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DoublePredicate(java.util.function.DoublePredicate)

Example 17 with DoublePredicate

use of java.util.function.DoublePredicate in project j2objc by google.

the class DoublePredicateTest method testAnd.

public void testAnd() throws Exception {
    double arg = 5.0d;
    AtomicBoolean alwaysTrueInvoked = new AtomicBoolean(false);
    AtomicBoolean alwaysTrue2Invoked = new AtomicBoolean(false);
    AtomicBoolean alwaysFalseInvoked = new AtomicBoolean(false);
    AtomicBoolean alwaysFalse2Invoked = new AtomicBoolean(false);
    AtomicBoolean[] invocationState = { alwaysTrueInvoked, alwaysTrue2Invoked, alwaysFalseInvoked, alwaysFalse2Invoked };
    DoublePredicate alwaysTrue = x -> {
        alwaysTrueInvoked.set(true);
        assertEquals(x, arg);
        return true;
    };
    DoublePredicate alwaysTrue2 = x -> {
        alwaysTrue2Invoked.set(true);
        assertEquals(x, arg);
        return true;
    };
    DoublePredicate alwaysFalse = x -> {
        alwaysFalseInvoked.set(true);
        assertEquals(x, arg);
        return false;
    };
    DoublePredicate alwaysFalse2 = x -> {
        alwaysFalse2Invoked.set(true);
        assertEquals(x, arg);
        return false;
    };
    // true && true
    resetToFalse(invocationState);
    assertTrue(alwaysTrue.and(alwaysTrue2).test(arg));
    assertTrue(alwaysTrueInvoked.get() && alwaysTrue2Invoked.get());
    // true && false
    resetToFalse(invocationState);
    assertFalse(alwaysTrue.and(alwaysFalse).test(arg));
    assertTrue(alwaysTrueInvoked.get() && alwaysFalseInvoked.get());
    // false && false
    resetToFalse(invocationState);
    assertFalse(alwaysFalse.and(alwaysFalse2).test(arg));
    assertTrue(alwaysFalseInvoked.get() && !alwaysFalse2Invoked.get());
    // false && true
    resetToFalse(invocationState);
    assertFalse(alwaysFalse.and(alwaysTrue).test(arg));
    assertTrue(alwaysFalseInvoked.get() && !alwaysTrueInvoked.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestCase(junit.framework.TestCase) DoublePredicate(java.util.function.DoublePredicate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DoublePredicate(java.util.function.DoublePredicate)

Example 18 with DoublePredicate

use of java.util.function.DoublePredicate in project j2objc by google.

the class DoublePredicateTest method testAnd_null.

public void testAnd_null() throws Exception {
    DoublePredicate alwaysTrue = x -> true;
    try {
        alwaysTrue.and(null);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestCase(junit.framework.TestCase) DoublePredicate(java.util.function.DoublePredicate) DoublePredicate(java.util.function.DoublePredicate)

Aggregations

DoublePredicate (java.util.function.DoublePredicate)18 Test (org.junit.Test)11 Predicate (java.util.function.Predicate)9 List (java.util.List)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 DoublePredicateAssert (org.assertj.core.api.DoublePredicateAssert)7 DoublePredicateAssertBaseTest (org.assertj.core.api.DoublePredicateAssertBaseTest)7 PredicateDescription (org.assertj.core.presentation.PredicateDescription)7 FailureMessages.actualIsNull (org.assertj.core.util.FailureMessages.actualIsNull)7 Lists.newArrayList (org.assertj.core.util.Lists.newArrayList)7 Mockito.verify (org.mockito.Mockito.verify)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 IntPredicate (java.util.function.IntPredicate)5 Collectors (java.util.stream.Collectors)5 DoubleStream (java.util.stream.DoubleStream)5 TestCase (junit.framework.TestCase)5 NoElementsShouldMatch.noElementsShouldMatch (org.assertj.core.error.NoElementsShouldMatch.noElementsShouldMatch)5 ShouldNotAccept.shouldNotAccept (org.assertj.core.error.ShouldNotAccept.shouldNotAccept)5 File (java.io.File)4 URI (java.net.URI)4