require "test/unit"
require "resize_pictures.rb"


class TestResize < Test::Unit::TestCase
    def test_size_to_rotatable_box
        test_cases = [
        #       w    h     bw   bh   expected
        [   [ 640, 480,   640, 480 ],[640, 480], "same landscape" ],
        [   [ 480, 640,   480, 640 ],[480, 640], "same portrait" ],
        [   [ 480, 640,   640, 480 ],[480, 640], "portrait/landscape" ],
        [   [ 640, 480,   480, 640 ],[640, 480], "landscape/portrait" ],
        [   [1024, 768,   640, 480 ],[640, 480], "big to small - landscape/landscape" ],
        [   [ 768,1024,   480, 640 ],[480, 640], "big to small - portrait/portrait" ],
        [   [ 768,1024,   640, 480 ],[480, 640], "big to small - portrait/landscape" ],
        [   [1024, 768,   480, 640 ],[640, 480], "big to small - landscape/portrait" ],
        [   [ 640, 400,   640, 480 ],[640, 400], "off-height (-) landscape/landscape" ],
        [   [ 610, 480,   640, 480 ],[610, 480], "off-width  (-) landscape/landscape" ],
        [   [ 400, 640,   640, 480 ],[400, 640], "off-width  (-) portrait/landscape" ],
        [   [ 480, 610,   640, 480 ],[480, 610], "off-height (-) portrait/landscape" ],
        [   [ 640, 500,   640, 480 ],[614, 480], "off-height (+) landscape/landscape" ],
        [   [ 700, 480,   640, 480 ],[640, 439], "off-width  (+) landscape/landscape" ],
        [   [ 500, 640,   640, 480 ],[480, 614], "off-width  (+) portrait/landscape" ],
        [   [ 480, 700,   640, 480 ],[439, 640], "off-height (+) portrait/landscape" ],
        ]
        
        test_cases.each{|args, expected, test_name|
            result = size_to_rotatable_box(*args)
            # if expected == result
            #     puts test_name
            # else
            #    puts test_name + ":   expected #{expected.inspect}, got #{result.inspect}"
            # end
            assert_equal expected, result, test_name
        }
    end
    
    def test_size_to_rotatable_box_exception
        test_cases = [
        [   [  0,1,1,1 ], "zero width" ],
        [   [  1,0,1,1 ], "zero height" ],
        [   [  1,1,0,1 ], "zero box_width" ],
        [   [  1,1,1,0 ], "zero box_height" ],
        [   [  0,0,1,1 ], "zero width, height" ],
        [   [  0,0,1,0 ], "zero width, height, box_height" ],
        ]
        
        test_cases.each{|args, err_msg|
            assert_raises ArgumentError do size_to_rotatable_box(*args) end
            
            begin 
                size_to_rotatable_box(*args) 
            rescue ArgumentError=>e
                assert_equal err_msg, e.message
            end
        }
    end
    
end

