Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (41 sloc) 1.386 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#! /usr/local/bin/ruby -w

require 'RMagick'
require 'test/unit'
require 'test/unit/ui/console/testrunner'


class Pixel_UT < Test::Unit::TestCase

    def setup
        @pixel = Magick::Pixel.from_color('brown')
    end

    def test_hash
        hash = nil
        assert_nothing_raised { hash = @pixel.hash}
        assert_not_nil(hash)
        assert_equal(-761981696, hash)

        p = Magick::Pixel.new
        assert_equal(0, p.hash)

        p = Magick::Pixel.from_color('red')
        assert_equal(-8388608, p.hash)

        # Pixel.hash sacrifices the last bit of the opacity channel
        p = Magick::Pixel.new(0, 0, 0, 72)
        p2 = Magick::Pixel.new(0, 0, 0, 73)
        assert_not_equal(p, p2)
        assert_equal(p.hash, p2.hash)

    end

    def test_eql?
        p = @pixel
        assert(@pixel.eql?(p))
        p = Magick::Pixel.new
        assert(!@pixel.eql?(p))
    end

    def test_fcmp
        red = Magick::Pixel.from_color('red')
        blue = Magick::Pixel.from_color('blue')
        assert_nothing_raised { red.fcmp(red) }
        assert(red.fcmp(red))
        assert(! red.fcmp(blue) )

        assert_nothing_raised { red.fcmp(blue, 10) }
        assert_nothing_raised { red.fcmp(blue, 10, Magick::RGBColorspace) }
        assert_raises(TypeError) { red.fcmp(blue, 'x') }
        assert_raises(TypeError) { red.fcmp(blue, 10, 'x') }
    end

end
Something went wrong with that request. Please try again.