mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
fix Rect and add tests
This commit is contained in:
parent
cb14a132b7
commit
f95514c0f3
2 changed files with 97 additions and 6 deletions
|
@ -47,7 +47,9 @@ namespace rubyopencv {
|
||||||
/*
|
/*
|
||||||
* Create a rectangle
|
* Create a rectangle
|
||||||
*
|
*
|
||||||
* @overload new(x = 0, y = 0, width = 0, height = 0)
|
* @overload new()
|
||||||
|
* @return [Rect] new rectangle
|
||||||
|
* @overload new(x, y, width, height)
|
||||||
* @param x [Integer] x coordinate
|
* @param x [Integer] x coordinate
|
||||||
* @param y [Integer] y coordinate
|
* @param y [Integer] y coordinate
|
||||||
* @param width [Integer] Width
|
* @param width [Integer] Width
|
||||||
|
@ -73,6 +75,9 @@ namespace rubyopencv {
|
||||||
selfptr->width = NUM2INT(values[2]);
|
selfptr->width = NUM2INT(values[2]);
|
||||||
selfptr->height = NUM2INT(values[3]);
|
selfptr->height = NUM2INT(values[3]);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 4)", argc);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
86
test/test_rect.rb
Executable file
86
test/test_rect.rb
Executable file
|
@ -0,0 +1,86 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
# -*- mode: ruby; coding: utf-8 -*-
|
||||||
|
require 'test/unit'
|
||||||
|
require 'opencv'
|
||||||
|
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
||||||
|
|
||||||
|
include OpenCV
|
||||||
|
|
||||||
|
# Tests for OpenCV::Rect
|
||||||
|
class TestRect < OpenCVTestCase
|
||||||
|
def test_x
|
||||||
|
rect = Rect.new
|
||||||
|
rect.x = 100
|
||||||
|
assert_equal(100, rect.x)
|
||||||
|
rect.x = 200
|
||||||
|
assert_equal(200, rect.x)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_y
|
||||||
|
rect = Rect.new
|
||||||
|
rect.y = 100
|
||||||
|
assert_equal(100, rect.y)
|
||||||
|
rect.y = 200
|
||||||
|
assert_equal(200, rect.y)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_width
|
||||||
|
rect = Rect.new
|
||||||
|
rect.width = 100
|
||||||
|
assert_equal(100, rect.width)
|
||||||
|
rect.width = 200
|
||||||
|
assert_equal(200, rect.width)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_height
|
||||||
|
rect = Rect.new
|
||||||
|
rect.height = 100
|
||||||
|
assert_equal(100, rect.height)
|
||||||
|
rect.height = 200
|
||||||
|
assert_equal(200, rect.height)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_initialize
|
||||||
|
rect = Rect.new
|
||||||
|
assert_equal(0, rect.x)
|
||||||
|
assert_equal(0, rect.y)
|
||||||
|
assert_equal(0, rect.width)
|
||||||
|
assert_equal(0, rect.height)
|
||||||
|
|
||||||
|
rect = Rect.new(10, 20, 30, 40)
|
||||||
|
assert_equal(10, rect.x)
|
||||||
|
assert_equal(20, rect.y)
|
||||||
|
assert_equal(30, rect.width)
|
||||||
|
assert_equal(40, rect.height)
|
||||||
|
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
Rect.new(DUMMY_OBJ, 1, 1, 1)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
Rect.new(1, DUMMY_OBJ, 1, 1)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
Rect.new(1, 1, DUMMY_OBJ, 1)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
Rect.new(1, 1, 1, DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
assert_raise(ArgumentError) {
|
||||||
|
Rect.new(1)
|
||||||
|
}
|
||||||
|
assert_raise(ArgumentError) {
|
||||||
|
Rect.new(1, 2)
|
||||||
|
}
|
||||||
|
assert_raise(ArgumentError) {
|
||||||
|
Rect.new(1, 2, 3)
|
||||||
|
}
|
||||||
|
assert_raise(ArgumentError) {
|
||||||
|
Rect.new(1, 2, 3, 4, 5)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_s
|
||||||
|
rect = Rect.new(1, 2, 3, 4)
|
||||||
|
assert_equal('#<OpenCV::Rect:[3 x 4 from (1, 2)]>', rect.to_s)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue