require "test_helper" class SungemmTest < MiniTest::Test def test_stack stack = Sungemm::Stack.new([5, 6, 7, 8]) 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 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