summaryrefslogtreecommitdiff
path: root/test/test_prime.rb
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-13 13:51:49 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-13 13:51:49 +0000
commit7287b852da95b3bee1395fd80752e62b686da294 (patch)
treef22c154e749662d907df5b6fdb98e3208b8528e0 /test/test_prime.rb
parent0fefd1902329f72434e859bd77a7ea5a114c00ff (diff)
* lib/prime.rb (Prime#prime_division): now decomposes
negative integer into a decomposition with element [-1, 1]. * test/test_prime.rb: test for it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_prime.rb')
-rw-r--r--test/test_prime.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/test/test_prime.rb b/test/test_prime.rb
index e7c025a55a..307d53afb3 100644
--- a/test/test_prime.rb
+++ b/test/test_prime.rb
@@ -98,10 +98,15 @@ class TestPrime < Test::Unit::TestCase
def test_prime_division
pd = PRIMES.inject(&:*).prime_division
assert_equal PRIMES.map{|p| [p, 1]}, pd
+
+ pd = (-PRIMES.inject(&:*)).prime_division
+ assert_equal [-1, *PRIMES].map{|p| [p, 1]}, pd
end
def test_from_prime_division
assert_equal PRIMES.inject(&:*), Integer.from_prime_division(PRIMES.map{|p| [p,1]})
+
+ assert_equal -PRIMES.inject(&:*), Integer.from_prime_division([[-1, 1]] + PRIMES.map{|p| [p,1]})
end
def test_prime?