1 17 18 package org.sablecc.sablecc.automaton; 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.alphabet.Realms; 28 import org.sablecc.sablecc.exception.InternalException; 29 30 public class GroupPairTest { 31 32 GroupPair<Integer > groupPair; 33 34 Group<Integer > group1; 35 36 Group<Integer > group2; 37 38 Partition<Integer > partition1; 39 40 Partition<Integer > partition2; 41 42 Dfa<Integer > dfa1; 43 44 Dfa<Integer > dfa2; 45 46 Nfa<Integer > nfa1; 47 48 Nfa<Integer > nfa2; 49 50 @Before 51 public void setUp() 52 throws Exception { 53 54 this.nfa1 = new Nfa<Integer >(Realms.getInteger().createInterval(50)) 56 .zeroOrMore(); 57 58 this.dfa1 = new Dfa<Integer >(this.nfa1); 59 60 this.partition1 = new Partition<Integer >(this.dfa1); 61 62 this.group1 = new Group<Integer >(this.partition1); 63 64 this.nfa2 = new Nfa<Integer >(Realms.getInteger().createInterval(25)) 66 .zeroOrMore(); 67 68 this.dfa2 = new Dfa<Integer >(this.nfa2); 69 70 this.partition2 = new Partition<Integer >(this.dfa2); 71 72 this.group2 = new Group<Integer >(this.partition2); 73 74 this.groupPair = new GroupPair<Integer >(this.group1, this.group2); 75 } 76 77 @SuppressWarnings ("unused") 78 @Test 79 public void testGroupPair() { 80 81 Group<Integer > nullGroup = null; 83 84 try { 85 GroupPair<Integer > groupPair = new GroupPair<Integer >(nullGroup, 86 this.group2); 87 fail("group1 may not be null"); 88 } 89 catch (InternalException e) { 90 } 92 93 try { 94 GroupPair<Integer > groupPair = new GroupPair<Integer >(this.group1, 95 nullGroup); 96 fail("group2 may not be null"); 97 } 98 catch (InternalException e) { 99 } 101 102 assertEquals("group1 has not been entered correctly", this.group1, 103 this.groupPair.getGroup1()); 104 105 assertEquals("group2 has not been entered correctly", this.group2, 106 this.groupPair.getGroup2()); 107 } 108 109 @Test 110 public void testEqualsObject() { 111 112 Object nullObject = null; 114 115 assertFalse("groupPair should not be equal to null", this.groupPair 116 .equals(nullObject)); 117 118 assertFalse("groupPair should not be equal to an Integer", 120 this.groupPair.equals(10)); 121 122 assertTrue("a groupPair should be equal to himself", this.groupPair 124 .equals(this.groupPair)); 125 126 GroupPair<Integer > sameGroupPair = new GroupPair<Integer >(this.group1, 127 this.group2); 128 129 assertTrue("groupPair should be equal to this instance", this.groupPair 130 .equals(sameGroupPair)); 131 } 132 133 } 134 | Popular Tags |