mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
764524f65b
commit
aa87ea9915
4 changed files with 47 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue