Skip to content

Commit

Permalink
Understanding octal converter
Browse files Browse the repository at this point in the history
  • Loading branch information
rabajaj0509 committed May 16, 2018
1 parent c01c0c2 commit 88792a2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Understanding assertions/base_conversion/octal_converter.rb
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 Understanding assertions/base_conversion/test_octal_converter.rb
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

0 comments on commit 88792a2

Please sign in to comment.