Check-in [e546ebb465]

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:e546ebb465ce73fd25086251027d2661d9cbf36a
User & Date: kbk 2014-08-03 01:37:51
Context
2014-08-03
01:38
Add more FDDD tests, clean up whitespace in tests, and fix bugs exposed in testing. check-in: 323dd8ca3e user: kbk tags: trunk
01:37
Add more FDDD tests, clean up whitespace in tests, and fix bugs exposed in testing. check-in: e546ebb465 user: kbk tags: trunk
00:21
Add more FDDD tests, clean up whitespace in tests, and fix bugs exposed in testing. check-in: 00ccb10f83 user: kbk tags: trunk
Changes

Changes to library/tclfddd.tcl.

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
...
529
530
531
532
533
534
535






536
537
538
539
540
541
542
543
544
545
546
....
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
....
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
    set chain {}
    foreach b $bits {
	lappend chain {*}$b
    }
    return [list [Invert $chain] $chain]
}

if 0 { # this needs to be a method of the database

# bdd::fddd::support --
#
#	Makes a call to the BDD engine to determine the support of a relation
#	in a finite domain
#
# Usage:
#	bdd::fddd::support sysName relationName layout
#
# Parameters:
#	sysName - Name of the system of BDD's
#	relationName - Name of the relation to be analyzed
#	layout - Description of the finite domain
#
# Results:
#	Returns the names of variables on which the relation depends.

proc bdd::fddd::support {sysName relationName layout} {
    set haveVar {}
    foreach bit [$sysName support $relationName] {
	dict set haveVar [lindex $layout 1 [expr {2 * $bit}]] {}
    }
    return [dict keys $haveVar]
}

}

# Class: bdd::fddd::database
#
#	Class that represents a database containing relations whose
#       columns belong to finite domains. The database is held in a
#	system of Binary Decision Diagrams (BDD's).

oo::class create bdd::fddd::database {
................................................................................
		}

		# Evaluate the script and handle the status returns
		try {
		    uplevel 1 $script
		} on error {message options} {
		    dict incr options -level 1






		    return -options $options $message
		} on return {retval options} {
		    dict incr options -level 1
		    return -options $options $message
		} on break {} {
		    return -level 0 -code 6
		} on continue {} {
		    continue
		}
	    }
	}
................................................................................
		return -code error \
		    -errorcode [list FDDD DuplicateReplaceOutput $to] \
		    "attempt to rename two input columns to \"$to\""
	    }
	    if {![dict exists $sourcecols $from]} {
		return -code error \
		    -errorcode [list FDDD BadReplaceInput $from] \
		    "attempt to rename an input column \"from\" that\
		     does not exist or has already been renamed"
	    }
	    if {![dict exists $destcols $to]} {
		return -code error \
		    -errorcode [list FDDD BadReplaceOutput $to] \
		    "attempt to rename an input column to \"$to\",
                     which does not exist in \"$dest\""
	    }
	    dict unset sourcecols $from
	    dict set colsAdded $to {}
	}
	foreach {to from} $args {
	    if {[dict exists $sourcecols $to]} {
		return -code error \
		    -errorcode [list FDDD ReplaceOutputOverInput $to] \
		    "attempt to rename an input column to \"$to\",
                     but another input column already has that name."
	    }
	    dict set sourcecols $to {}
	}
	my ColumnsMustBe $dest [lsort -dictionary [dict keys $sourcecols]]

	set fromvars {}
	set tovars {}
	foreach {to from} $args {
	    set tv [dict get $m_columns $to]
	    set fv [dict get $m_columns $from]
	    if {[llength $tv] < [llength $fv]} {
		return -code error \
		    -errorcode [list FDDD ReplaceColumnTooNarrow $from $to] \
		    "replacement column \"$to\" is to narrow to hold values\
                     from column \"$from\""
	    }
	    lappend fromvars {*}$fv
	    lappend tovars {*}[lrange $tv 0 [expr {[llength $fv] - 1}]]
	}

	return \
................................................................................
	my relationMustExist $dest
	my relationMustExist $source1
	my relationMustExist $source2
	my ColumnsMustBeSame $dest $source1
	my ColumnsMustBeSame $dest $source2
	return [list [namespace which sys] | $dest $source1 $source2]
    }

