-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated unit tests for MemoryListGenerator
- Loading branch information
Showing
2 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} |