BoundedFIFOTestCasepublic class BoundedFIFOTestCase extends TestCase Unit test the {@link BoundedFIFO}. |
Fields Summary |
---|
static Logger | cat | static int | MAX | static LoggingEvent[] | e |
Constructors Summary |
---|
public BoundedFIFOTestCase(String name)
for (int i = 0; i < MAX; i++) {
e[i] = new LoggingEvent("", cat, Level.DEBUG, "e"+i, null);
}
super(name);
|
Methods Summary |
---|
int | min(int a, int b)
return a < b ? a : b;
| public void | setUp()
| public static junit.framework.Test | suite()
TestSuite suite = new TestSuite();
suite.addTest(new BoundedFIFOTestCase("test1"));
suite.addTest(new BoundedFIFOTestCase("test2"));
suite.addTest(new BoundedFIFOTestCase("testResize1"));
suite.addTest(new BoundedFIFOTestCase("testResize2"));
suite.addTest(new BoundedFIFOTestCase("testResize3"));
return suite;
| public void | test1()Pattern: +++++..-----..
for(int size = 1; size <= 128; size *=2) {
BoundedFIFO bf = new BoundedFIFO(size);
assertEquals(bf.getMaxSize(), size);
assertNull(bf.get());
int i;
int j;
int k;
for(i = 1; i < 2*size; i++) {
for(j = 0; j < i; j++) {
//System.out.println("Putting "+e[j]);
bf.put(e[j]); assertEquals(bf.length(), j < size ? j+1 : size);
}
int max = size < j ? size : j;
j--;
for(k = 0; k <= j; k++) {
//System.out.println("max="+max+", j="+j+", k="+k);
assertEquals(bf.length(), max - k > 0 ? max - k : 0);
Object r = bf.get();
//System.out.println("Got "+r);
if(k >= size)
assertNull(r);
else
assertEquals(r, e[k]);
}
}
//System.out.println("Passed size="+size);
}
| public void | test2()Pattern: ++++--++--++
int size = 3;
BoundedFIFO bf = new BoundedFIFO(size);
bf.put(e[0]);
assertEquals(bf.get(), e[0]);
assertNull(bf.get());
bf.put(e[1]); assertEquals(bf.length(), 1);
bf.put(e[2]); assertEquals(bf.length(), 2);
bf.put(e[3]); assertEquals(bf.length(), 3);
assertEquals(bf.get(), e[1]); assertEquals(bf.length(), 2);
assertEquals(bf.get(), e[2]); assertEquals(bf.length(), 1);
assertEquals(bf.get(), e[3]); assertEquals(bf.length(), 0);
assertNull(bf.get()); assertEquals(bf.length(), 0);
| public void | testResize1()Pattern ++++++++++++++++++++ (insert only);
int size = 10;
for(int n = 1; n < size*2; n++) {
for(int i = 0; i < size*2; i++) {
BoundedFIFO bf = new BoundedFIFO(size);
for(int f = 0; f < i; f++) {
bf.put(e[f]);
}
bf.resize(n);
int expectedSize = min(n, min(i, size));
assertEquals(bf.length(), expectedSize);
for(int c = 0; c < expectedSize; c++) {
assertEquals(bf.get(), e[c]);
}
}
}
| public void | testResize2()Pattern ++...+ --...-
int size = 10;
for(int n = 1; n < size*2; n++) {
for(int i = 0; i < size*2; i++) {
for(int d = 0; d < min(i,size); d++) {
BoundedFIFO bf = new BoundedFIFO(size);
for(int p = 0; p < i; p++) {
bf.put(e[p]);
}
for(int g = 0; g < d; g++) {
bf.get();
}
// x = the number of elems in
int x = bf.length();
bf.resize(n);
int expectedSize = min(n, x);
assertEquals(bf.length(), expectedSize);
for(int c = 0; c < expectedSize; c++) {
assertEquals(bf.get(), e[c+d]);
}
assertNull(bf.get());
}
}
}
| public void | testResize3()Pattern: i inserts, d deletes, r inserts
int size = 10;
for(int n = 1; n < size*2; n++) {
for(int i = 0; i < size; i++) {
for(int d = 0; d < i; d++) {
for(int r = 0; r < d; r++) {
BoundedFIFO bf = new BoundedFIFO(size);
for(int p0 = 0; p0 < i; p0++)
bf.put(e[p0]);
for(int g = 0; g < d; g++)
bf.get();
for(int p1 = 0; p1 < r; p1++)
bf.put(e[i+p1]);
int x = bf.length();
bf.resize(n);
int expectedSize = min(n, x);
assertEquals(bf.length(), expectedSize);
for(int c = 0; c < expectedSize; c++) {
assertEquals(bf.get(), e[c+d]);
}
//assertNull(bf.get());
}
}
}
}
|
|