if 0 {
    # deprecate this for now.
    method load {name list} {
	my relationMustExist $name
	set nColumns [llength [dict get $m_relcolumns $name]]
	if {[llength $list] % $nColumns != 0} {
	    return -code error \
		-errorcode [list FDDD WrongListLength $nColumns] \
		"list must have a multiple of $nColumns values"
	}
	set reader [my loader $name]
	set nCM1 [expr {$nColumns - 1}]
	while {[llength $list] > 0} {
	    {*}$reader {*}[lrange $list 0 $nCM1]
	    set list [lreplace ${list}[set list {}] 0 $nCM1]
	}
	return
    }
}



}

package provide tclbdd::fddd 0.1







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
>



|







 







|




|
|








|
|
|












|
|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



188
189
190
191
192
193
194




























195
196
197
198
199
200
201
...
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
....
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
....
1147
1148
1149
1150
1151
1152
1153























1154
1155
1156
    set chain {}
    foreach b $bits {
	lappend chain {*}$b
    }
    return [list [Invert $chain] $chain]
}





























# Class: bdd::fddd::database
#
#	Class that represents a database containing relations whose
#       columns belong to finite domains. The database is held in a
#	system of Binary Decision Diagrams (BDD's).

oo::class create bdd::fddd::database {
................................................................................
		}

		# Evaluate the script and handle the status returns
		try {
		    uplevel 1 $script
		} on error {message options} {
		    dict incr options -level 1
		    regsub \
			{\("uplevel" body line (\d*?)\).*?\("try" body line 2\)} \
			[dict get $options -errorinfo] \
			{("enumerate" body, line \1)} \
			ei
		    dict set options -errorinfo $ei
		    return -options $options $message
		} on return {retval options} {
		    dict incr options -level 1
		    return -options $options $retval
		} on break {} {
		    return -level 0 -code 6
		} on continue {} {
		    continue
		}
	    }
	}
................................................................................
		return -code error \
		    -errorcode [list FDDD DuplicateReplaceOutput $to] \
		    "attempt to rename two input columns to \"$to\""
	    }
	    if {![dict exists $sourcecols $from]} {
		return -code error \
		    -errorcode [list FDDD BadReplaceInput $from] \
		    "attempt to rename an input column \"$from\" that\
		     does not exist or has already been renamed"
	    }
	    if {![dict exists $destcols $to]} {
		return -code error \
		    -errorcode [list FDDD BadReplaceOutput $to $dest] \
		    "attempt to rename an input column to \"$to\",\
                     which does not exist in \"$dest\""
	    }
	    dict unset sourcecols $from
	    dict set colsAdded $to {}
	}
	foreach {to from} $args {
	    if {[dict exists $sourcecols $to]} {
		return -code error \
		    -errorcode [list FDDD ReplaceOutputOverInput $from $to] \
		    "attempt to rename input column \"$from\" to \"$to\",\
                     but another input column already has that name"
	    }
	    dict set sourcecols $to {}
	}
	my ColumnsMustBe $dest [lsort -dictionary [dict keys $sourcecols]]

	set fromvars {}
	set tovars {}
	foreach {to from} $args {
	    set tv [dict get $m_columns $to]
	    set fv [dict get $m_columns $from]
	    if {[llength $tv] < [llength $fv]} {
		return -code error \
		    -errorcode [list FDDD ReplaceColumnTooNarrow $to $from] \
		    "replacement column \"$to\" is too narrow to hold values\
                     from column \"$from\""
	    }
	    lappend fromvars {*}$fv
	    lappend tovars {*}[lrange $tv 0 [expr {[llength $fv] - 1}]]
	}

	return \
................................................................................
	my relationMustExist $dest
	my relationMustExist $source1
	my relationMustExist $source2
	my ColumnsMustBeSame $dest $source1
	my ColumnsMustBeSame $dest $source2
	return [list [namespace which sys] | $dest $source1 $source2]
    }























}

package provide tclbdd::fddd 0.1

Changes to tests/fddd.test.

329
330
331
332
333
334
335



336
337
338
339
340
341
342
...
429
430
431
432
433
434
435
436
































































437
438
439
440
441
442
443
...
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
...
800
801
802
803
804
805
806






807






































































































































































































































































































808
809
810
811
812
813
814
815
816
             [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
    }
}
................................................................................
        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
................................................................................
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
................................................................................
        }
        lsort [dict keys $r]
    }
    -cleanup {db destroy}
    -result {0 1 2 3}
}















































































































































































































































































































