File: faop_trim.test

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (209 lines) | stat: -rw-r--r-- 4,722 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# -*- tcl -*-
# fa_operations.test:  tests for the FA operations.
#
# Copyright (c) 2004-2007 by Andreas Kupries <andreas_kupries@users.sourceforge.net>
#
# RCS: @(#) $Id: faop_trim.test,v 1.7 2007/04/12 03:43:15 andreas_kupries Exp $

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

if {![::tcltest::testConstraint runtotal]} {
    ::tcltest::cleanupTests
    return
}

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

test faop-trim-${setimpl}-1.0 {trim, error} {
    catch {grammar::fa::op::trim} res
    set res
} {wrong # args: should be "grammar::fa::op::trim fa ?what?"}


test faop-trim-${setimpl}-1.1 {trim, error} {
    catch {grammar::fa::op::trim a foo} res
    set res
} {Expected !reachable, !useful, !reachable&!useful, !(reachable|useful), !reachable|!useful, or !(reachable&useful), got "foo"}


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


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if 0 {
    00 x       
    01 x-      
    02 xy      
    03 xy-     
    04 xy-=    
    05 xyz/-=  
    06 xyz|-=  
    07 xyz+-=_ 
    08 xyz&-=_ 
    09 xyz!-=  
    10 xyz!-e  
}

foreach {n code} {
    00 x
    01 x-
    02 xe
    03 xy
    04 xy-
    05 xye
    06 xyee
    07 xye-
    08 xy--
    09 xy-=
    10 xyz/ee
    11 xyz/e-
    12 xyz/--
    13 xyz/-=
    14 xyz|ee
    15 xyz|e-
    16 xyz|--
    17 xyz|-=
    18 xyz+eee
    19 xyz+ee-
    20 xyz+e--
    21 xyz+e-=
    22 xyz+---
    23 xyz+--=
    24 xyz+-=_
    25 xyz&eee
    26 xyz&ee-
    27 xyz&e--
    28 xyz&e-=
    29 xyz&---
    30 xyz&--=
    31 xyz&-=_
    32 xyz!ee
    33 xyz!e-
    34 xyz!--
    35 xyz!-=
    36 xyz!-e
} {
    if {[string match xyz* $code]} {
	set sets {{} x y z {x y} {x z} {y z} {x y z}}
	set max 2
    } elseif {[string match xy* $code]} {
	set sets {{} x y {x y}}
	set max 1
    } elseif {[string match x* $code]} {
	set sets {{} x}
	set max 0
    } else {
	set sets {{}}
	set max 4
    }

    # Pre-loop, generate the relevant combinations of input.

    set states       [string range $code 0 $max]
    set combinations {}

    foreach st $sets {
	lappend combinations !reachable $st {}
	lappend combinations !useful    {}  $st
    }
    foreach method {
	!reachable&!useful !(reachable|useful)
	!reachable|!useful !(reachable&useful)
    } {
	foreach st $sets {
	    foreach fin $sets {
		lappend combinations $method $st $fin
	    }
	}
    }

    foreach {method st fin} $combinations {
	set key $n.$code.([join $st {}],[join $fin {}]).$method

	test faop-trim-${setimpl}-2.$key {trim} {
	    grammar::fa a
	    gen $code
	    a start set $st
	    a final set $fin

	    switch -exact -- $method {
		!reachable {set kept [a reachable_states]}
		!useful    {set kept [a useful_states]}
		!reachable&!useful -
		!(reachable|useful) {
		    set kept [struct::set union [a reachable_states] [a useful_states]]
		}
		!reachable|!useful -
		!(reachable&useful) {
		    set kept [struct::set intersect [a reachable_states] [a useful_states]]
		}
	    }
	    set kept [join [lsort $kept] {}]

	    grammar::fa::op::trim a $method
	    set res [expr {$kept eq [join [lsort [a states]] {}]}]
	    a destroy
	    set res
	} 1 ; # {}

	test faop-trim-${setimpl}-3.$key {second trim is null operation} {
	    grammar::fa a
	    gen $code
	    a start set $st
	    a final set $fin
	    grammar::fa::op::trim a $method
	    set res [a serialize]
	    grammar::fa::op::trim a $method
	    set res [validate_serial $res a]
	    a destroy
	    set res
	} ok ; # {}


	test faop-trim-${setimpl}-3.$key {trim, as method} {
	    grammar::fa a
	    gen $code
	    a start set $st
	    a final set $fin

	    switch -exact -- $method {
		!reachable {set kept [a reachable_states]}
		!useful    {set kept [a useful_states]}
		!reachable&!useful -
		!(reachable|useful) {
		    set kept [struct::set union [a reachable_states] [a useful_states]]
		}
		!reachable|!useful -
		!(reachable&useful) {
		    set kept [struct::set intersect [a reachable_states] [a useful_states]]
		}
	    }
	    set kept [join [lsort $kept] {}]

	    a trim $method
	    set res [expr {$kept eq [join [lsort [a states]] {}]}]
	    a destroy
	    set res
	} 1 ; # {}

	test faop-trim-${setimpl}-4.$key {second trim is null operation, for method} {
	    grammar::fa a
	    gen $code
	    a start set $st
	    a final set $fin
	    a trim $method
	    set res [a serialize]
	    a trim $method
	    set res [validate_serial $res a]
	    a destroy
	    set res
	} ok ; # {}
    }
}


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