Created
December 18, 2012 04:16
-
-
Save kejadlen/4324973 to your computer and use it in GitHub Desktop.
Another coding assignment for Tableau.
This file contains hidden or 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
require 'minitest/autorun' | |
class TestDiv < MiniTest::Unit::TestCase | |
def div(x, y) | |
return 0 if x < y | |
current = 1 | |
while x - 2 * current * y >= y | |
current *= 2 | |
end | |
remainder = x - current * y | |
current + div(remainder, y) | |
end | |
def test_div | |
100.times do | |
x = rand(100) | |
y = rand(100) + 1 | |
assert_equal (x/y), div(x, y) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment