Skip to content

Instantly share code, notes, and snippets.

@diegocasmo
Created February 9, 2017 14:36
Show Gist options
  • Save diegocasmo/a6ea2f301e8efd5d2c08aefdb08dad41 to your computer and use it in GitHub Desktop.
Save diegocasmo/a6ea2f301e8efd5d2c08aefdb08dad41 to your computer and use it in GitHub Desktop.
Tests for an implementation of the Karatsuba multiplication algorithm in Ruby
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
@diegocasmo
Copy link
Author

The Karatsuba class being tested can be found here: https://gist.github.com/diegocasmo/27988de71d4ab22f11654ce0fefff4b1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment