From 6e47478f54274f717158968958d4aaea4a809c58 Mon Sep 17 00:00:00 2001 From: ser1zw Date: Fri, 31 Dec 2010 17:50:07 +0900 Subject: [PATCH] added some tests of CvColor --- test/test_cvscalar.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/test_cvscalar.rb b/test/test_cvscalar.rb index 08a0418..8b70412 100755 --- a/test/test_cvscalar.rb +++ b/test/test_cvscalar.rb @@ -8,6 +8,13 @@ include OpenCV # Tests for OpenCV::CvScalar class TestCvScalar < TestOpenCV + def is_same_elems(a, b, delta = 0.01) + 4.times { |i| + return false unless (a[i].to_f - b[i].to_f).abs <= delta.to_f + } + true + end + def test_aref s = CvScalar.new 4.times { |i| assert_in_delta(0, s[i], 0.01) } @@ -53,5 +60,24 @@ class TestCvScalar < TestOpenCV assert_in_delta(x, b[i], 0.01) } end + + def test_cvcolor + assert(is_same_elems(CvColor::Black, CvScalar.new(0x0, 0x0, 0x0, 0))) + assert(is_same_elems(CvColor::Silver, CvScalar.new(0x0c, 0x0c, 0x0c, 0))) + assert(is_same_elems(CvColor::Gray, CvScalar.new(0x80, 0x80, 0x80, 0))) + assert(is_same_elems(CvColor::White, CvScalar.new(0xff, 0xff, 0xff, 0))) + assert(is_same_elems(CvColor::Maroon, CvScalar.new(0x0, 0x0, 0x80, 0))) + assert(is_same_elems(CvColor::Red, CvScalar.new(0x0, 0x0, 0xff, 0))) + assert(is_same_elems(CvColor::Purple, CvScalar.new(0x80, 0x0, 0x80, 0))) + assert(is_same_elems(CvColor::Fuchsia, CvScalar.new(0xff, 0x0, 0xff, 0))) + assert(is_same_elems(CvColor::Green, CvScalar.new(0x0, 0x80, 0x0, 0))) + assert(is_same_elems(CvColor::Lime, CvScalar.new(0x0, 0xff, 0x0, 0))) + assert(is_same_elems(CvColor::Olive, CvScalar.new(0x0, 0x80, 0x80, 0))) + assert(is_same_elems(CvColor::Yellow, CvScalar.new(0x0, 0xff, 0xff, 0))) + assert(is_same_elems(CvColor::Navy, CvScalar.new(0x80, 0x0, 0x0, 0))) + assert(is_same_elems(CvColor::Blue, CvScalar.new(0xff, 0x0, 0x0, 0))) + assert(is_same_elems(CvColor::Teal, CvScalar.new(0x80, 0x80, 0x0, 0))) + assert(is_same_elems(CvColor::Aqua, CvScalar.new(0xff, 0xff, 0x0, 0))) + end end