1 17 18 package org.sablecc.sablecc.automaton; 19 20 import static org.junit.Assert.fail; 21 22 import org.junit.Before; 23 import org.junit.Test; 24 import org.sablecc.sablecc.alphabet.Realms; 25 import org.sablecc.sablecc.exception.InternalException; 26 27 public class PartitionTest { 28 29 Partition<Integer > partition; 30 31 Dfa<Integer > dfa; 32 33 Nfa<Integer > nfa; 34 35 @Before 36 public void setUp() 37 throws Exception { 38 39 this.nfa = new Nfa<Integer >(Realms.getInteger().createInterval(50)) 40 .zeroOrMore(); 41 42 this.dfa = new Dfa<Integer >(this.nfa); 43 44 this.partition = new Partition<Integer >(this.dfa); 45 46 } 47 48 @Test 49 public void testPartition() { 50 51 Dfa<Integer > nullDfa = null; 53 try { 54 this.partition = new Partition<Integer >(nullDfa); 55 fail("dfa may not be null"); 56 } 57 catch (InternalException e) { 58 } 60 } 61 62 @Test 63 public void testAddGroup() { 64 65 Group<Integer > nullGroup = null; 67 try { 68 this.partition.addGroup(nullGroup); 69 fail("group may not be null"); 70 } 71 catch (InternalException e) { 72 } 74 75 Partition<Integer > newPartition = new Partition<Integer >(this.dfa); 77 Group<Integer > invalidGroup = new Group<Integer >(newPartition); 78 try { 79 this.partition.addGroup(invalidGroup); 80 fail("invalid group"); 81 } 82 catch (InternalException e) { 83 } 85 86 Group<Integer > group = new Group<Integer >(this.partition); 88 try { 89 this.partition.addGroup(group); 90 fail("group is already in this partiton"); 91 } 92 catch (InternalException e) { 93 } 95 } 96 97 @Test 98 public void testGetElement() { 99 100 DfaState<Integer > nullState = null; 102 try { 103 this.partition.getElement(nullState); 104 fail("state may not be null"); 105 } 106 catch (InternalException e) { 107 } 109 110 Dfa<Integer > newDfa = new Dfa<Integer >(this.nfa); 112 DfaState<Integer > dfaState = newDfa.getStartState(); 113 try { 114 this.partition.getElement(dfaState); 115 fail("invalid state"); 116 } 117 catch (InternalException e) { 118 } 120 dfaState = this.dfa.getStartState(); 121 this.partition.getElement(dfaState); 122 } 123 124 @Test 125 public void testAddElement() { 126 127 Element<Integer > element; 128 Element<Integer > nullElement = null; 130 try { 131 this.partition.addElement(nullElement); 132 fail("element may not be null"); 133 } 134 catch (InternalException e) { 135 } 137 138 Partition<Integer > newPartition = new Partition<Integer >(this.dfa); 140 element = newPartition.getElement(this.dfa.getStartState()); 141 try { 142 this.partition.addElement(element); 143 fail("invalid element"); 144 } 145 catch (InternalException e) { 146 } 148 } 149 150 } 151 | Popular Tags |