package counters;
import org.junit.*;
import static org.junit.Assert.*;
import counters.SimpleCounter;
import counters.LimitReachedException;
/**
*
* Tests for the creation of simple counters and reporting of
* their limits and initial values by SimpleCounter
.
*
*
*
* Requires JUnit 4.x
.
*
*
* @author Wayne Eberly
*
*/
public class CreationTest {
/*
* First test attempt to create counters with negative limits
*
*/
@Test (expected = IllegalArgumentException.class)
public void TestLargestNegative () {
SimpleCounter testCounter;
testCounter = new SimpleCounter(-2147483648);
}
@Test (expected = IllegalArgumentException.class)
public void TestLargeNegative () {
SimpleCounter testCounter;
testCounter = new SimpleCounter(-1000);
}
@Test (expected = IllegalArgumentException.class)
public void TestNegativeOne () {
SimpleCounter testCounter;
testCounter = new SimpleCounter(-1);
}
@Test (expected = IllegalArgumentException.class)
public void TestZero () {
SimpleCounter testCounter;
testCounter = new SimpleCounter(0);
}
/*
*
* The remaining tests check that counters are created
* with the required limits when inputs are valid
*
*/
private void setAndCheck ( int i ) {
SimpleCounter testCounter;
testCounter = new SimpleCounter(i);
assertEquals(testCounter.getLimit(), i);
assertEquals(testCounter.getValue(), 0);
}
@Test
public void TestOne () {
setAndCheck(1);
}
@Test
public void TestTwo () {
setAndCheck(2);
}
@Test
public void TestLargePositive () {
setAndCheck(10000);
}
@Test
public void TestLargestPositive () {
setAndCheck(2147483647);
}
}