binary_decision_tree 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/binary_decision_tree/marshalled_tree.rb +2 -2
- data/lib/binary_decision_tree/tree.rb +2 -2
- data/lib/binary_decision_tree/version.rb +1 -1
- data/test/unit/binary_decision_tree/marshalled_tree_test.rb +11 -4
- data/test/unit/binary_decision_tree/tree_test.rb +14 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 788140290951a2efc6b9ea9d01f74a473d2d2472
|
4
|
+
data.tar.gz: ff066dc9ad48d7dea86df354b7465561030c43ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 215dff89705f8acbb8d9be7dd0e1de1423e03bb2898e8337829775bbfc24bf51c3ef50019470b85524c026f851b50242585fd624337ddb8798c825cee74382dd
|
7
|
+
data.tar.gz: 06d2a3284a398b1c119a2e665aa3962eedbb9e114025fc932deb3b687df500ee7f08e399d0c342dc9237fd77d499feee09ea9a6ebd07a7fd71de711d036b00e8
|
@@ -2,9 +2,9 @@ module BinaryDecisionTree
|
|
2
2
|
class Tree
|
3
3
|
attr_reader :depth
|
4
4
|
|
5
|
-
def initialize(depth)
|
5
|
+
def initialize(depth, node_class: Node)
|
6
6
|
@depth = depth
|
7
|
-
@nodes = Array.new(size) {|i| i == 0 ? nil :
|
7
|
+
@nodes = Array.new(size) {|i| i == 0 ? nil : node_class.new(self, i)}
|
8
8
|
end
|
9
9
|
|
10
10
|
def root
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative '../../../test/test_helper'
|
2
2
|
|
3
3
|
module BinaryDecisionTree
|
4
|
+
class SubTree < Tree; end
|
5
|
+
|
4
6
|
class MarshalledTreeTest < MiniTest::Spec
|
5
7
|
before do
|
6
8
|
@tree = Tree.new(6)
|
@@ -8,13 +10,11 @@ module BinaryDecisionTree
|
|
8
10
|
next if i == 0
|
9
11
|
@tree.at(i).decision = rand(2)
|
10
12
|
end
|
13
|
+
|
14
|
+
@marshalled_tree = MarshalledTree.from_tree(@tree)
|
11
15
|
end
|
12
16
|
|
13
17
|
describe "marshalling a tree" do
|
14
|
-
before do
|
15
|
-
@marshalled_tree = MarshalledTree.from_tree(@tree)
|
16
|
-
end
|
17
|
-
|
18
18
|
it "should marshal and unmarshal to the same tree" do
|
19
19
|
assert_same_tree @tree, @marshalled_tree.to_tree
|
20
20
|
end
|
@@ -24,5 +24,12 @@ module BinaryDecisionTree
|
|
24
24
|
assert_same_tree @tree, another_tree
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
describe "using a different tree class" do
|
29
|
+
it "should instantiate the correct object type" do
|
30
|
+
assert_equal Tree, @marshalled_tree.to_tree.class
|
31
|
+
assert_equal SubTree, @marshalled_tree.to_tree(tree_class: SubTree).class
|
32
|
+
end
|
33
|
+
end
|
27
34
|
end
|
28
35
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative '../../../test/test_helper'
|
2
|
+
|
3
|
+
module BinaryDecisionTree
|
4
|
+
class SubNode < Node; end
|
5
|
+
|
6
|
+
class TreeTest < MiniTest::Spec
|
7
|
+
describe "creating a new tree" do
|
8
|
+
it "should allow an optional node class" do
|
9
|
+
assert_equal Node, Tree.new(1).root.class
|
10
|
+
assert_equal SubNode, Tree.new(1, node_class: SubNode).root.class
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binary_decision_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Haruska
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- test/test_helper.rb
|
105
105
|
- test/unit/binary_decision_tree/marshalled_tree_test.rb
|
106
106
|
- test/unit/binary_decision_tree/node_test.rb
|
107
|
+
- test/unit/binary_decision_tree/tree_test.rb
|
107
108
|
homepage: http://github.com/haruska/binary_decision_tree
|
108
109
|
licenses:
|
109
110
|
- MIT
|
@@ -132,3 +133,4 @@ test_files:
|
|
132
133
|
- test/test_helper.rb
|
133
134
|
- test/unit/binary_decision_tree/marshalled_tree_test.rb
|
134
135
|
- test/unit/binary_decision_tree/node_test.rb
|
136
|
+
- test/unit/binary_decision_tree/tree_test.rb
|