Example #1
0
 @Test
 public void shouldNotMemoizeAlreadyMemoizedFunction() {
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> f =
       (i1, i2, i3, i4, i5) -> null;
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> memo = f.memoized();
   assertThat(memo.memoized() == memo).isTrue();
 }
Example #2
0
 @Test
 public void shouldMemoizeValueGivenNullArguments() {
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> f =
       (i1, i2, i3, i4, i5) -> null;
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> memo = f.memoized();
   assertThat(memo.apply(null, null, null, null, null)).isNull();
 }
Example #3
0
 @Test
 public void shouldTuple() {
   final Function5<Object, Object, Object, Object, Object, Object> f =
       (o1, o2, o3, o4, o5) -> null;
   final Function1<Tuple5<Object, Object, Object, Object, Object>, Object> tupled = f.tupled();
   assertThat(tupled).isNotNull();
 }
Example #4
0
 @Test
 public void shouldComposeWithAndThen() {
   final Function5<Object, Object, Object, Object, Object, Object> f =
       (o1, o2, o3, o4, o5) -> null;
   final Function1<Object, Object> after = o -> null;
   final Function5<Object, Object, Object, Object, Object, Object> composed = f.andThen(after);
   assertThat(composed).isNotNull();
 }
Example #5
0
 @Test
 public void shouldRecognizeMemoizedFunctions() {
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> f =
       (i1, i2, i3, i4, i5) -> null;
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> memo = f.memoized();
   assertThat(f.isMemoized()).isFalse();
   assertThat(memo.isMemoized()).isTrue();
 }
Example #6
0
 @Test
 public void shouldRecognizeApplicabilityToTypes() {
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> f =
       (i1, i2, i3, i4, i5) -> null;
   assertThat(
           f.isApplicableToTypes(
               Integer.class, Integer.class, Integer.class, Integer.class, Integer.class))
       .isTrue();
 }
Example #7
0
 @Test
 public void shouldPartiallyApply() {
   final Function5<Object, Object, Object, Object, Object, Object> f =
       (o1, o2, o3, o4, o5) -> null;
   assertThat(f.apply(null)).isNotNull();
   assertThat(f.apply(null, null)).isNotNull();
   assertThat(f.apply(null, null, null)).isNotNull();
   assertThat(f.apply(null, null, null, null)).isNotNull();
 }
Example #8
0
 @Test
 public void shouldCurry() {
   final Function5<Object, Object, Object, Object, Object, Object> f =
       (o1, o2, o3, o4, o5) -> null;
   final Function1<
           Object,
           Function1<Object, Function1<Object, Function1<Object, Function1<Object, Object>>>>>
       curried = f.curried();
   assertThat(curried).isNotNull();
 }
Example #9
0
 @Test
 public void testTypesEquals() {
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> f1 =
       (i1, i2, i3, i4, i5) -> null;
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> f2 =
       (i1, i2, i3, i4, i5) -> null;
   final Function5<Integer, Integer, Integer, Integer, Integer, String> f3 =
       (i1, i2, i3, i4, i5) -> null;
   final Function5<String, Integer, Integer, Integer, Integer, Integer> f4 =
       (i1, i2, i3, i4, i5) -> null;
   final Function5.Type<Integer, Integer, Integer, Integer, Integer, Integer> t1 = f1.getType();
   assertThat(t1).isEqualTo(t1);
   assertThat(t1).isNotEqualTo(11);
   assertThat(f1.getType()).isEqualTo(f2.getType());
   assertThat(f1.getType()).isNotEqualTo(f3.getType());
   assertThat(f1.getType()).isNotEqualTo(f4.getType());
 }
Example #10
0
 @Test
 public void shouldLiftPartialFunction() {
   assertThat(
           Function5.lift(
               (o1, o2, o3, o4, o5) -> {
                 while (true) ;
               }))
       .isNotNull();
 }
Example #11
0
 @Test
 public void shouldLift() {
   class Type {
     Object methodReference(Object o1, Object o2, Object o3, Object o4, Object o5) {
       return null;
     }
   }
   final Type type = new Type();
   assertThat(Function5.of(type::methodReference)).isNotNull();
 }
Example #12
0
 @Test
 public void shouldGetType() {
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> f =
       (i1, i2, i3, i4, i5) -> null;
   final Function5.Type<Integer, Integer, Integer, Integer, Integer, Integer> type = f.getType();
   assertThat(type.parameterType1()).isEqualTo(Integer.class);
   assertThat(type.parameterType2()).isEqualTo(Integer.class);
   assertThat(type.parameterType3()).isEqualTo(Integer.class);
   assertThat(type.parameterType4()).isEqualTo(Integer.class);
   assertThat(type.parameterType5()).isEqualTo(Integer.class);
   assertThat(type.toString())
       .isEqualTo(
           "(java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer) -> java.lang.Integer");
 }
Example #13
0
 @Test
 public void shouldMemoize() {
   final AtomicInteger integer = new AtomicInteger();
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> f =
       (i1, i2, i3, i4, i5) -> i1 + i2 + i3 + i4 + i5 + integer.getAndIncrement();
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> memo = f.memoized();
   // should apply f on first apply()
   final int expected = memo.apply(1, 2, 3, 4, 5);
   // should return memoized value of second apply()
   assertThat(memo.apply(1, 2, 3, 4, 5)).isEqualTo(expected);
   // should calculate new values when called subsequently with different parameters
   assertThat(memo.apply(2, 3, 4, 5, 6)).isEqualTo(2 + 3 + 4 + 5 + 6 + 1);
   // should return memoized value of second apply() (for new value)
   assertThat(memo.apply(2, 3, 4, 5, 6)).isEqualTo(2 + 3 + 4 + 5 + 6 + 1);
 }
Example #14
0
  @Test
  public void shouldLiftTryPartialFunction() {
    AtomicInteger integer = new AtomicInteger();
    Function5<Integer, Integer, Integer, Integer, Integer, Integer> divByZero =
        (i1, i2, i3, i4, i5) -> 10 / integer.get();
    Function5<Integer, Integer, Integer, Integer, Integer, Try<Integer>> divByZeroTry =
        Function5.liftTry(divByZero);

    Try<Integer> res = divByZeroTry.apply(0, 0, 0, 0, 0);
    assertThat(res.isFailure()).isTrue();
    assertThat(res.getCause()).isNotNull();
    assertThat(res.getCause().getMessage()).isEqualToIgnoringCase("/ by zero");

    integer.incrementAndGet();
    res = divByZeroTry.apply(1, 2, 3, 4, 5);
    assertThat(res.isSuccess()).isTrue();
    assertThat(res.get()).isEqualTo(10);
  }
Example #15
0
 @Test
 public void shouldConstant() {
   final Function5<Object, Object, Object, Object, Object, Object> f = Function5.constant(6);
   assertThat(f.apply(1, 2, 3, 4, 5)).isEqualTo(6);
 }
Example #16
0
 @Test
 public void shouldReverse() {
   final Function5<Object, Object, Object, Object, Object, Object> f =
       (o1, o2, o3, o4, o5) -> null;
   assertThat(f.reversed()).isNotNull();
 }
Example #17
0
 @Test
 public void shouldGetArity() {
   final Function5<Object, Object, Object, Object, Object, Object> f =
       (o1, o2, o3, o4, o5) -> null;
   assertThat(f.arity()).isEqualTo(5);
 }
Example #18
0
 @Test
 public void shouldCalculatedRecursively() {
   assertThat(recurrent1.apply(11, 11, 11, 11, 11)).isEqualTo(11);
   assertThat(recurrent1.apply(22, 22, 22, 22, 22)).isEqualTo(22);
 }
Example #19
0
 @Test
 public void shouldRecognizeApplicabilityOfNonNull() {
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> f =
       (i1, i2, i3, i4, i5) -> null;
   assertThat(f.isApplicableTo(1, 2, 3, 4, 5)).isTrue();
 }
Example #20
0
 @Test
 public void shouldRecognizeApplicabilityOfNull() {
   final Function5<Object, Object, Object, Object, Object, Object> f =
       (o1, o2, o3, o4, o5) -> null;
   assertThat(f.isApplicableTo(null, null, null, null, null)).isTrue();
 }
Example #21
0
 @Test
 public void shouldGetReturnType() {
   final Function5<Integer, Integer, Integer, Integer, Integer, Integer> f =
       (i1, i2, i3, i4, i5) -> null;
   assertThat(f.getType().returnType()).isEqualTo(Integer.class);
 }