01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.stats;
05:
06: import junit.framework.TestCase;
07:
08: public class LossyStackTest extends TestCase {
09:
10: public void testException() {
11: try {
12: new LossyStack(0);
13: fail();
14: } catch (IllegalArgumentException iae) {
15: // expected
16: }
17:
18: try {
19: new LossyStack(-4);
20: fail();
21: } catch (IllegalArgumentException iae) {
22: // expected
23: }
24:
25: }
26:
27: public void test() {
28: LossyStack stack = new LossyStack(5);
29: assertEquals(0, stack.depth());
30: assertTrue(stack.isEmtpy());
31: assertNull(stack.peek());
32:
33: try {
34: stack.pop();
35: fail();
36: } catch (IllegalStateException ise) {
37: // expected
38: }
39:
40: stack.push(new Integer(1));
41: assertFalse(stack.isEmtpy());
42: assertEquals(1, stack.depth());
43: stack.push(new Integer(2));
44: assertFalse(stack.isEmtpy());
45: assertEquals(2, stack.depth());
46:
47: assertEquals(new Integer(2), stack.pop());
48: assertFalse(stack.isEmtpy());
49: assertEquals(new Integer(1), stack.pop());
50: assertEquals(0, stack.depth());
51: assertTrue(stack.isEmtpy());
52: assertNull(stack.peek());
53:
54: stack.push(new Integer(1));
55: stack.push(new Integer(2));
56: stack.push(new Integer(3));
57: stack.push(new Integer(4));
58: stack.push(new Integer(5));
59: assertEquals(5, stack.depth());
60: stack.push(new Integer(6));
61: assertEquals(5, stack.depth());
62: stack.push(new Integer(7));
63: assertEquals(5, stack.depth());
64:
65: Integer[] data = (Integer[]) stack.toArray(new Integer[stack
66: .depth()]);
67: assertEquals(5, data.length);
68: for (int i = 0; i < data.length; i++) {
69: assertEquals(new Integer(7 - i), data[i]);
70: }
71:
72: }
73:
74: }
|