Skip to content
This repository
Newer
Older
100644 121 lines (100 sloc) 5.007 kb
f784d816 »
2006-08-21 New tests
1 #! /usr/local/bin/ruby -w
2
3 require 'RMagick'
4 require 'test/unit'
95bba790 »
2009-01-02 Update to work with new test/unit in 1.9.1
5 require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
f784d816 »
2006-08-21 New tests
6
7
8 class Pixel_UT < Test::Unit::TestCase
9
10 def setup
11 @pixel = Magick::Pixel.from_color('brown')
12 end
13
14 def test_hash
15 hash = nil
16 assert_nothing_raised { hash = @pixel.hash}
17 assert_not_nil(hash)
18 assert_equal(-761981696, hash)
19
20 p = Magick::Pixel.new
21 assert_equal(0, p.hash)
22
23 p = Magick::Pixel.from_color('red')
24 assert_equal(-8388608, p.hash)
25
26 # Pixel.hash sacrifices the last bit of the opacity channel
27 p = Magick::Pixel.new(0, 0, 0, 72)
28 p2 = Magick::Pixel.new(0, 0, 0, 73)
29 assert_not_equal(p, p2)
30 assert_equal(p.hash, p2.hash)
31
32 end
33
34 def test_eql?
35 p = @pixel
36 assert(@pixel.eql?(p))
37 p = Magick::Pixel.new
38 assert(!@pixel.eql?(p))
39 end
40
5dba317a »
2007-01-27 Add test_fcmp method
41 def test_fcmp
7b42cb92 »
2008-03-21 Add from_hsla, to_hsla test
42 red = Magick::Pixel.from_color('red')
43 blue = Magick::Pixel.from_color('blue')
44 assert_nothing_raised { red.fcmp(red) }
45 assert(red.fcmp(red))
46 assert(! red.fcmp(blue) )
47
48 assert_nothing_raised { red.fcmp(blue, 10) }
49 assert_nothing_raised { red.fcmp(blue, 10, Magick::RGBColorspace) }
50 assert_raises(TypeError) { red.fcmp(blue, 'x') }
51 assert_raises(TypeError) { red.fcmp(blue, 10, 'x') }
52 end
fdea5b4a »
2009-12-21 [fix bug 27607] Changed Pixel_from_hsla/Pixel_to_hsla to use the new …
53
7b42cb92 »
2008-03-21 Add from_hsla, to_hsla test
54 def test_from_hsla
55 assert_nothing_raised { Magick::Pixel.from_hsla(127, 50, 50) }
56 assert_nothing_raised { Magick::Pixel.from_hsla(127, 50, 50, 0) }
fdea5b4a »
2009-12-21 [fix bug 27607] Changed Pixel_from_hsla/Pixel_to_hsla to use the new …
57 assert_nothing_raised { Magick::Pixel.from_hsla(127, "50%", 50, 0) }
58 assert_nothing_raised { Magick::Pixel.from_hsla("10%", "50%", 50, 0) }
7b42cb92 »
2008-03-21 Add from_hsla, to_hsla test
59 assert_raise(TypeError) { Magick::Pixel.from_hsla([], 50, 50, 0) }
60 assert_raise(TypeError) { Magick::Pixel.from_hsla(127, [], 50, 0) }
61 assert_raise(TypeError) { Magick::Pixel.from_hsla(127, 50, [], 0) }
62 assert_raise(TypeError) { Magick::Pixel.from_hsla(127, 50, 50, []) }
63 assert_nothing_raised { @pixel.to_hsla }
64
9f93e7eb »
2008-12-26 Fewer to_/from_hsla tests
65 18.times do |h|
7b42cb92 »
2008-03-21 Add from_hsla, to_hsla test
66 25.times do |s|
67 25.times do |l|
68 5.times do |a|
9f93e7eb »
2008-12-26 Fewer to_/from_hsla tests
69 args = [20*h, s+25, l+25, a/5]
7b42cb92 »
2008-03-21 Add from_hsla, to_hsla test
70 px = Magick::Pixel.from_hsla(*args)
71 hsla = px.to_hsla()
b5c34a86 »
2008-03-22 Reduce excessive number of from_hsla/to_hsla tests.
72 #puts "[#{args.join(', ')}] = [#{hsla.join(', ')}]"
9f93e7eb »
2008-12-26 Fewer to_/from_hsla tests
73 # Handle cases where the result is very near 360
74 #hsla[0] = ((hsla[0] + 0.005) % 360.0) - 0.005
75 #hsla[1] = ((hsla[1] + 0.005) % 360.0) - 0.005
76 #hsla[2] = ((hsla[2] + 0.005) % 360.0) - 0.005
fdea5b4a »
2009-12-21 [fix bug 27607] Changed Pixel_from_hsla/Pixel_to_hsla to use the new …
77 assert_in_delta(args[0], hsla[0], 0.25, "expected #{args.inspect} got #{hsla.inspect}")
78 assert_in_delta(args[1], hsla[1], 0.25, "expected #{args.inspect} got #{hsla.inspect}")
79 assert_in_delta(args[2], hsla[2], 0.25, "expected #{args.inspect} got #{hsla.inspect}")
9f93e7eb »
2008-12-26 Fewer to_/from_hsla tests
80 assert_in_delta(args[3], hsla[3], 0.005, "expected #{args.inspect} got #{hsla.inspect}")
7b42cb92 »
2008-03-21 Add from_hsla, to_hsla test
81 end
82 end
83 end
84 end
fdea5b4a »
2009-12-21 [fix bug 27607] Changed Pixel_from_hsla/Pixel_to_hsla to use the new …
85
86 # test percentages
87 args = ["20%","20%","20%","20%"]
88 args2 = [360.0/5,255.0/5,255.0/5,1.0/5]
89 px = Magick::Pixel.from_hsla(*args)
90 hsla = px.to_hsla
91 px2 = Magick::Pixel.from_hsla(*args2)
92 hsla2 = px2.to_hsla
93
94 assert_in_delta(hsla[0], hsla2[0], 0.25, "#{hsla.inspect} != #{hsla2.inspect} with args: #{args.inspect} and #{args2.inspect}")
95 assert_in_delta(hsla[1], hsla2[1], 0.25, "#{hsla.inspect} != #{hsla2.inspect} with args: #{args.inspect} and #{args2.inspect}")
96 assert_in_delta(hsla[2], hsla2[2], 0.25, "#{hsla.inspect} != #{hsla2.inspect} with args: #{args.inspect} and #{args2.inspect}")
97 assert_in_delta(hsla[3], hsla2[3], 0.005, "#{hsla.inspect} != #{hsla2.inspect} with args: #{args.inspect} and #{args2.inspect}")
7b42cb92 »
2008-03-21 Add from_hsla, to_hsla test
98 end
fdea5b4a »
2009-12-21 [fix bug 27607] Changed Pixel_from_hsla/Pixel_to_hsla to use the new …
99
7b42cb92 »
2008-03-21 Add from_hsla, to_hsla test
100 def test_to_color
101 assert_nothing_raised { @pixel.to_color(Magick::AllCompliance) }
102 assert_nothing_raised { @pixel.to_color(Magick::SVGCompliance) }
103 assert_nothing_raised { @pixel.to_color(Magick::X11Compliance) }
104 assert_nothing_raised { @pixel.to_color(Magick::XPMCompliance) }
105 assert_nothing_raised { @pixel.to_color(Magick::AllCompliance, true) }
106 assert_nothing_raised { @pixel.to_color(Magick::AllCompliance, false) }
107 assert_nothing_raised { @pixel.to_color(Magick::AllCompliance, false, 8) }
108 assert_nothing_raised { @pixel.to_color(Magick::AllCompliance, false, 16) }
a2873b32 »
2008-06-21 Test "hex-format" to_color
109 # test "hex" format
110 assert_nothing_raised { @pixel.to_color(Magick::AllCompliance, false, 8, true) }
111 assert_nothing_raised { @pixel.to_color(Magick::AllCompliance, false, 16, true) }
112
113 assert_equal("#A52A2A", @pixel.to_color(Magick::AllCompliance, false, 8, true))
114 assert_equal("#A5A52A2A2A2A", @pixel.to_color(Magick::AllCompliance, false, 16, true))
115
7b42cb92 »
2008-03-21 Add from_hsla, to_hsla test
116 assert_raise(ArgumentError) { @pixel.to_color(Magick::AllCompliance, false, 32) }
117 assert_raise(TypeError) { @pixel.to_color(1) }
5dba317a »
2007-01-27 Add test_fcmp method
118 end
119
f784d816 »
2006-08-21 New tests
120 end
Something went wrong with that request. Please try again.