gmath3D 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_util.rb CHANGED
@@ -1,57 +1,88 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- require 'helper'
3
-
4
- include GMath3D
5
-
6
- MiniTest::Unit.autorun
7
-
8
- class UtilTestCase < MiniTest::Unit::TestCase
9
- def test_check_arg_type
10
- integerInstance = 1
11
- floatInstance = 3.1415
12
- stringInstance = 'string'
13
-
14
- # no exception raise
15
- Util3D.check_arg_type(Integer, integerInstance)
16
- Util3D.check_arg_type(Float, floatInstance)
17
- Util3D.check_arg_type(String, stringInstance)
18
-
19
- # exception raise
20
- assert_raises ArgumentError do
21
- Util3D.check_arg_type(Integer, floatInstance)
22
- end
23
- assert_raises ArgumentError do
24
- Util3D.check_arg_type(Integer, stringInstance)
25
- end
26
- assert_raises ArgumentError do
27
- Util3D.check_arg_type(Float, integerInstance)
28
- end
29
- assert_raises ArgumentError do
30
- Util3D.check_arg_type(Float, stringInstance)
31
- end
32
- assert_raises ArgumentError do
33
- Util3D.check_arg_type(String, integerInstance)
34
- end
35
- assert_raises ArgumentError do
36
- Util3D.check_arg_type(String, floatInstance)
37
- end
38
- end
39
-
40
- def test_array_methods
41
- point_ary = Array.new([Vector3.new(2,4,3),Vector3.new(-2,2.5,8),Vector3.new(9,0,-3)])
42
- assert_equal( Vector3.new(9, 6.5, 8), point_ary.sum)
43
- assert_equal( Vector3.new(3, 6.5/3, 8/3.0), point_ary.avg)
44
- end
45
-
46
- def test_matrix_equation_solving
47
- mat = Matrix[[1,2,3],[4,5,6],[7,8,-9]]
48
- vec = Matrix.column_vector([26,62,8])
49
- inv_mat = mat.inverse
50
- ans = inv_mat*vec
51
- assert_equal(3, ans.row_size)
52
- assert_equal(1, ans.column_size)
53
- assert_equal(3, ans[0,0])
54
- assert_equal(4, ans[1,0])
55
- assert_equal(5, ans[2,0])
56
- end
57
- end
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ include GMath3D
5
+
6
+ MiniTest::Unit.autorun
7
+
8
+ class UtilTestCase < MiniTest::Unit::TestCase
9
+ def test_check_arg_type
10
+ integerInstance = 1
11
+ floatInstance = 3.1415
12
+ stringInstance = 'string'
13
+
14
+ # no exception raise
15
+ Util3D.check_arg_type(Integer, integerInstance)
16
+ Util3D.check_arg_type(Float, floatInstance)
17
+ Util3D.check_arg_type(String, stringInstance)
18
+
19
+ # exception raise
20
+ assert_raises ArgumentError do
21
+ Util3D.check_arg_type(Integer, floatInstance)
22
+ end
23
+ assert_raises ArgumentError do
24
+ Util3D.check_arg_type(Integer, stringInstance)
25
+ end
26
+ assert_raises ArgumentError do
27
+ Util3D.check_arg_type(Float, integerInstance)
28
+ end
29
+ assert_raises ArgumentError do
30
+ Util3D.check_arg_type(Float, stringInstance)
31
+ end
32
+ assert_raises ArgumentError do
33
+ Util3D.check_arg_type(String, integerInstance)
34
+ end
35
+ assert_raises ArgumentError do
36
+ Util3D.check_arg_type(String, floatInstance)
37
+ end
38
+
39
+ # not raise exception
40
+ arg = {:geom => Vector3.new(), :color => [1,0,0,1]}
41
+ Util3D.check_key_arg(arg, :geom)
42
+ assert_raises ArgumentError do
43
+ Util3D.check_key_arg(arg, :dummy)
44
+ end
45
+
46
+ # test nullable
47
+ Util3D.check_arg_type(String, nil, true)
48
+ assert_raises ArgumentError do
49
+ Util3D.check_arg_type(String, nil, false)
50
+ end
51
+ assert_raises ArgumentError do
52
+ Util3D.check_arg_type(String, nil)
53
+ end
54
+ assert_raises ArgumentError do
55
+ Util3D.check_arg_type(String, ["hoge", nil], false, true)
56
+ end
57
+
58
+ #test array check
59
+ Util3D.check_arg_type(String, "hoge")
60
+ Util3D.check_arg_type(String, "hoge", false, true)
61
+ Util3D.check_arg_type(String, ["hoge", "piyo"], false, true)
62
+ Util3D.check_arg_type(String, ["hoge", nil], true, true)
63
+ assert_raises ArgumentError do
64
+ Util3D.check_arg_type(String, ["hoge", "piyo"], false, false)
65
+ end
66
+ assert_raises ArgumentError do
67
+ Util3D.check_arg_type(String, ["hoge", "piyo"], false)
68
+ end
69
+ end
70
+
71
+ def test_array_methods
72
+ point_ary = Array.new([Vector3.new(2,4,3),Vector3.new(-2,2.5,8),Vector3.new(9,0,-3)])
73
+ assert_equal( Vector3.new(9, 6.5, 8), point_ary.sum)
74
+ assert_equal( Vector3.new(3, 6.5/3, 8/3.0), point_ary.avg)
75
+ end
76
+
77
+ def test_matrix_equation_solving
78
+ mat = Matrix[[1,2,3],[4,5,6],[7,8,-9]]
79
+ vec = Matrix.column_vector([26,62,8])
80
+ inv_mat = mat.inverse
81
+ ans = inv_mat*vec
82
+ assert_equal(3, ans.row_size)
83
+ assert_equal(1, ans.column_size)
84
+ assert_equal(3, ans[0,0])
85
+ assert_equal(4, ans[1,0])
86
+ assert_equal(5, ans[2,0])
87
+ end
88
+ end