diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-29 02:43:52 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-29 02:43:52 +0000 |
commit | aa87ea991570acf8d0c55ce116999ac170c915c2 (patch) | |
tree | 06b524401be188e3d09994db3cf7d0d78bea104a /test | |
parent | 764524f65b1b27a0670c81e3605a9ac8e3385040 (diff) | |
download | ruby-aa87ea991570acf8d0c55ce116999ac170c915c2.tar.gz |
* lib/matrix.rb: Generalize Vector#cross_product to arbitrary dimensions
based on a patch by gogo tanaka [#10074]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/matrix/test_vector.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/test/matrix/test_vector.rb b/test/matrix/test_vector.rb index 4e2bca6ef6..a063d2ca12 100644 --- a/test/matrix/test_vector.rb +++ b/test/matrix/test_vector.rb @@ -169,7 +169,17 @@ class TestVector < Test::Unit::TestCase def test_cross_product v = Vector[1, 0, 0].cross_product Vector[0, 1, 0] assert_equal(Vector[0, 0, 1], v) - v = Vector[1, 0, 0].cross Vector[0, 1, 0] - assert_equal(Vector[0, 0, 1], v) + v2 = Vector[1, 2].cross_product + assert_equal(Vector[-2, 1], v2) + v3 = Vector[3, 5, 2, 1].cross(Vector[4, 3, 1, 8], Vector[2, 9, 4, 3]) + assert_equal(Vector[16, -65, 139, -1], v3) + assert_equal Vector[0, 0, 0, 1], + Vector[1, 0, 0, 0].cross(Vector[0, 1, 0, 0], Vector[0, 0, 1, 0]) + assert_equal Vector[0, 0, 0, 0, 1], + Vector[1, 0, 0, 0, 0].cross(Vector[0, 1, 0, 0, 0], Vector[0, 0, 1, 0, 0], Vector[0, 0, 0, 1, 0]) + assert_raise(Vector::ErrDimensionMismatch) { Vector[1, 2, 3].cross_product(Vector[1, 4]) } + assert_raise(TypeError) { Vector[1, 2, 3].cross_product(42) } + assert_raise(ArgumentError) { Vector[1, 2].cross_product(Vector[2, -1]) } + assert_raise(Vector::ErrOperationNotDefined) { Vector[1].cross_product } end end |