Search in sources :

Example 1 with IntPredicate

use of java.util.function.IntPredicate in project gatk by broadinstitute.

the class MathUtilsUnitTest method testAllMatchInt.

@Test
public void testAllMatchInt() {
    for (final double[] doubleArray : testArrays) {
        final int[] array = Arrays.stream(doubleArray).mapToInt(x -> (int) Math.round(x)).toArray();
        final IntPredicate pred = x -> x > -1;
        Assert.assertEquals(MathUtils.allMatch(array, pred), Arrays.stream(array).allMatch(pred));
    }
}
Also used : Math.exp(java.lang.Math.exp) java.util(java.util) DataProvider(org.testng.annotations.DataProvider) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Math.log10(java.lang.Math.log10) Test(org.testng.annotations.Test) IntPredicate(java.util.function.IntPredicate) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) Logger(org.apache.logging.log4j.Logger) MathUtils(org.broadinstitute.hellbender.utils.MathUtils) NormalDistribution(org.apache.commons.math3.distribution.NormalDistribution) Assert(org.testng.Assert) DoublePredicate(java.util.function.DoublePredicate) LogManager(org.apache.logging.log4j.LogManager) IntPredicate(java.util.function.IntPredicate) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 2 with IntPredicate

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

the class IntPredicateTest method testAnd.

public void testAnd() throws Exception {
    int arg = 5;
    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 };
    IntPredicate alwaysTrue = x -> {
        alwaysTrueInvoked.set(true);
        assertEquals(x, arg);
        return true;
    };
    IntPredicate alwaysTrue2 = x -> {
        alwaysTrue2Invoked.set(true);
        assertEquals(x, arg);
        return true;
    };
    IntPredicate alwaysFalse = x -> {
        alwaysFalseInvoked.set(true);
        assertEquals(x, arg);
        return false;
    };
    IntPredicate 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) IntPredicate(java.util.function.IntPredicate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IntPredicate(java.util.function.IntPredicate)

Example 3 with IntPredicate

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

the class IntPredicateTest method testAnd_null.

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

Example 4 with IntPredicate

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

the class IntPredicateTest method testNegate.

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

Example 5 with IntPredicate

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

the class IntPredicateTest method testOr_null.

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

Aggregations

IntPredicate (java.util.function.IntPredicate)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 TestCase (junit.framework.TestCase)5 Test (org.testng.annotations.Test)3 List (java.util.List)2 IntStream (java.util.stream.IntStream)2 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)2 RollbackException (com.torodb.core.transaction.RollbackException)1 IOException (java.io.IOException)1 Math.exp (java.lang.Math.exp)1 Math.log10 (java.lang.Math.log10)1 String.format (java.lang.String.format)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1