test/helper.rb in processing-0.5.29 vs test/helper.rb in processing-0.5.30

- old
+ new

@@ -27,16 +27,28 @@ .first .bitmap .to_a end -def graphics(width = 10, height = 10, &block) - Processing::Graphics.new(width, height).tap do |g| +def graphics(width = 10, height = 10, *args, &block) + Processing::Graphics.new(width, height, *args).tap do |g| g.beginDraw {block.call g, g.getInternal__} if block end end def assert_equal_vector(v1, v2, delta = 0.000001) assert_in_delta v1.x, v2.x, delta assert_in_delta v1.y, v2.y, delta assert_in_delta v1.z, v2.z, delta +end + +def assert_equal_pixels(expected, actual, threshold: 1.0) + exp_pixels = get_pixels expected + act_pixels = get_pixels actual + raise "Number of pixels does not match" if act_pixels.size != exp_pixels.size + + equal_count = exp_pixels.zip(act_pixels).count {|a, b| a == b} + equal_rate = equal_count.to_f / act_pixels.size.to_f + assert equal_rate >= threshold, <<~EOS + The rate of the same pixel #{equal_rate} is below the threshold #{threshold} + EOS end