Check-in [22d056d9e0]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add more FDDD tests, clean up whitespace in tests, and fix bugs exposed in testing.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:22d056d9e04ec7d7ce5b56a32d23df78b5ad24eb
User & Date: kbk 2014-08-02 23:48:33
Context
2014-08-02
23:54
Add more FDDD tests, clean up whitespace in tests, and fix bugs exposed in testing. check-in: 95d5eacadf user: kbk tags: trunk
23:48
Add more FDDD tests, clean up whitespace in tests, and fix bugs exposed in testing. check-in: 22d056d9e0 user: kbk tags: trunk
21:24
Refactor tests so that fddd tests do not test functions that depend only on the core BDD library check-in: 1c92997d04 user: kbk tags: trunk
Changes

Changes to library/tclfddd.tcl.

584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
...
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
...
988
989
990
991
992
993
994














995
996
997
998
999
1000
1001
	if {[lsearch -exact $destcolumns $col1] == -1} {
	    return -code error -errorcode \
		[list FDDD RelationDoesNotContainColumn $dest $col1] \
		"relation \"$dest\" does not contain column \"$col1\""
	}
	if {[lsearch -exact $destcolumns $col2] == -1} {
	    return -code error -errorcode \
		[list FDDD RelationDoesNotContainColumn $dest $col1] \
		"relation \"$dest\" does not contain column \"$col1\""
	}
	set vars1 [dict get $m_columns $col1]
	set vars2 [dict get $m_columns $col2]
	if {[llength $vars1] != [llength $vars2]} {
	    return -code error \
		-errorcode [list FDDD EquateWrongDomains $col1 $col2] \
		"cannot equate domains \"$col1\" and \"$col2\":\
                 sizes do not match"
	}

	# Sort the variables in descending order by the first column's
	# positions. This will keep them ordered well for the rename in
	# the easy cases.

................................................................................
	if {[lsearch -exact $destcolumns $col1] == -1} {
	    return -code error -errorcode \
		[list FDDD RelationDoesNotContainColumn $dest $col1] \
		"relation \"$dest\" does not contain column \"$col1\""
	}
	if {[lsearch -exact $destcolumns $col2] == -1} {
	    return -code error -errorcode \
		[list FDDD RelationDoesNotContainColumn $dest $col1] \
		"relation \"$dest\" does not contain column \"$col1\""
	}
	set vars1 [dict get $m_columns $col1]
	set vars2 [dict get $m_columns $col2]
	if {[llength $vars1] != [llength $vars2]} {
	    return -code error \
		-errorcode [list FDDD EquateWrongDomains $col1 $col2] \
		"cannot equate domains \"$col1\" and \"$col2\":\
                 sizes do not match"
	}

	# Sort the variables in descending order by the first column's
	# positions. This will keep them ordered well for the rename in
	# the easy cases.

................................................................................
	if {![dict exists $m_relcolumns $name]} {
	    return -level 2 -code error \
		-errorcode [list FDDD RelationNotDefined $name] \
		"relation \"$name\" is not defined in this database"
	}
	return
    }















    # Method: replace
    #
    #	Generates code to reassign physical domains in a relation
    #
    # Usage:
    #	$db replace dest source ?outcol incol?...







|
|





|
|







 







|
|





|
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>







584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
...
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
...
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
	if {[lsearch -exact $destcolumns $col1] == -1} {
	    return -code error -errorcode \
		[list FDDD RelationDoesNotContainColumn $dest $col1] \
		"relation \"$dest\" does not contain column \"$col1\""
	}
	if {[lsearch -exact $destcolumns $col2] == -1} {
	    return -code error -errorcode \
		[list FDDD RelationDoesNotContainColumn $dest $col2] \
		"relation \"$dest\" does not contain column \"$col2\""
	}
	set vars1 [dict get $m_columns $col1]
	set vars2 [dict get $m_columns $col2]
	if {[llength $vars1] != [llength $vars2]} {
	    return -code error \
		-errorcode [list FDDD CompareWrongDomains $col1 $col2] \
		"cannot compare domains \"$col1\" and \"$col2\":\
                 sizes do not match"
	}

	# Sort the variables in descending order by the first column's
	# positions. This will keep them ordered well for the rename in
	# the easy cases.

