1 18 19 package org.sablecc.sablecc.automaton; 20 21 import static org.junit.Assert.assertEquals; 22 import static org.junit.Assert.assertFalse; 23 import static org.junit.Assert.fail; 24 25 import org.junit.Before; 26 import org.junit.Test; 27 import org.sablecc.sablecc.alphabet.Interval; 28 import org.sablecc.sablecc.alphabet.Realms; 29 import org.sablecc.sablecc.alphabet.Symbol; 30 import org.sablecc.sablecc.exception.InternalException; 31 32 public class GroupTest { 33 34 private Group<Integer > group; 35 36 private Interval<Integer > interval; 37 38 private Nfa<Integer > nfa; 39 40 private Dfa<Integer > dfa; 41 42 private Partition<Integer > partition; 43 44 @Before 45 public void setUp() 46 throws Exception { 47 48 this.interval = Realms.getInteger().createInterval(50); 49 50 this.nfa = new Nfa<Integer >(this.interval).zeroOrMore(); 51 52 this.dfa = new Dfa<Integer >(this.nfa); 53 54 this.partition = new Partition<Integer >(this.dfa); 55 56 this.group = new Group<Integer >(this.partition); 57 } 58 59 @Test 60 public void testGroup() { 61 62 Partition<Integer > nullPartition = null; 64 try { 65 this.group = new Group<Integer >(nullPartition); 66 fail("partition may not be null"); 67 } 68 catch (InternalException e) { 69 } 71 72 assertEquals("the group has the wrong partition", this.partition, 73 this.group.getPartition()); 74 } 75 76 @Test 77 public void testAddElement() { 78 79 Element<Integer > nullElement = null; 81 try { 82 this.group.addElement(nullElement); 83 fail("element may not be null"); 84 } 85 catch (InternalException e) { 86 } 88 } 89 90 @Test 91 public void testRemoveElement() { 92 93 Element<Integer > nullElement = null; 95 try { 96 this.group.removeElement(nullElement); 97 fail("element may not be null"); 98 } 99 catch (InternalException e) { 100 } 102 } 103 104 @Test 105 public void testAddTransition() { 106 107 Symbol<Integer > nullSymbol = null; 109 try { 110 this.group.addTransition(nullSymbol, this.group); 111 fail("symbol may not be null"); 112 } 113 catch (InternalException e) { 114 } 116 Symbol<Integer > symbol = new Symbol<Integer >(this.interval); 118 try { 119 this.group.addTransition(nullSymbol, this.group); 120 fail("group may not be null"); 121 } 122 catch (InternalException e) { 123 } 125 126 this.group.addTransition(symbol, this.group); 127 assertFalse("The set of transition of the group should not be empty", 128 this.group.getTransitions().isEmpty()); 129 } 130 } 131 | Popular Tags |