Created
February 9, 2017 14:36
-
-
Save diegocasmo/a6ea2f301e8efd5d2c08aefdb08dad41 to your computer and use it in GitHub Desktop.
Tests for an implementation of the Karatsuba multiplication algorithm in Ruby
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' | |
require './karatsuba' | |
describe Karatsuba do | |
before do | |
@karatsuba = Karatsuba.new | |
end | |
describe "#multiply" do | |
it "should multiply small numbers of equal size" do | |
assert_equal(@karatsuba.multiply(5, 5), 25) | |
end | |
it "should multiply small numbers of different size" do | |
assert_equal(@karatsuba.multiply(3, 12), 36) | |
end | |
it "should multiply small numbers with zeros inbetween" do | |
assert_equal(@karatsuba.multiply(10, 100), 1000) | |
end | |
it "should multiply large numbers with zeros inbetween" do | |
assert_equal(@karatsuba.multiply(100020001, 10030501), 1003250720050501) | |
end | |
it "should multiply large numbers of equal size" do | |
assert_equal(@karatsuba.multiply(345345345, 146348395), 50540736961471275) | |
end | |
it "should multiply large numbers of different size" do | |
assert_equal(@karatsuba.multiply(7655432, 7853), 60118107496) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Karatsuba class being tested can be found here: https://gist.github.com/diegocasmo/27988de71d4ab22f11654ce0fefff4b1