File: faop_remeps.test

package info (click to toggle)
tcllib 2.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,560 kB
  • sloc: tcl: 306,798; ansic: 14,272; sh: 3,035; xml: 1,766; yacc: 1,157; pascal: 881; makefile: 124; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (158 lines) | stat: -rw-r--r-- 4,637 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# -*- tcl -*-
# fa_operations.test:  tests for the FA operations.
#
# Copyright (c) 2004-2007 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
#
# RCS: @(#) $Id: faop_remeps.test,v 1.5 2007/04/12 03:43:15 andreas_kupries Exp $

# -------------------------------------------------------------------------

test faop-remove-${setimpl}-eps-1.0 {remove-eps, error} {
    catch {grammar::fa::op::remove_eps} res
    set res
} {wrong # args: should be "grammar::fa::op::remove_eps fa"}


test faop-remove-${setimpl}-eps-1.1 {remove-eps, error} {
    catch {grammar::fa::op::remove_eps a b} res
    set res
} {wrong # args: should be "grammar::fa::op::remove_eps fa"}


test faop-remove-${setimpl}-eps-1.2 {remove-eps, error} {
    catch {grammar::fa::op::remove_eps a} res
    set res
} {invalid command name "a"}


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


foreach {n code result} {
    00 x       id
    01 x-      id
    02 xe      {grammar::fa {} {x {0 0 {}}}}
    03 xy      id
    04 xy-     id
    05 xye     {grammar::fa {} {x {0 0 {}} y {0 0 {}}}}
    06 xyee    {grammar::fa {} {x {0 0 {}} y {0 0 {}}}}
    07 xye-    {grammar::fa @  {x {0 0 {@ {x y}}} y {0 0 {@ {x y}}}}}
    08 xy--    id
    09 xy-=    id
    10 xyz/ee  {grammar::fa {} {x {0 0 {}}    y {0 0 {}} z {0 0 {}}}}
    11 xyz/e-  {grammar::fa @  {x {0 0 {@ y}} y {0 0 {}} z {0 0 {}}}}
    12 xyz/--  id
    13 xyz/-=  id
    14 xyz|ee  {grammar::fa {} {x {0 0 {}}    y {0 0 {}} z {0 0 {}}}}
    15 xyz|e-  {grammar::fa @  {x {0 0 {@ z}} y {0 0 {}} z {0 0 {}}}}
    16 xyz|--  id
    17 xyz|-=  id
    18 xyz+eee {grammar::fa {}    {x {0 0 {}} y {0 0 {}} z {0 0 {}}}}
    19 xyz+ee- {grammar::fa @     {x {0 0 {@ {x y z}}} y {0 0 {@ {x y z}}} z {0 0 {@ {x y z}}}}}
    20 xyz+e-- {grammar::fa @     {x {0 0 {@ z}} y {0 0 {@ z}} z {0 0 {@ {x y}}}}}
    21 xyz+e-= {grammar::fa {@ =} {x {0 0 {@ z}} y {0 0 {@ z}} z {0 0 {= {x y}}}}}
    22 xyz+--- id
    23 xyz+--= id
    24 xyz+-=_ id
    25 xyz&eee {grammar::fa {}    {x {0 0 {}} y {0 0 {}} z {0 0 {}}}}
    26 xyz&ee- {grammar::fa @     {x {0 0 {@ z}} y {0 0 {@ z}} z {0 0 {}}}}
    27 xyz&e-- {grammar::fa @     {x {0 0 {@ z}} y {0 0 {@ z}} z {0 0 {}}}}
    28 xyz&e-= {grammar::fa {@ =} {x {0 0 {= z @ z}} y {0 0 {= z}} z {0 0 {}}}}
    29 xyz&--- id
    30 xyz&--= id
    31 xyz&-=_ id
    32 xyz!ee  {grammar::fa {} {x {0 0 {}} y {0 0 {}} z {0 0 {}}}}
    33 xyz!e-  {grammar::fa @  {x {0 0 {@ z}} y {0 0 {@ z}} z {0 0 {}}}}
    34 xyz!--  id
    35 xyz!-=  id
    36 xyz!-e  {grammar::fa @ {x {0 0 {@ {y z}}} y {0 0 {}} z {0 0 {}}}}
} {
    set key ${n}.${code}
    if {$result eq "id"} {
	grammar::fa a
	gen $code
	set result [a serialize]
	a destroy
    }

    test faop-remove-${setimpl}-eps-2.$key {remove-eps} {
	grammar::fa a
	gen $code
	grammar::fa::op::remove_eps a
	set     res [a is epsilon-free]
	lappend res [validate_serial $result a]
	a destroy
	set res
    } {1 ok}

    test faop-remove-${setimpl}-eps-3.$key {second remove eps is null operation} {
	grammar::fa a
	gen $code
	grammar::fa::op::remove_eps a
	set res [a serialize]
	grammar::fa::op::remove_eps a
	set res [validate_serial $res a]
	a destroy
	set res
    } ok

    test faop-remove-${setimpl}-eps-4.$key {remove-eps, as method} {
	grammar::fa a
	gen $code
	a remove_eps
	set     res [a is epsilon-free]
	lappend res [validate_serial $result a]
	a destroy
	set res
    } {1 ok}

    test faop-remove-${setimpl}-eps-5.$key {second remove eps is null operation, as method} {
	grammar::fa a
	gen $code
	a remove_eps
	set res [a serialize]
	a remove_eps
	set res [validate_serial $res a]
	a destroy
	set res
    } ok
}


foreach {n code st fin stnew finnew} {
    00 datom x y x       y
    01 dalt  u z {u v w} {x y z}
    02 dopt  u x {u v x} {u w x} 
    03 drep  u x {u v x} {u w x}
} {
    test faop-remove-${setimpl}-eps-6.$n.$code {remove epsilon, start/final propagation} {
	grammar::fa a
	gen $code
	a start add $st
	a final add $fin
	grammar::fa::op::remove_eps a

	set     res {}
	lappend res [string equal $stnew  [lsort [a startstates]]]
	lappend res [string equal $finnew [lsort [a finalstates]]]
	a destroy
	set res
    } {1 1}

    test faop-remove-${setimpl}-eps-7.$n.$code {remove epsilon, start/final propagation, as method} {
	grammar::fa a
	gen $code
	a start add $st
	a final add $fin
	a remove_eps

	set     res {}
	lappend res [string equal $stnew  [lsort [a startstates]]]
	lappend res [string equal $finnew [lsort [a finalstates]]]
	a destroy
	set res
    } {1 1}
}

# -------------------------------------------------------------------------
::tcltest::cleanupTests