All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.ihmc.commons.lists.SupplierBuilderTest Maven / Gradle / Ivy

There is a newer version: 0.35.0
Show newest version
package us.ihmc.commons.lists;

import org.apache.commons.lang3.mutable.MutableInt;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

import java.util.function.IntFunction;
import java.util.function.Supplier;

public class SupplierBuilderTest
{
   @Test
   public void testZeroIndexedSupplierBuilder()
   {
      IntFunction indexFunction = (index) -> new MutableInt(2 * index - 1);
      Supplier intSupplier = SupplierBuilder.indexedSupplier(indexFunction);

      for (int i = 0; i < 10; i++)
      {
         MutableInt mutableInt = intSupplier.get();
         assertEquals((long) mutableInt.getValue(), (long) indexFunction.apply(i).getValue());
      }
   }

   @Test
   public void testNonZeroIndexedSupplierBuilder()
   {
      int initialIndex = 10;
      IntFunction indexFunction = (index) -> new MutableInt(-3 * index + 1);
      Supplier intSupplier = SupplierBuilder.indexedSupplier(indexFunction, initialIndex);

      for (int i = 0; i < 10; i++)
      {
         MutableInt mutableInt = intSupplier.get();
         assertEquals((long) mutableInt.getValue(), (long) indexFunction.apply(i + initialIndex).getValue());
      }
   }

   @Test
   public void testMutableIntSupplierFromConstructor()
   {
      Supplier supplier = SupplierBuilder.createFromEmptyConstructor(MutableInt.class);
      for (int i = 0; i < 10; i++)
      {
         assertEquals((long) supplier.get().getValue(), 0);
      }
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy