diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-09-03 05:49:06 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-09-03 05:49:06 +0000 |
commit | 7c2230bd8c8a16a976091f983737d94ce52959d1 (patch) | |
tree | 4514272cb7d8e21b44593c0b3dd7c8ea8146ca18 /test/matrix | |
parent | a4ce3ab4fd5982af49662320839f8ec109d63881 (diff) | |
download | ruby-7c2230bd8c8a16a976091f983737d94ce52959d1.tar.gz |
matrix.rb: complex vector
* lib/matrix.rb (Vector#magnitude): accumulate squares of absolute
values to fix for complex vector. [ruby-dev:46100] [Bug #6966]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/matrix')
-rw-r--r-- | test/matrix/test_vector.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/matrix/test_vector.rb b/test/matrix/test_vector.rb index 582509fd20..18660df574 100644 --- a/test/matrix/test_vector.rb +++ b/test/matrix/test_vector.rb @@ -131,4 +131,19 @@ class TestVector < Test::Unit::TestCase assert_equal("Vector[1, 2, 3]", @v1.inspect) end + def test_magnitude + assert_in_epsilon(3.7416573867739413, @v1.norm) + assert_in_epsilon(3.7416573867739413, @v4.norm) + end + + def test_complex_magnitude + bug6966 = '[ruby-dev:46100]' + v = Vector[Complex(0,1), 0] + assert_equal(1.0, v.norm, bug6966) + end + + def test_rational_magnitude + v = Vector[Rational(1,2), 0] + assert_equal(0.5, v.norm) + end end |