Skip to content

Commit

Permalink
updated unit tests for MemoryListGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
firaja committed Apr 8, 2018
1 parent f4fb142 commit 1720baf
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/cc/firaja/generators/MemoryListGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ protected void saveState()
memory.add(new State(last()));
}

/**
*
* @throws NullPointerException if
*/

protected T getResult(final int c)
{
Objects.requireNonNull(c, "c cannot be null");
Expand Down
87 changes: 87 additions & 0 deletions testsrc/cc/firaja/generators/MemoryListUnitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package cc.firaja.generators;

import java.util.NoSuchElementException;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* @author David Bertoldi
*/
public class MemoryListUnitTest
{

private static final int MAX_ITERATIONS = 10;
private static final String VAR = "var_string";

MemoryListGenerator<Boolean> classUnderTest = new MemoryListGenerator<Boolean>()
{
@Override
public Boolean generate()
{
if (c() == 0)
{
return false;
}
return !getResult(c() - 1);
}
};


@Test
public void testConstructorNoArgs()
{
// GIVEN

// WHEN
for (int i = 0; i < MAX_ITERATIONS; i++)
{
// THEN
if (i % 2 == 0)
{
assertFalse(classUnderTest.next());
}
else
{
assertTrue(classUnderTest.next());
}
}
assertTrue(classUnderTest.hasNext());
}

@Test
public void testConstructorWithLimit()
{
// GIVEN
classUnderTest.resize(MAX_ITERATIONS);

// WHEN
for (int i = 0; i < MAX_ITERATIONS; i++)
{
// THEN
if (i % 2 == 0)
{
assertFalse(classUnderTest.next());
}
else
{
assertTrue(classUnderTest.next());
}
}
assertFalse(classUnderTest.hasNext());
}


@Test(expected = NoSuchElementException.class)
public void testGetResultExc()
{
// GIVEN
classUnderTest.resize(MAX_ITERATIONS);

// WHEN
classUnderTest.getResult(50);

}

}

0 comments on commit 1720baf

Please sign in to comment.