Skip to content

Commit

Permalink
Fix bug when comparing node with nil
Browse files Browse the repository at this point in the history
  • Loading branch information
febeling committed Mar 21, 2015
1 parent d968425 commit 254daba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]
### Fixed
- Fix a bug in `Libsvm::Node#==` when comparing with `nil`.

## [1.3.1] - 2015-03-21
### Fixed
- Spelling and punctuation in documentation comments
Expand Down
8 changes: 5 additions & 3 deletions lib/libsvm/node.rb
Expand Up @@ -90,13 +90,15 @@ def initialize(index=0, value=0.0)
self.value = value
end

# Compare features for equality.
# Compare feature node for equality.
#
# Nodes with equal index and value are equal.
#
# @return [Boolean]
def ==(other)
index == other.index && value == other.value
def == (other)
other.class == self.class &&
index == other.index &&
value == other.value
end

def inspect
Expand Down
4 changes: 4 additions & 0 deletions spec/node_spec.rb
Expand Up @@ -67,6 +67,10 @@
expect(ary.map(&:index)).to eq([3, 5, 6, 10])
end

it "compares with nil" do
expect(Node.new(1,2)).to_not eq(nil)
end

it "implements value equality" do
expect(Node[1, 0.1]).to eq(Node[1, 0.1])
end
Expand Down

0 comments on commit 254daba

Please sign in to comment.