test/lib/sungemm_test.rb in sungemm-0.0.2 vs test/lib/sungemm_test.rb in sungemm-0.0.3

- old
+ new

@@ -1,31 +1,75 @@ require "test_helper" -class SungemmTest < MiniTest::Unit::TestCase - def test_fibo_finder - assert_equal 0, Sungemm.fibo_finder(0) - assert_equal 1, Sungemm.fibo_finder(1) - assert_equal 3, Sungemm.fibo_finder(4) - assert_equal 13, Sungemm.fibo_finder(7) - assert_equal 55, Sungemm.fibo_finder(10) - end - +class SungemmTest < MiniTest::Test def test_stack stack = Sungemm::Stack.new([5, 6, 7, 8]) - assert_equal stack.pop, 8 - assert_equal stack.pop, 7 - assert_equal stack.push([4, 2]), true - assert_equal stack.pop(3), [2, 4, 6] - assert_equal stack.to_a, [5] + assert_equal 8, stack.pop + assert_equal 7, stack.pop + assert_equal true, stack.push([4, 2]) + assert_equal [2, 4, 6], stack.pop(3) + assert_equal [5], stack.to_a end def test_queue queue = Sungemm::Queue.new([5, 6, 7, 8]) - assert_equal queue.pop, 5 - assert_equal queue.pop, 6 - assert_equal queue.push([4, 2]), true - assert_equal queue.pop(2), [7, 8] - assert_equal queue.to_a, [4, 2] + assert_equal 5, queue.pop + assert_equal 6, queue.pop + assert_equal true, queue.push([4, 2]) + assert_equal [7, 8], queue.pop(2) + assert_equal [4, 2], queue.to_a + end + + def test_person + person = Sungemm::Person.new("kurt vonnegut", 89, "caucasian") + assert_equal "Kurt Vonnegut", person.name + assert_equal "Caucasian", person.race + assert_equal 89, person.age + end + + def test_character + thorin = Sungemm::Character.new + thorin.name = "Thorin Oakenshield" + thorin.quote = "Some courage and some wisdom, blended in measure. If more + of us valued food and cheer and song above hoarded gold, it would be a + merrier world" + + stephen = Sungemm::Character.new + stephen.name = "Stephen Dedalus" + + assert_equal "Thorin Oakenshield", thorin.name + assert_equal "Stephen Dedalus", stephen.name + end + + def test_hash + composers = Sungemm::HashWithIndifferentAccess.new + composers[:Janacek] = "Leos Janacek" + composers["Sweelinck"] = "Jan Pieterszoon Sweelinck" + + mathematicians = Sungemm::HashWithIndifferentAccess["Yutaka", "Taniyama", + :Alonzo, "Church"] + + assert_equal "Leos Janacek", composers["Janacek"] + assert_equal "Jan Pieterszoon Sweelinck", composers[:Sweelinck] + assert_equal "Taniyama", mathematicians[:Yutaka] + assert_equal true, (mathematicians["Alonzo"] == mathematicians[:Alonzo]) + end + + def test_key_for_min_value + input = {"k" => 2, "h" => 3, "j" => 1} + assert_equal "j", Sungemm.key_for_min_value(input) + input = {"o" => 0, "z" => -2, "j" => 1} + assert_equal "z", Sungemm.key_for_min_value(input) + input = {} + assert_equal nil, Sungemm.key_for_min_value(input) + end + + def test_point_and_rectangle + p1 = Sungemm::Point.new(0, 0) + p2 = Sungemm::Point.new(3, 4) + assert_equal 12, Sungemm::Rectangle.new(p1, p2).area + assert_equal 12, Sungemm::Rectangle.new(p2, p1).area + assert_equal 10, Sungemm::Rectangle.new(Sungemm::Point.new(13, 5), p2).area end end