forked from rabajaj0509/Ruby-concepts-step-by-step
-
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.
- Loading branch information
1 parent
c01c0c2
commit 88792a2
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
Understanding assertions/base_conversion/octal_converter.rb
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,19 @@ | ||
class OctalConverter | ||
def initialize(number) | ||
@number = number | ||
end | ||
|
||
def convert | ||
octal = [] | ||
if @number < 8 | ||
octal << @number | ||
else | ||
until @number.zero? | ||
remainder = @number % 8 | ||
@number = @number / 8 | ||
octal.unshift(remainder) | ||
end | ||
end | ||
octal | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
Understanding assertions/base_conversion/test_octal_converter.rb
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,10 @@ | ||
require 'minitest/autorun' | ||
require_relative 'octal_converter' | ||
|
||
describe OctalConverter do | ||
it 'should return 137 for 95' do | ||
converter = OctalConverter.new(137) | ||
result = converter.convert | ||
assert_equal [2, 1, 1], result | ||
end | ||
end |