cleanupTests
return

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







>
>
>







 







<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|





|







 







>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
...
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
...
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
...
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
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
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
             [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 temp1 parent xyz
    ::db relation temp2 xyz child
    ::db relation temp3 parent xyz child
    ::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
    }
}
................................................................................
        lsort [db columns isParentOf]
    }
    -cleanup {db destroy}
    -result {child parent}
}

# fddd-8 - enumerate


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

test fddd-8.2 {enumerate - error in script} {*}{
    -setup makeDB
    -body {
        list [catch {
            db enumerate d isParentOf {error testing}
        } result] $result [regsub -all \n $::errorInfo ^]
    }
    -cleanup {db destroy}
    -match glob
    -result {1 testing {testing^    while executing^"error testing"^    ("enumerate" body, line 1)^    invoked from within^"db enumerate d isParentOf {error testing}"}}
}

test fddd-8.3 {enumerate - return from script} {*}{
    -setup {
        makeDB
        proc doit {} {
            db enumerate d isParentOf {return {testing}}
        }
    }
    -body doit
    -cleanup {
        db destroy
        rename doit {}
    }
    -result testing
}

test fddd-8.4 {enumerate - break out of script} {*}{
    -setup makeDB
    -body {
        set r {}
        db enumerate d isParentOf {
            if {[dict get $d child] == 5} break
            lappend r [dict get $d parent]:[dict get $d child]
        }
        set r
    }
    -cleanup {db destroy}
    -result {0:0 0:1 1:2 1:3 2:4}
}

test fddd-8.5 {enumerate - continue in script} {*}{
    -setup makeDB
    -body {
        set r {}
        db enumerate d isParentOf {
            if {[dict get $d child] == 5} continue
            lappend r [dict get $d parent]:[dict get $d child]
        }
        set r
    }
    -cleanup {db destroy}
    -result {0:0 0:1 1:2 1:3 2:4 3:6 3:7}
}

# fddd-9 - equate

test fddd-9.1 {equate} {*}{
    -setup makeDB
    -body {
        list [catch {db equate rubbish bit parent} result] $result $::errorCode
................................................................................
test fddd-10.1 {forget - do nothing gracefully} {*}{
    -setup makeDB
    -body {
        db forget_relation rubbish
        db relations
    }
    -cleanup {db destroy}
    -result {everything isParentOf result temp1 temp2 temp3 troll}
}

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

# fddd-11 - inequality
................................................................................
        }
        lsort [dict keys $r]
    }
    -cleanup {db destroy}
    -result {0 1 2 3}
}

