1 17 18 package org.sablecc.sablecc.util; 19 20 import static org.junit.Assert.assertEquals; 21 import static org.junit.Assert.assertFalse; 22 import static org.junit.Assert.assertTrue; 23 import static org.junit.Assert.fail; 24 25 import org.junit.Before; 26 import org.junit.Test; 27 import org.sablecc.sablecc.exception.InternalException; 28 29 public class WorkSetTest { 30 31 private WorkSet<Integer > workSet; 32 33 @Before 34 public void setUp() 35 throws Exception { 36 37 this.workSet = new WorkSet<Integer >(); 38 } 39 40 @Test 41 public void testHasNext() { 42 43 assertFalse("the WorkSet is empty.", this.workSet.hasNext()); 45 46 this.workSet.add(5); 48 this.workSet.add(10); 49 assertTrue("the WorkSet contains one element.", this.workSet.hasNext()); 50 } 51 52 @Test 53 public void testNext() { 54 55 this.workSet.add(100); 57 this.workSet.add(25); 58 this.workSet.add(50); 59 60 assertEquals("the first element should be 100", 100, this.workSet 61 .next()); 62 assertEquals("the first element should be 25", 25, this.workSet.next()); 63 assertEquals("the first element should be 50", 50, this.workSet.next()); 64 65 assertFalse("the WorkSet is empty.", this.workSet.hasNext()); 66 67 this.workSet.add(100); 69 this.workSet.add(25); 70 this.workSet.add(50); 71 72 assertFalse("the WorkSet should still be empty.", this.workSet 73 .hasNext()); 74 } 75 76 @Test 77 public void testAdd() { 78 79 try { 81 this.workSet.add(null); 82 fail("element may not be null"); 83 } 84 catch (InternalException e) { 85 } 87 88 } 89 } 90 | Popular Tags |