................................................................................
	if {[lsearch -exact $destcolumns $col1] == -1} {
	    return -code error -errorcode \
		[list FDDD RelationDoesNotContainColumn $dest $col1] \
		"relation \"$dest\" does not contain column \"$col1\""
	}
	if {[lsearch -exact $destcolumns $col2] == -1} {
	    return -code error -errorcode \
		[list FDDD RelationDoesNotContainColumn $dest $col2] \
		"relation \"$dest\" does not contain column \"$col2\""
	}
	set vars1 [dict get $m_columns $col1]
	set vars2 [dict get $m_columns $col2]
	if {[llength $vars1] != [llength $vars2]} {
	    return -code error \
		-errorcode [list FDDD CompareWrongDomains $col1 $col2] \
		"cannot compare domains \"$col1\" and \"$col2\":\
                 sizes do not match"
	}

	# Sort the variables in descending order by the first column's
	# positions. This will keep them ordered well for the rename in
	# the easy cases.

................................................................................
	if {![dict exists $m_relcolumns $name]} {
	    return -level 2 -code error \
		-errorcode [list FDDD RelationNotDefined $name] \
		"relation \"$name\" is not defined in this database"
	}
	return
    }

    # Method: relations
    #
    #	Lists the relations in a database
    #
    # Usage:
    #	$db relations
    #
    # Results:
    #	Returns the names of the relations

    method relations {} {
	return [lsort [dict keys $m_relcolumns]]
    }

    # Method: replace
    #
    #	Generates code to reassign physical domains in a relation
    #
    # Usage:
    #	$db replace dest source ?outcol incol?...

Changes to tests/fddd.test.

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
package require tcltest 2
namespace import -force ::tcltest::*
tcltest::loadTestedCommands
package require tclbdd::fddd

