diff options
author | Rick Mark <rick.mark@coinbase.com> | 2021-04-01 12:29:21 -0700 |
---|---|---|
committer | Rick Mark <rick.mark@coinbase.com> | 2021-04-01 12:29:21 -0700 |
commit | 0321b1e945f89d08ab3632fe8bb3b7726086e9bb (patch) | |
tree | d3b22086f46eb438e1893ea28b3269dabf4ad902 /test | |
parent | 69f89d4ae967f87e355dbbe05fbc039a083b6792 (diff) | |
download | ruby-openssl-0321b1e945f89d08ab3632fe8bb3b7726086e9bb.tar.gz |
BN.abs and BN uplus
Adds standard math abs fuction and revises uplus to return a duplicated object due to BN mutability
Diffstat (limited to 'test')
-rw-r--r-- | test/openssl/test_bn.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/openssl/test_bn.rb b/test/openssl/test_bn.rb index 547d334c..1ed4bbee 100644 --- a/test/openssl/test_bn.rb +++ b/test/openssl/test_bn.rb @@ -131,6 +131,27 @@ class OpenSSL::TestBN < OpenSSL::TestCase assert_equal(-999, +@e2) assert_equal(-999, -@e1) assert_equal(+999, -@e2) + + # These methods create new BN instances due to BN mutability + # Ensure that the instance isn't the same + e1_plus = +@e1 + e1_minus = -@e1 + assert_equal(false, @e1.equal?(e1_plus)) + assert_equal(true, @e1 == e1_plus) + assert_equal(false, @e1.equal?(e1_minus)) + end + + def test_abs + assert_equal(@e1, @e2.abs) + assert_equal(@e3, @e4.abs) + assert_not_equal(@e2, @e2.abs) + assert_not_equal(@e4, @e4.abs) + assert_equal(false, @e2.abs.negative?) + assert_equal(false, @e4.abs.negative?) + assert_equal(true, (-@e1.abs).negative?) + assert_equal(true, (-@e2.abs).negative?) + assert_equal(true, (-@e3.abs).negative?) + assert_equal(true, (-@e4.abs).negative?) end def test_mod |