-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ruby/binary-search-tree: 1st iteration
- Loading branch information
Showing
10 changed files
with
409 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
=begin | ||
Write your code for the 'Binary Search Tree' exercise in this file. Make the tests in | ||
`binary_search_tree_test.rb` pass. | ||
# frozen_string_literal: false | ||
|
||
To get started with TDD, see the `README.md` file in your | ||
`ruby/binary-search-tree` directory. | ||
=end | ||
# https://exercism.org/tracks/ruby/exercises/binary-search-tree | ||
# Binary Search Tree exercise | ||
class Bst | ||
attr_reader :data, :left, :right | ||
|
||
def initialize(data = nil) | ||
@data = data | ||
@left = nil | ||
@right = nil | ||
end | ||
|
||
def insert(data) | ||
if data <= @data | ||
@left ? @left.insert(data) : @left = Bst.new(data) | ||
else | ||
@right ? @right.insert(data) : @right = Bst.new(data) | ||
end | ||
end | ||
|
||
def each(&block) | ||
return enum_for(:each) unless block_given? | ||
|
||
@left&.each(&block) | ||
block.call(@data) | ||
@right&.each(&block) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"result": { | ||
"line": 100.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"test:exercism": { | ||
"coverage": { | ||
"/home/vpayno/git_vpayno/exercism-workspace/ruby/binary-search-tree/binary_search_tree.rb": { | ||
"lines": [ | ||
null, | ||
null, | ||
null, | ||
null, | ||
1, | ||
1, | ||
null, | ||
1, | ||
33, | ||
33, | ||
33, | ||
null, | ||
null, | ||
1, | ||
35, | ||
18, | ||
null, | ||
17, | ||
null, | ||
null, | ||
null, | ||
1, | ||
20, | ||
null, | ||
19, | ||
19, | ||
19, | ||
null, | ||
null | ||
] | ||
} | ||
}, | ||
"timestamp": 1698805764 | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version='1.0'?> | ||
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd"> | ||
<!-- Generated by simplecov-cobertura version 2.1.0 (https://github.com/dashingrocket/simplecov-cobertura) --> | ||
<coverage line-rate="1.0" lines-covered="15" lines-valid="15" complexity="0" version="0" timestamp="1698805764"> | ||
<sources> | ||
<source>/home/vpayno/git_vpayno/exercism-workspace/ruby/binary-search-tree</source> | ||
</sources> | ||
<packages> | ||
<package name="binary-search-tree" line-rate="1.0" complexity="0"> | ||
<classes> | ||
<class name="binary_search_tree" filename="binary_search_tree.rb" line-rate="1.0" complexity="0"> | ||
<methods/> | ||
<lines> | ||
<line number="5" hits="1"/> | ||
<line number="6" hits="1"/> | ||
<line number="8" hits="1"/> | ||
<line number="9" hits="33"/> | ||
<line number="10" hits="33"/> | ||
<line number="11" hits="33"/> | ||
<line number="14" hits="1"/> | ||
<line number="15" hits="35"/> | ||
<line number="16" hits="18"/> | ||
<line number="18" hits="17"/> | ||
<line number="22" hits="1"/> | ||
<line number="23" hits="20"/> | ||
<line number="25" hits="19"/> | ||
<line number="26" hits="19"/> | ||
<line number="27" hits="19"/> | ||
</lines> | ||
</class> | ||
</classes> | ||
</package> | ||
</packages> | ||
</coverage> |
Oops, something went wrong.