Permalink
Browse files

Fixed list insertion bug: loss of 2 when inserting into [0,1,330]. In…

…cluded unit test.
  • Loading branch information...
1 parent b523a24 commit c9ff3d0e68bea9213550bdc984a1f3a368633077 @mohawkjohn mohawkjohn committed Dec 7, 2012
Showing with 16 additions and 4 deletions.
  1. +4 −4 ext/nmatrix/util/sl_list.cpp
  2. +12 −0 spec/nmatrix_list_spec.rb
@@ -344,14 +344,14 @@ NODE* find_nearest_from(NODE* prev, size_t key) {
f = find_preceding_from(prev, key);
- if (!f->next) {
+ if (!f->next) { // key exceeds final node; return final node.
return f;
- } else if (key == f->next->key) {
+ } else if (key == f->next->key) { // node already present; return location
return f->next;
-
+
} else {
- return prev;
+ return f;
}
}
View
@@ -79,5 +79,17 @@
n[1,0,0].should == 3
n[0,0,1].should == 4
end
+
+ it "should correctly insert a value between the middle and last entries of a three-element list" do
+ n = NMatrix.new(:list, 5940, 0, :float64)
+ n[0,0] = -7.0710685196786e-01
+ n[330,0] = 7.0710685196786e-01
+ n[1,0] = -7.0710685196786e-01
+ n[2,0] = -7.0710685196786e-01
+ n[0,0].should_not == 0
+ n[330,0].should_not == 0
+ n[2,0].should_not == 0
+ n[1,0].should_not == 0
+ end
end
end

0 comments on commit c9ff3d0

Please sign in to comment.