Skip to content

Commit

Permalink
Added unit test for arrayList shuffler.
Browse files Browse the repository at this point in the history
  • Loading branch information
nomemory authored and Ciobanu, Andrei-Nicolin (UK - EDC) committed May 8, 2017
1 parent 141a032 commit c77c74a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public MockUnit<float[]> arrayFloat(float[] source) {
return () -> supplier;
}

//TODO add tests
public <T> MockUnit<ArrayList<T>> arrayList(ArrayList<T> source) {
notNull(source, "source");
Supplier<ArrayList<T>> supplier = () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.andreinc.mockneat.unit.objects.model.SimpleBean;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -281,4 +282,58 @@ public void testFloatArray() throws Exception {
}
);
}

@Test(expected = NullPointerException.class)
public void testArrayListNullSource() throws Exception {
M.shufflers().arrayList(null).val();
}


@Test
public void testArrayListEmptySource() throws Exception {
ArrayList<Double> al = new ArrayList<>();
ArrayList<Double> newAl = M.shufflers().arrayList(al).val();

assertNotNull(newAl);
assertTrue(al!=newAl);
assertTrue(newAl.size()==0);
}

@Test
public void testArrayListOneElement() throws Exception {
ArrayList<Double> al = new ArrayList<>();
al.add(1.0);

ArrayList<Double> newAl = M.shufflers().arrayList(al).val();

assertNotNull(newAl);
assertTrue(newAl!=al);
assertTrue(newAl.size() == 1);
assertTrue(newAl.get(0).equals(1.0));
}

@Test
public void testArrayListArray() throws Exception {
loop(
SHUFFLED_CYCLES,
MOCKS,
m -> {
ArrayList<Double> al = (ArrayList<Double>) m.doubles()
.list(ArrayList.class, 50)
.val();

Set<Double> possibleValues = new HashSet<>(al);

ArrayList<Double> newAl = m.shufflers()
.arrayList(al)
.val();

assertTrue(newAl!=al);
assertTrue(al.size() == newAl.size());

range(0, newAl.size())
.forEach(i -> assertTrue(possibleValues.contains(newAl.get(i))));
}
);
}
}

0 comments on commit c77c74a

Please sign in to comment.