binary_decision_tree 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd430f35feb7cf78297db1208f4678ad0cb192f3
4
- data.tar.gz: 4777835269c7eca78d13d3694e11070c2b8f5729
3
+ metadata.gz: 788140290951a2efc6b9ea9d01f74a473d2d2472
4
+ data.tar.gz: ff066dc9ad48d7dea86df354b7465561030c43ce
5
5
  SHA512:
6
- metadata.gz: 7998bc2ad37b1d2b0652ac4b4117e199679a64b2594cafa3a2594e2c3b92c71e8b4c2b1a8b330f60c21d60b40d75cf546517d27d3f9c89aacd2bc370773fd81e
7
- data.tar.gz: 000651f02ad554ab4ab1350936e16bba13e54f47cb8a417301c70bd9fbfcfd209f2fbf6a326c97db9162e2e9cc4fb6bb775c80607fe77377d281ac2d0bb582db
6
+ metadata.gz: 215dff89705f8acbb8d9be7dd0e1de1423e03bb2898e8337829775bbfc24bf51c3ef50019470b85524c026f851b50242585fd624337ddb8798c825cee74382dd
7
+ data.tar.gz: 06d2a3284a398b1c119a2e665aa3962eedbb9e114025fc932deb3b687df500ee7f08e399d0c342dc9237fd77d499feee09ea9a6ebd07a7fd71de711d036b00e8
@@ -27,8 +27,8 @@ module BinaryDecisionTree
27
27
  new(depth, decisions, mask)
28
28
  end
29
29
 
30
- def to_tree
31
- tree = Tree.new(depth)
30
+ def to_tree(tree_class: Tree)
31
+ tree = tree_class.new(depth)
32
32
 
33
33
  (2**tree.depth).times do |i|
34
34
  next if i == 0
@@ -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 : Node.new(self, i)}
7
+ @nodes = Array.new(size) {|i| i == 0 ? nil : node_class.new(self, i)}
8
8
  end
9
9
 
10
10
  def root
@@ -1,3 +1,3 @@
1
1
  module BinaryDecisionTree
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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.0
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-04-30 00:00:00.000000000 Z
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