[e-lang] ordered-region comparison is broken

Allen Short washort at divmod.com
Thu Dec 20 16:22:33 EST 2007


Ordered regions (produced by operations such as "1..10", etc) have a comparison method that is supposed to order regions by subset. Currently it's reporting non-overlapping regions as equivalent, and equivalent regions as non-overlapping, as well as ordering by superset instead. Here's a patch to fix it:


Index: src/esrc/org/erights/e/elang/coord/OrderedRegionMaker.emaker
===================================================================
--- src/esrc/org/erights/e/elang/coord/OrderedRegionMaker.emaker	(revision 474)
+++ src/esrc/org/erights/e/elang/coord/OrderedRegionMaker.emaker	(working copy)
@@ -514,8 +514,8 @@
              * As a region, my comparison is a subset test.
              */
             to op__cmp(other) :float64 {
-                def selfExtra := (self & !other).isEmpty()
-                def otherExtra := (other & !self).isEmpty()
+                def selfExtra := !(self & !other).isEmpty()
+                def otherExtra := !(other & !self).isEmpty()
                 if (selfExtra) {
                     if (otherExtra) {
                         # Both have left-overs, so they're incomparable.
Index: src/esrc/scripts/test/updoc/orderedRegion.updoc
===================================================================
--- src/esrc/scripts/test/updoc/orderedRegion.updoc	(revision 0)
+++ src/esrc/scripts/test/updoc/orderedRegion.updoc	(revision 0)
@@ -0,0 +1,18 @@
+Former bug: the sense of the 'isEmpty' tests in
+org.erights.e.elang.coord.OrderedRegionMaker$OrderedRegionMaker$self.op__cmp
+was reversed.
+
+? (1..10).op__cmp(1..10)
+# value: 0.0
+
+? (1..10).op__cmp(3..7)
+# value: 1.0
+
+?(1..10).op__cmp(1..20)
+#value: -1.0
+
+?(1..10).op__cmp(-10..10)
+#value: -1.0
+
+?(1..10).op__cmp(20..30)
+#value: NaN


More information about the e-lang mailing list