test fddd-1.1 {domain - wrong # args} {*}{
    -body {
	bdd::fddd::domain
    }
    -result {wrong # args: *}
    -match glob
    -returnCodes error
}

test fddd-1.2 {domain - bigendian default, littleendian available} {*}{
    -body {
	list \
	    [bdd::fddd::domain a 3] \
	    [bdd::fddd::domain b 3 littleendian] \
	    [bdd::fddd::domain c 3 bigendian]
    }
    -result {{{a {0 1 2}} {a 0 a 1 a 2}} {{b {0 1 2}} {b 0 b 1 b 2}} {{c {2 1 0}} {c 2 c 1 c 0}}}
}

test fddd-1.3 {interleave - duplicated domains} {*}{
    -body {
	list [catch {
	    bdd::fddd::interleave \
		[bdd::fddd::domain a 3] \
		[bdd::fddd::domain a 3]
	} result] $result $::errorCode
    }
    -result {1 {domain named "a" appears in multiple places} {FDDD DuplicateName a}}
}

test fddd-1.4 {interleave - two domains} {*}{
    -body {
	bdd::fddd::interleave \
	    [bdd::fddd::domain a 3] \
	    [bdd::fddd::domain b 3]
    }
    -result {{a {0 2 4} b {1 3 5}} {a 0 b 0 a 1 b 1 a 2 b 2}}
}

test fddd-1.5 {interleave - three domains} {*}{
    -body {
	bdd::fddd::interleave \
	    [bdd::fddd::domain a 3] \
	    [bdd::fddd::domain b 3 bigendian] \
	    [bdd::fddd::domain c 3]
    }
    -result {{a {0 3 6} b {7 4 1} c {2 5 8}} {a 0 b 2 c 0 a 1 b 1 c 1 a 2 b 0 c 2}}
}

test fddd-1.6 {interleave - domains of unequal lengths} {*}{
    -body {
	bdd::fddd::interleave \
	    [bdd::fddd::domain a 4] \
	    [bdd::fddd::domain b 3 bigendian] \
	    [bdd::fddd::domain c 2]
    }
    -result {{a {0 3 6 8} b {7 4 1} c {2 5}} {a 0 b 2 c 0 a 1 b 1 c 1 a 2 b 0 a 3}}
}

test fddd-1.7 {concatenate - duplicated domains} {*}{
    -body {
	list [catch {
	    bdd::fddd::concatenate \
		[bdd::fddd::domain a 3] \
		[bdd::fddd::domain a 3]
	} result] $result $::errorCode
    }
    -result {1 {domain named "a" appears in multiple places} {FDDD DuplicateName a}}
}

test fddd-1.8 {concatenate - two domains} {*}{
    -body {
	bdd::fddd::concatenate \
	    [bdd::fddd::domain a 3] \
	    [bdd::fddd::domain b 3 bigendian]
    }
    -result {{a {0 1 2} b {5 4 3}} {a 0 a 1 a 2 b 2 b 1 b 0}}
}

test fddd-1.9 {concatenate of interleaved} {*}{
    -body {
	bdd::fddd::concatenate \
	    [bdd::fddd::interleave \
		 [bdd::fddd::domain a 3] \
		 [bdd::fddd::domain b 3]] \
	    [bdd::fddd::interleave \
		 [bdd::fddd::domain c 3] \
		 [bdd::fddd::domain d 3]]
    }
    -result {{a {0 2 4} b {1 3 5} c {6 8 10} d {7 9 11}} {a 0 b 0 a 1 b 1 a 2 b 2 c 0 d 0 c 1 d 1 c 2 d 2}}
}

test fddd-1.10 {interleave of concatenated} {*}{
    -body {
	bdd::fddd::interleave \
	    [bdd::fddd::concatenate \
		 [bdd::fddd::domain a 3] \
		 [bdd::fddd::domain b 3]] \
	    [bdd::fddd::concatenate \
		 [bdd::fddd::domain c 3] \
		 [bdd::fddd::domain d 3]]
    }
    -result {{a {0 2 4} c {1 3 5} b {6 8 10} d {7 9 11}} {a 0 c 0 a 1 c 1 a 2 c 2 b 0 d 0 b 1 d 1 b 2 d 2}}
}

test fddd-2.1 {reader - 1 column} {*}{
    -constraints obsolete
    -setup {
	bdd::system create sys
	set layout \
	    [bdd::fddd::concatenate \
		 [bdd::fddd::domain a 2] \
		 [bdd::fddd::domain b 2]]
    }
    -body {
	interp alias {} rdr {} {*}[bdd::fddd::reader sys x $layout a]
	rdr 1
	rdr 2
	set result {}
	sys foreach_sat s x {
	    lappend result $s
	}
	sys unset x
	lappend result [sys gc]
	set result
    }
    -cleanup {
	rename rdr {}
	sys destroy
    }
    -result {{0 0 1 1} {0 1 1 0} 2}
}

test fddd-2.2 {reader - 2 columns} {
    -constraints obsolete
    -setup {
	bdd::system create sys
	set layout \
	    [bdd::fddd::concatenate \
		 [bdd::fddd::domain a 2 bigendian] \
		 [bdd::fddd::domain b 2 bigendian]]
    }
    -body {
	interp alias {} rdr {} {*}[bdd::fddd::reader sys x $layout a b]
	rdr 1 2
	rdr 2 3
	rdr 3 1
	set result {}
	sys foreach_sat s x {
	    lappend result $s
	}
	sys unset x
	lappend result [sys gc]
	set result
    }
    -cleanup {
	rename rdr {}
	sys destroy
    }
    -result {{0 0 1 1 2 1 3 0} {0 1 1 0 2 1 3 1} {0 1 1 1 2 0 3 1} 2}
}














































































































































































































































































































































































































































cleanupTests
return

# Local Variables:
# mode: tcl
# c-basic-offset: 4

# End:







|








|
|
|
|






|
|
|
|
|






|
|
|






|
|
|
|






|
|
|
|






|
|
|
|
|






|
|
|






|
|
|
|
|
|
|






|
|
|
|
|
|
|







|
|
|
|
|


|
|
|
|
|
|
|
|
|
|


|
|




|


|
|
|
|
|


|
|
|
|
|
|
|
|
|
|
|


|
|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>

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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
package require tcltest 2
namespace import -force ::tcltest::*
tcltest::loadTestedCommands
package require tclbdd::fddd

test fddd-1.1 {domain - wrong # args} {*}{
    -body {
        bdd::fddd::domain
    }
    -result {wrong # args: *}
    -match glob
    -returnCodes error
}

test fddd-1.2 {domain - bigendian default, littleendian available} {*}{
    -body {
        list \
            [bdd::fddd::domain a 3] \
            [bdd::fddd::domain b 3 littleendian] \
            [bdd::fddd::domain c 3 bigendian]
    }
    -result {{{a {0 1 2}} {a 0 a 1 a 2}} {{b {0 1 2}} {b 0 b 1 b 2}} {{c {2 1 0}} {c 2 c 1 c 0}}}
}

test fddd-1.3 {interleave - duplicated domains} {*}{
    -body {
        list [catch {
            bdd::fddd::interleave \
                [bdd::fddd::domain a 3] \
                [bdd::fddd::domain a 3]
        } result] $result $::errorCode
    }
    -result {1 {domain named "a" appears in multiple places} {FDDD DuplicateName a}}
}

test fddd-1.4 {interleave - two domains} {*}{
    -body {
        bdd::fddd::interleave \
            [bdd::fddd::domain a 3] \
            [bdd::fddd::domain b 3]
    }
    -result {{a {0 2 4} b {1 3 5}} {a 0 b 0 a 1 b 1 a 2 b 2}}
}

test fddd-1.5 {interleave - three domains} {*}{
    -body {
        bdd::fddd::interleave \
            [bdd::fddd::domain a 3] \
            [bdd::fddd::domain b 3 bigendian] \
            [bdd::fddd::domain c 3]
    }
    -result {{a {0 3 6} b {7 4 1} c {2 5 8}} {a 0 b 2 c 0 a 1 b 1 c 1 a 2 b 0 c 2}}
}

test fddd-1.6 {interleave - domains of unequal lengths} {*}{
    -body {
        bdd::fddd::interleave \
            [bdd::fddd::domain a 4] \
            [bdd::fddd::domain b 3 bigendian] \
            [bdd::fddd::domain c 2]
    }
    -result {{a {0 3 6 8} b {7 4 1} c {2 5}} {a 0 b 2 c 0 a 1 b 1 c 1 a 2 b 0 a 3}}
}

test fddd-1.7 {concatenate - duplicated domains} {*}{
    -body {
        list [catch {
            bdd::fddd::concatenate \
                [bdd::fddd::domain a 3] \
                [bdd::fddd::domain a 3]
        } result] $result $::errorCode
    }
    -result {1 {domain named "a" appears in multiple places} {FDDD DuplicateName a}}
}

test fddd-1.8 {concatenate - two domains} {*}{
    -body {
        bdd::fddd::concatenate \
            [bdd::fddd::domain a 3] \
            [bdd::fddd::domain b 3 bigendian]
    }
    -result {{a {0 1 2} b {5 4 3}} {a 0 a 1 a 2 b 2 b 1 b 0}}
}

test fddd-1.9 {concatenate of interleaved} {*}{
    -body {
        bdd::fddd::concatenate \
            [bdd::fddd::interleave \
                 [bdd::fddd::domain a 3] \
                 [bdd::fddd::domain b 3]] \
            [bdd::fddd::interleave \
                 [bdd::fddd::domain c 3] \
                 [bdd::fddd::domain d 3]]
    }
    -result {{a {0 2 4} b {1 3 5} c {6 8 10} d {7 9 11}} {a 0 b 0 a 1 b 1 a 2 b 2 c 0 d 0 c 1 d 1 c 2 d 2}}
}

test fddd-1.10 {interleave of concatenated} {*}{
    -body {
        bdd::fddd::interleave \
            [bdd::fddd::concatenate \
                 [bdd::fddd::domain a 3] \
                 [bdd::fddd::domain b 3]] \
            [bdd::fddd::concatenate \
                 [bdd::fddd::domain c 3] \
                 [bdd::fddd::domain d 3]]
    }
    -result {{a {0 2 4} c {1 3 5} b {6 8 10} d {7 9 11}} {a 0 c 0 a 1 c 1 a 2 c 2 b 0 d 0 b 1 d 1 b 2 d 2}}
}

test fddd-2.1 {reader - 1 column} {*}{
    -constraints obsolete
    -setup {
        bdd::system create sys
        set layout \
            [bdd::fddd::concatenate \
                 [bdd::fddd::domain a 2] \
                 [bdd::fddd::domain b 2]]
    }
    -body {
        interp alias {} rdr {} {*}[bdd::fddd::reader sys x $layout a]
        rdr 1
        rdr 2
        set result {}
        sys foreach_sat s x {
            lappend result $s
        }
        sys unset x
        lappend result [sys gc]
        set result
    }
    -cleanup {
        rename rdr {}
        sys destroy
    }
    -result {{0 0 1 1} {0 1 1 0} 2}
}

test fddd-2.2 {reader - 2 columns} {*}{
    -constraints obsolete
    -setup {
        bdd::system create sys
        set layout \
            [bdd::fddd::concatenate \
                 [bdd::fddd::domain a 2 bigendian] \
                 [bdd::fddd::domain b 2 bigendian]]
    }
    -body {
        interp alias {} rdr {} {*}[bdd::fddd::reader sys x $layout a b]
        rdr 1 2
        rdr 2 3
        rdr 3 1
        set result {}
        sys foreach_sat s x {
            lappend result $s
        }
        sys unset x
        lappend result [sys gc]
        set result
    }
    -cleanup {
        rename rdr {}
        sys destroy
    }
    -result {{0 0 1 1 2 1 3 0} {0 1 1 0 2 1 3 1} {0 1 1 1 2 0 3 1} 2}
}

# fddd-3 - database construction

test fddd-3.1 {constructor error} {*}{
    -body {
        bdd::fddd::database create db rubbish
    }
    -returnCodes error
    -result {expected a domain layout but found "rubbish"}
}

test fddd-3.2 {constructor error} {*}{
    -body {
        bdd::fddd::database create db \
            {an excessively long amount of rubbish that gets truncated}
    }
    -returnCodes error
    -result {expected a domain layout but found "an excessively long amount of rubbish th..."}
}

test fddd-3.3 {malformed list} {*}{
    -body {
        bdd::fddd::database create db \{
    }
    -returnCodes error
    -result {unmatched open brace in list}
}

test fddd-3.4 {actual construction} {*}{
    -body {
        bdd::fddd::database create ::db \
            [bdd::fddd::interleave \
                 [bdd::fddd::domain parent 8] \
                 [bdd::fddd::domain child 8]]
    }
    -result ::db
    -cleanup {
        db destroy
    }
}

proc makeDB {} {
    bdd::fddd::database create ::db\
        [bdd::fddd::interleave \
             [bdd::fddd::domain parent 8] \
             [bdd::fddd::domain child 8] \
             [bdd::fddd::domain xyz 8]]
}

# fddd-4 - relation construction

test fddd-4.1 {relation construction - missing column} {*}{
    -setup makeDB
    -body {
        list [catch {
            db relation isParentOf parent goofball
        } result] $result $::errorCode

    }
    -cleanup {db destroy}
    -result {1 {column "goofball" is not defined in this database} {FDDD ColumnNotDefined goofball}}
}

test fddd-4.2 {relation construction - successful} {*}{
    -setup makeDB
    -body {
        db relation isParentOf parent child
        lsort [db columns isParentOf]
    }
    -cleanup {db destroy}
    -result {child parent}
}

test fddd-4.3 {relation construction - duplicate name} {*}{
    -setup makeDB
    -body {
        db relation isParentOf parent child
        list [catch {
            db relation isParentOf parent child
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "isParentOf" is already defined in this database} {FDDD RelationAlreadyDefined isParentOf}}
}

proc makeDB {} {
    bdd::fddd::database create ::db\
        [bdd::fddd::interleave \
             [bdd::fddd::domain parent 8] \
             [bdd::fddd::domain child 8] \
             [bdd::fddd::domain xyz 8]]
    ::db relation isParentOf parent child
}

test fddd-5.1 {loader - code gen} {*}{
    -setup makeDB
    -body {
        lrange [::db loader isParentOf] 1 3
    }
    -cleanup {db destroy}
    -result {load isParentOf {0 0 0 1 1 0 3 0 1 4 1 1 6 0 2 7 1 2 9 0 3 10 1 3 12 0 4 13 1 4 15 0 5 16 1 5 18 0 6 19 1 6 21 0 7 22 1 7}}
}

proc makeDB {} {
    bdd::fddd::database create ::db\
        [bdd::fddd::interleave \
             [bdd::fddd::domain parent 3 bigendian] \
             [bdd::fddd::domain child 3 bigendian] \
             [bdd::fddd::domain xyz 3 bigendian]]
    ::db relation isParentOf parent child
    ::db relation troll parent
    interp alias {} loadIsParentOf {} {*}[::db loader isParentOf]
    interp alias {} loadTroll {} {*}[::db loader troll]
}

test fddd-5.2 {loader - load a relation} {*}{
    -setup makeDB
    -body {
        foreach {p c} {0 0 0 1 1 2 1 3 2 4 2 5 3 6 3 7} {
            loadIsParentOf $p $c
        }
        set r \n
        ::db enumerate d isParentOf {
            append r {        } $d \n
        }
        append r {    }
        string map [list \t {        }] $r
    }
    -cleanup {db destroy}
    -result {
        parent 0 child 0
        parent 0 child 1
        parent 1 child 2
        parent 1 child 3
        parent 2 child 4
        parent 2 child 5
        parent 3 child 6
        parent 3 child 7
    }
}

proc makeDB {} {
    bdd::fddd::database create ::db \
        [bdd::fddd::concatenate \
             [bdd::fddd::domain bit 1] \
             [bdd::fddd::interleave \
                  [bdd::fddd::domain parent 3 bigendian] \
                  [bdd::fddd::domain child 3 bigendian] \
                  [bdd::fddd::domain xyz 3 bigendian]]]
    ::db relation isParentOf parent child
    ::db relation result parent child
    ::db relation troll parent
    ::db relation everything bit parent child xyz
    interp alias {} loadIsParentOf {} {*}[::db loader isParentOf]
    interp alias {} loadTroll {} {*}[::db loader troll]
    foreach {p c} {0 0 0 1 1 2 1 3 2 4 2 5 3 6 3 7} {
        loadIsParentOf $p $c
    }
}

# fddd-6 - antijoin

test fddd-6.1 {antijoin - relation doesn't exist} {
    -setup makeDB
    -body {
        list [catch {
            db antijoin rubbish isParentOf troll
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "rubbish" is not defined in this database} {FDDD RelationNotDefined rubbish}}
}

test fddd-6.2 {antijoin - relation doesn't exist} {
    -setup makeDB
    -body {
        list [catch {
            db antijoin result rubbish troll
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "rubbish" is not defined in this database} {FDDD RelationNotDefined rubbish}}
}

test fddd-6.3 {antijoin - relation doesn't exist} {
    -setup makeDB
    -body {
        list [catch {
            db antijoin result isParentOf rubbish
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "rubbish" is not defined in this database} {FDDD RelationNotDefined rubbish}}
}

test fddd-6.4 {antijoin} {*}{
    -setup {
        makeDB
        foreach i {0 2} {
            loadTroll $i
        }
    }
    -body {
        eval [db antijoin result isParentOf troll]
        set r \n
        ::db enumerate d result {
            append r {        } $d \n
        }
        append r {    }
        string map [list \t {        }] $r
    }
    -result {
        parent 1 child 2
        parent 1 child 3
        parent 3 child 6
        parent 3 child 7
    }
    -cleanup {db destroy}
}

# fddd-7 - columns

test fddd-7.1 {columns} {
    -setup makeDB
    -body {
        lsort [db columns]
    }
    -cleanup {db destroy}
    -result {bit child parent xyz}
}

test fddd-7.2 {columns - bad relation} {
    -setup makeDB
    -body {
        list [catch {
            db columns rubbish
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "rubbish" is not defined in this database} {FDDD RelationNotDefined rubbish}}
}

test fddd-7.3 {columns} {
    -setup makeDB
    -body {
        lsort [db columns isParentOf]
    }
    -cleanup {db destroy}
    -result {child parent}
}

# fddd-8 - enumerate
# FIXME - implement this

# fddd-9 - equate

test fddd-9.1 {equate} {*}{
    -setup makeDB
    -body {
        list [catch {db equate rubbish bit parent} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "rubbish" is not defined in this database} {FDDD RelationNotDefined rubbish}}
}

test fddd-9.2 {equate} {*}{
    -setup makeDB
    -body {
        list [catch {db equate everything rubbish parent} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {column "rubbish" is not defined in this database} {FDDD ColumnNotDefined rubbish}}
}

test fddd-9.3 {equate} {*}{
    -setup makeDB
    -body {
        list [catch {db equate everything bit rubbish} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {column "rubbish" is not defined in this database} {FDDD ColumnNotDefined rubbish}}
}

test fddd-9.4 {equate} {*}{
    -setup makeDB
    -body {
        list [catch {db equate result bit child} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "result" does not contain column "bit"} {FDDD RelationDoesNotContainColumn result bit}}
}

test fddd-9.5 {equate} {*}{
    -setup makeDB
    -body {
        list [catch {db equate result parent bit} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "result" does not contain column "bit"} {FDDD RelationDoesNotContainColumn result bit}}
}

test fddd-9.6 {equate} {*}{
    -setup makeDB
    -body {
        list [catch {db equate everything parent bit} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {cannot compare domains "parent" and "bit": sizes do not match} {FDDD CompareWrongDomains parent bit}}
}

test fddd-9.7 {equate} {*}{
    -setup makeDB
    -body {
        eval [db equate result parent child]
        set r \n
        ::db enumerate d result {
            append r {        } $d \n
        }
        append r {    }
        set r
    }
    -cleanup {db destroy}
    -result {
        parent 0 child 0
        parent 1 child 1
        parent 2 child 2
        parent 3 child 3
        parent 4 child 4
        parent 5 child 5
        parent 6 child 6
        parent 7 child 7
    }
}

# fddd-10 - forget

test fddd-10.1 {forget - do nothing gracefully} {*}{
    -setup makeDB
    -body {
        db forget_relation rubbish
        db relations
    }
    -cleanup {db destroy}
    -result {everything isParentOf result troll}
}

test fddd-10.2 {forget - forget things} {*}{
    -setup makeDB
    -body {
        db forget_relation everything troll
        db relations
    }
    -cleanup {db destroy}
    -result {isParentOf result}
}

# fddd-11 - inequality

test fddd-11.1 {inequality} {*}{
    -setup makeDB
    -body {
        list [catch {db inequality rubbish bit parent} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "rubbish" is not defined in this database} {FDDD RelationNotDefined rubbish}}
}

test fddd-11.2 {inequality} {*}{
    -setup makeDB
    -body {
        list [catch {db inequality everything rubbish parent} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {column "rubbish" is not defined in this database} {FDDD ColumnNotDefined rubbish}}
}

test fddd-11.3 {inequality} {*}{
    -setup makeDB
    -body {
        list [catch {db inequality everything bit rubbish} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {column "rubbish" is not defined in this database} {FDDD ColumnNotDefined rubbish}}
}

test fddd-11.4 {inequality} {*}{
    -setup makeDB
    -body {
        list [catch {db inequality result bit child} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "result" does not contain column "bit"} {FDDD RelationDoesNotContainColumn result bit}}
}

test fddd-11.5 {inequality} {*}{
    -setup makeDB
    -body {
        list [catch {db inequality result parent bit} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "result" does not contain column "bit"} {FDDD RelationDoesNotContainColumn result bit}}
}

test fddd-11.6 {inequality} {*}{
    -setup makeDB
    -body {
        list [catch {db inequality everything parent bit} result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {cannot compare domains "parent" and "bit": sizes do not match} {FDDD CompareWrongDomains parent bit}}
}

test fddd-11.7 {inequality} {*}{
    -setup makeDB
    -body {
        eval [db inequality result parent child]
        for {set i 0} {$i < 8} {incr i} {
            for {set j 0} {$j < 8} {incr j} {
                dict set shouldhave $i:$j {}
            }
        }
        ::db enumerate d result {
            dict unset shouldhave [dict get $d parent]:[dict get $d child]
        }
        dict keys $shouldhave
    }
    -cleanup {db destroy}
    -result {0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7}
}

cleanupTests
return

# Local Variables:
# mode: tcl
# c-basic-offset: 4
# indent-tabs-mode: nil
# End: