Commits

Aleš Erjavec committed b05f82f

Fixed comparison of Orange.data.Instance when the domain is empty.

Comments (0)

Files changed (2)

Orange/testing/unit/tests/test_instance.py

         self.assertRaises(TypeError, Orange.data.Instance, (domain, ["?", "?", "?"]))
         self.assertRaises(TypeError, Orange.data.Instance, (domain, ["?", "?"]))
 
+    def test_compare(self):
+        # Empty domain/instance (compare equal)
+        domain = Orange.data.Domain([])
+        self.assertEqual(Orange.data.Instance(domain, []),
+                         Orange.data.Instance(domain, []))
+
+        lenses = Orange.data.Table("lenses")
+
+        inst1 = lenses[0]
+        inst2 = Orange.data.Instance(inst1)
+
+        self.assertEqual(inst1, inst2)
+
+        inst1[0] = "?"
+        self.assertNotEqual(inst1, inst2)
+
+        inst2[0] = "?"
+        self.assertEqual(inst1, inst2)
+
+        for f in lenses.domain:
+            inst1[f] = inst2[f] = "?"
+
+        self.assertEqual(inst1, inst2)
+
 
 if __name__ == "__main__":
-    unittest.main()
+    unittest.main()

source/orange/examples.cpp

 int TExample::compare(const TExample &other, const bool ignoreClass) const
 { if (domain != other.domain)
     raiseError("examples are from different domains");
-
   int Na = domain->variables->size();
   if (ignoreClass) {
       if (domain->classVar) {
       Na += domain->classVars->size();
   }
   if (!Na)
-    return true;
+    return 0;
 
   const_iterator i1(begin()), i2(other.begin());
   int comp;