test fddd-16.1 {replace} {*}{
    -setup makeDB
    -body {
        list [catch {
            db replace rubbish isParentOf xyz child
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "rubbish" is not defined in this database} {FDDD RelationNotDefined rubbish}}
}

test fddd-16.2 {replace} {*}{
    -setup makeDB
    -body {
        list [catch {
            db replace temp1 rubbish xyz child
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "rubbish" is not defined in this database} {FDDD RelationNotDefined rubbish}}
}

test fddd-16.3 {replace} {*}{
    -setup makeDB
    -body {
        list [catch {
            db replace temp1 isParentOf rubbish child
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {column "rubbish" is not defined in this database} {FDDD ColumnNotDefined rubbish}}
}

test fddd-16.4 {replace} {*}{
    -setup makeDB
    -body {
        list [catch {
            db replace temp1 isParentOf xyz rubbish
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {column "rubbish" is not defined in this database} {FDDD ColumnNotDefined rubbish}}
}

test fddd-16.5 {replace} {*}{
    -setup makeDB
    -body {
        list [catch {
            db replace temp1 isParentOf xyz parent xyz child
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {attempt to rename two input columns to "xyz"} {FDDD DuplicateReplaceOutput xyz}}
}

test fddd-16.6 {replace} {*}{
    -setup makeDB
    -body {
        list [catch {
            db replace temp1 isParentOf parent child xyz child
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {attempt to rename an input column "child" that does not exist or has already been renamed} {FDDD BadReplaceInput child}}
}

test fddd-16.7 {replace} {*}{
    -setup makeDB
    -body {
        list [catch {
            db replace result isParentOf xyz parent
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {attempt to rename an input column to "xyz", which does not exist in "result"} {FDDD BadReplaceOutput xyz result}}
}

test fddd-16.8 {replace} {*}{
    -setup makeDB
    -body {
        list [catch {
            db replace temp1 isParentOf parent child
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {attempt to rename input column "child" to "parent", but another input column already has that name} {FDDD ReplaceOutputOverInput child parent}}
}

test fddd-16.9 {replace} {*}{
    -setup makeDB
    -body {
        list [catch {
            db replace everything isParentOf xyz child
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relation "everything" has columns bit, parent, child, xyz but should have columns parent, xyz} {FDDD WrongColumns everything {bit parent child xyz} {parent xyz}}}
}

test fddd-16.10 {replace} {*}{
    -setup makeDB
    -body {
        list [catch {
            db replace everything everything bit child child bit
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {replacement column "bit" is too narrow to hold values from column "child"} {FDDD ReplaceColumnTooNarrow bit child}}
}

test fddd-16.11 {replace} {*}{
    -setup makeDB
    -body {
        set r {}
        eval [db replace result isParentOf child parent parent child]
        db enumerate d result {
            lappend r [dict get $d parent]:[dict get $d child]
        }
        lsort $r
    }
    -cleanup {db destroy}
    -result {0:0 1:0 2:1 3:1 4:2 5:2 6:3 7:3}
}

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

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

test fddd-17.3 {set} {*}{
    -setup makeDB
    -body {
        list [catch {
            db set result troll
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relations "result" and "troll" have different columns} {FDDD DifferentColumns result troll}}
}

test fddd-17.4 {set} {*}{
    -setup makeDB
    -body {
        eval [db set result {}]
        set r {}
        db enumerate d result {
            lappend r [dict get $d parent]:[dict get $d child]
        }
        lsort $r
    }
    -cleanup {db destroy}
    -result {}
}

test fddd-17.5 {set} {*}{
    -setup makeDB
    -body {
        eval [db set result _]
        set r {}
        db enumerate d result {
            dict set r [dict get $d parent]:[dict get $d child] {}
        }
        set trouble {}
        set sep {}
        for {set i 0} {$i < 8} {incr i} {
            for {set j 0} {$j < 8} {incr j} {
                if {![dict exists $r $i:$j]} {
                    append trouble $sep "missing: $i:$j"
                    set sep \n
                } else {
                    dict unset r $i:$j
                }
            }
        }
        foreach item [dict keys $r] {
            append trouble $sep "extra: $item"
            set sep \n
        }
        set trouble
    }
    -cleanup {db destroy}
    -result {}
}

test fddd-17.6 {set} {*}{
    -setup makeDB
    -body {
        eval [db set result isParentOf]
        set r {}
        db enumerate d result {
            lappend r [dict get $d parent]:[dict get $d child]
        }
        lsort $r
    }
    -cleanup {db destroy}
    -result {0:0 0:1 1:2 1:3 2:4 2:5 3:6 3:7}
}

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

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

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

test fddd-18.4 {union} {
    -setup makeDB
    -body {
        list [catch {
            db union result temp1 isParentOf
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relations "result" and "temp1" have different columns} {FDDD DifferentColumns result temp1}}
}

test fddd-18.5 {union} {
    -setup makeDB
    -body {
        list [catch {
            db union result result temp2
        } result] $result $::errorCode
    }
    -cleanup {db destroy}
    -result {1 {relations "result" and "temp2" have different columns} {FDDD DifferentColumns result temp2}}
}

test fddd-18.6 {union} {
    -setup makeDB
    -body {
        eval [db equate result parent child]
        eval [db union result result isParentOf]
        set r {}
        db enumerate d result {
            lappend r [dict get $d parent]:[dict get $d child]
        }
        lsort $r
    }
    -cleanup {db destroy}
    -result {0:0 0:1 1:1 1:2 1:3 2:2 2:4 2:5 3:3 3:6 3:7 4:4 5:5 6:6 7:7}
}

test fddd-30.1 {demo of an actual database join} {
    -setup makeDB
    -body {
        eval [db replace temp1 isParentOf xyz child]
        eval [db replace temp2 isParentOf xyz parent]
        eval [db join temp3 temp1 temp2]
        eval [db project result temp3]
        set r {}
        db enumerate d result {
            lappend r [dict get $d parent]:[dict get $d child]
        }
        lsort $r
    }
    -cleanup {db destroy}
    -result {0:0 0:1 0:2 0:3 1:4 1:5 1:6 1:7}
}

cleanupTests
return

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