2011-01-09 05:21:30 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# -*- mode: ruby; coding: utf-8-unix -*-
|
|
|
|
require 'test/unit'
|
|
|
|
require 'opencv'
|
|
|
|
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
|
|
|
|
|
|
|
include OpenCV
|
|
|
|
|
|
|
|
# Tests for OpenCV::CvSize
|
|
|
|
class TestCvSize < OpenCVTestCase
|
|
|
|
class MySize; end
|
|
|
|
|
|
|
|
def test_width
|
|
|
|
size = CvSize.new
|
|
|
|
size.width = 100
|
|
|
|
assert_equal(100, size.width)
|
|
|
|
size.width = 200
|
|
|
|
assert_equal(200, size.width)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_height
|
|
|
|
size = CvSize.new
|
|
|
|
size.height = 100
|
|
|
|
assert_equal(100, size.height)
|
|
|
|
size.height = 200
|
|
|
|
assert_equal(200, size.height)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_compatible
|
|
|
|
assert(!(CvSize.compatible? MySize.new))
|
|
|
|
MySize.class_eval { def width; end }
|
|
|
|
assert(!(CvSize.compatible? MySize.new))
|
|
|
|
MySize.class_eval { def height; end }
|
|
|
|
assert(CvSize.compatible? MySize.new)
|
|
|
|
assert(CvSize.compatible? CvSize.new)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize
|
|
|
|
size = CvSize.new
|
|
|
|
assert_equal(0, size.width)
|
|
|
|
assert_equal(0, size.height)
|
|
|
|
|
|
|
|
size = CvSize.new(10, 20)
|
|
|
|
assert_equal(10, size.width)
|
|
|
|
assert_equal(20, size.height)
|
|
|
|
|
|
|
|
size = CvSize.new(CvSize.new(10, 20))
|
|
|
|
assert_equal(10, size.width)
|
|
|
|
assert_equal(20, size.height)
|
|
|
|
|
|
|
|
assert_raise(ArgumentError) {
|
|
|
|
CvSize.new('string')
|
|
|
|
}
|
|
|
|
assert_raise(ArgumentError) {
|
|
|
|
CvSize.new(1, 2, 3)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_s
|
|
|
|
size = CvSize.new(10, 20)
|
|
|
|
assert_equal('<OpenCV::CvSize:10x20>', size.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_ary
|
|
|
|
a = CvSize.new(10, 20).to_ary
|
|
|
|
assert_equal(10, a[0])
|
|
|
|
assert_equal(20, a[1])
|
implemented to_a to CvCircle32f, CvPoint, CvPoint2D32f, CvPoint3D32f, CvScalar, CvSize, CvSize2D32f, CvTermCriteria, CvTwoPoints, CvVector, and added tests for them
2011-01-09 11:18:11 -05:00
|
|
|
|
|
|
|
# Alias
|
|
|
|
a = CvSize.new(10, 20).to_a
|
|
|
|
assert_equal(10, a[0])
|
|
|
|
assert_equal(20, a[1])
|
2011-01-09 05:21:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|