Skip to content
Browse files

fixed removal bug, improved tests

  • Loading branch information...
1 parent 7bd86ed commit e66df92219a412101f5bfeccc42f2e3c27bd61f2 @DNCrane committed
Showing with 13 additions and 9 deletions.
  1. +1 −3 Cover_Tree.h
  2. +1 −1 Cover_Tree_Point.cc
  3. +11 −5 test.cc
View
4 Cover_Tree.h
@@ -1,6 +1,4 @@
/*
- * opencog/util/Cover_Tree.h
- *
* Copyright (C) 2011 by Singularity Institute for Artificial Intelligence
* All Rights Reserved
*
@@ -343,7 +341,7 @@ void CoverTree<Point>::remove_rec(const Point& p,
}
}
if(level>_minLevel) remove_rec(p,coverSets,level-1,multi);
- if(minDist == 0.0) {//if minDist is 0.0 then minNode must be removed.
+ if(minNode->hasPoint(p)) {//minDist == 0.0) {//if minDist is 0.0 then minNode must be removed.
//the multi flag indicates the point we removed is from a
//node containing multiple points, and we have removed it.
if(multi) return;
View
2 Cover_Tree_Point.cc
@@ -38,5 +38,5 @@ void CoverTreePoint::print() const {
}
bool CoverTreePoint::operator==(const CoverTreePoint& p) const {
- return (this->distance(p)==0.0 && _name==p.getChar());
+ return (_vec==p.getVec() && _name==p.getChar());
}
View
16 test.cc
@@ -41,8 +41,7 @@ void testTree() {
else cout << "KNN test: \t\t\t\tFailed\n";
cTree.insert(CoverTreePoint(a,'b'));
- cTree.insert(CoverTreePoint(a,'c'));
-
+ cTree.insert(CoverTreePoint(a,'c'));
points = cTree.kNearestNeighbors(CoverTreePoint(a,'a'), 1);
//there should be a three-way tie since there are 3 nodes with distance 0
@@ -64,15 +63,22 @@ void testTree() {
cout << "Remove nonexistent point test: \t\tPassed\n";
else cout << "Remove nonexistent point test: \t\tFailed\n";
+ a[0]=1.1; cTree.remove(CoverTreePoint(a,'b')); //this has dist 0 to a
+ //node in cTree, but it is a different point, so the removal should not
+ //alter the tree at all.
+ points = cTree.kNearestNeighbors(CoverTreePoint(a,'c'),1);
+ if(points[0]==CoverTreePoint(a,'a') && cTree.isValidTree()) cout << "Remove differently-named point test: \tPassed\n";
+ else cout << "Remove differently-named point test: \tFailed\n";
+
a[0]=3.2; cTree.remove(CoverTreePoint(a,'a'));
a[0]=1.1; cTree.remove(CoverTreePoint(a,'a'));
a[0]=2.5; cTree.remove(CoverTreePoint(a,'a'));
if(cTree.isValidTree()) cout << "Remove test: \t\t\t\tPassed\n";
- else cout << "Remove test: \t\t\t\tPassed\n";
+ else cout << "Remove test: \t\t\t\tFailed\n";
a[0]=1.0; cTree.remove(CoverTreePoint(a,'a'));
if(cTree.isValidTree()) cout << "Remove root test: \t\t\tPassed\n";
- else cout << "Remove root test: \t\t\tPassed\n";
+ else cout << "Remove root test: \t\t\tFailed\n";
vector<double> start;
for(int j=0;j<5;j++) start.push_back((double)rand()/(double)RAND_MAX);
@@ -97,7 +103,7 @@ void testTree() {
points.push_back(CoverTreePoint(a,'a'));
}
if(cTree2.isValidTree()) cout << "500 random inserts test: \t\tPassed\n";
- else cout << "500 random inserts test: \t\tPassed\n";
+ else cout << "500 random inserts test: \t\tFailed\n";
bool NNGood=true;
for(int i=0;i<100;i++) {

0 comments on commit e66df92

Please sign in to comment.
Something went wrong with that request. Please try again.