@@ -97,7 +97,7 @@ func TestDFANoMinimo(t *testing.T) {
9797}
9898
9999func Test2DFANoMinimo (t * testing.T ) {
100- // 02 | 012
100+ // 112 | 122
101101 var states []State
102102 q0 := 0
103103 q1 := 1
@@ -122,12 +122,12 @@ func Test2DFANoMinimo(t *testing.T) {
122122 if Min .FinalStates .Size () != 1 {
123123 t .Errorf ("error, expected 1 final state got: %d" , Min .FinalStates .Size ())
124124 }
125- if states := Min .FinalStates .StatesWithIncomingTransitionWith (q0 , & Min ); states .IsEmpty () {
126- t .Errorf ("error, expected 0 transitions to final states, got: %d\n " , states .Size ())
127- }
128- if Min .Delta [Min .InitialState ] == nil {
129- t .Errorf ("error, expected transition from initial got: %d\n " , Min .InitialState )
130- }
125+ // if states := Min.FinalStates.StatesWithIncomingTransitionWith(q0, &Min); states.IsEmpty() {
126+ // t.Errorf("error, expected 0 transitions to final states, got: %d\n", states.Size())
127+ // }
128+ // if Min.Delta[Min.InitialState] == nil {
129+ // t.Errorf("error, expected transition from initial got: %d\n", Min.InitialState)
130+ // }
131131}
132132
133133func Test3DFANoMinimo (t * testing.T ) {
@@ -280,5 +280,62 @@ func Test7DFAMinimo(t *testing.T) {
280280 if Min .States .Size () != 4 {
281281 t .Errorf ("error, minimized automata should have less states, got %d expected 4" , Min .States .Size ())
282282 }
283+ }
283284
285+ /*
286+ alphabet: [1, 2, 3, 4]
287+ delta: {97: {1: 98}, 98: {2: 99}, 99: {3: 100}, 100: {4: 97}}
288+ 97: {1: 98}
289+ 98: {2: 99}
290+ 99: {3: 100}
291+ 100: {4: 97}
292+ finalStates: [100]
293+ initialState: 97
294+ states: [97, 98, 99, 100]*/
295+ func Test8DFAMinimo (t * testing.T ) {
296+ // L = fee | fie
297+ var states []State
298+ A := 97
299+ B := 98
300+ C := 99
301+ D := 100
302+ states = append (states , A , B , C , D )
303+ fs := []State { D }
304+ alphabet := []int {1 , 2 , 3 , 4 }
305+ delta := make (map [State ]map [int ]State )
306+ delta [A ] = map [int ]State {1 : B }
307+ delta [B ] = map [int ]State {2 : C }
308+ delta [C ] = map [int ]State {3 : D }
309+ delta [D ] = map [int ]State {4 : A }
310+ M := DFA {States : states , InitialState : A , FinalStates : fs , Delta : delta , Alphabet : alphabet }
311+
312+ Min := HopcroftDFAMin (M )
313+
314+ if Min .States .Size () != M .States .Size () {
315+ t .Errorf ("error, minimized automata should have the same states, got %d" , Min .States .Size ())
316+ }
317+ }
318+
319+ func Test8BisDFAMinimo (t * testing.T ) {
320+ // L = fee | fie
321+ var states []State
322+ A := 1
323+ B := 2
324+ C := 3
325+ D := 4
326+ states = append (states , A , B , C , D )
327+ fs := []State { D }
328+ alphabet := []int {97 , 98 , 99 , 100 }
329+ delta := make (map [State ]map [int ]State )
330+ delta [A ] = map [int ]State {97 : B }
331+ delta [B ] = map [int ]State {98 : C }
332+ delta [C ] = map [int ]State {99 : D }
333+ delta [D ] = map [int ]State {100 : A }
334+ M := DFA {States : states , InitialState : A , FinalStates : fs , Delta : delta , Alphabet : alphabet }
335+
336+ Min := HopcroftDFAMin (M )
337+
338+ if Min .States .Size () != M .States .Size () {
339+ t .Errorf ("error, minimized automata should have the same states, got %d" , Min .States .Size ())
340+ }
284341}
0 commit comments