Search in sources :

Example 1 with LongPredicate

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

the class LongPredicateTest method testAnd_null.

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

Example 2 with LongPredicate

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

the class LongPredicateTest method testNegate.

public void testNegate() throws Exception {
    long arg = 5L;
    LongPredicate alwaysTrue = x -> {
        assertEquals(x, arg);
        return true;
    };
    assertFalse(alwaysTrue.negate().test(arg));
    LongPredicate alwaysFalse = x -> {
        assertEquals(x, arg);
        return false;
    };
    assertTrue(alwaysFalse.negate().test(arg));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestCase(junit.framework.TestCase) LongPredicate(java.util.function.LongPredicate) LongPredicate(java.util.function.LongPredicate)

Example 3 with LongPredicate

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

the class LongPredicateTest method testAnd.

public void testAnd() throws Exception {
    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 };
    LongPredicate alwaysTrue = x -> {
        alwaysTrueInvoked.set(true);
        return true;
    };
    LongPredicate alwaysTrue2 = x -> {
        alwaysTrue2Invoked.set(true);
        return true;
    };
    LongPredicate alwaysFalse = x -> {
        alwaysFalseInvoked.set(true);
        return false;
    };
    LongPredicate alwaysFalse2 = x -> {
        alwaysFalse2Invoked.set(true);
        return false;
    };
    // true && true
    resetToFalse(invocationState);
    assertTrue(alwaysTrue.and(alwaysTrue2).test(1L));
    assertTrue(alwaysTrueInvoked.get() && alwaysTrue2Invoked.get());
    // true && false
    resetToFalse(invocationState);
    assertFalse(alwaysTrue.and(alwaysFalse).test(1L));
    assertTrue(alwaysTrueInvoked.get() && alwaysFalseInvoked.get());
    // false && false
    resetToFalse(invocationState);
    assertFalse(alwaysFalse.and(alwaysFalse2).test(1L));
    assertTrue(alwaysFalseInvoked.get() && !alwaysFalse2Invoked.get());
    // false && true
    resetToFalse(invocationState);
    assertFalse(alwaysFalse.and(alwaysTrue).test(1L));
    assertTrue(alwaysFalseInvoked.get() && !alwaysTrueInvoked.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestCase(junit.framework.TestCase) LongPredicate(java.util.function.LongPredicate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongPredicate(java.util.function.LongPredicate)

Example 4 with LongPredicate

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

the class LongPredicateTest method testOr.

public void testOr() throws Exception {
    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 };
    LongPredicate alwaysTrue = x -> {
        alwaysTrueInvoked.set(true);
        return true;
    };
    LongPredicate alwaysTrue2 = x -> {
        alwaysTrue2Invoked.set(true);
        return true;
    };
    LongPredicate alwaysFalse = x -> {
        alwaysFalseInvoked.set(true);
        return false;
    };
    LongPredicate alwaysFalse2 = x -> {
        alwaysFalse2Invoked.set(true);
        return false;
    };
    // true || true
    resetToFalse(invocationState);
    assertTrue(alwaysTrue.or(alwaysTrue2).test(1L));
    assertTrue(alwaysTrueInvoked.get() && !alwaysTrue2Invoked.get());
    // true || false
    resetToFalse(invocationState);
    assertTrue(alwaysTrue.or(alwaysFalse).test(1L));
    assertTrue(alwaysTrueInvoked.get() && !alwaysFalseInvoked.get());
    // false || false
    resetToFalse(invocationState);
    assertFalse(alwaysFalse.or(alwaysFalse2).test(1L));
    assertTrue(alwaysFalseInvoked.get() && alwaysFalse2Invoked.get());
    // false || true
    resetToFalse(invocationState);
    assertTrue(alwaysFalse.or(alwaysTrue).test(1L));
    assertTrue(alwaysFalseInvoked.get() && alwaysTrueInvoked.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestCase(junit.framework.TestCase) LongPredicate(java.util.function.LongPredicate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongPredicate(java.util.function.LongPredicate)

Example 5 with LongPredicate

use of java.util.function.LongPredicate in project jdk8u_jdk by JetBrains.

the class MatchOpTest method testLongStream.

@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
public void testLongStream(String name, TestData.OfLong data) {
    for (LongPredicate p : LONG_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpFalse), longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpEven), longKinds.get(kind).apply(p));
        }
    }
}
Also used : LongPredicate(java.util.function.LongPredicate) Test(org.testng.annotations.Test)

Aggregations

LongPredicate (java.util.function.LongPredicate)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 TestCase (junit.framework.TestCase)5 Test (org.testng.annotations.Test)1