summaryrefslogtreecommitdiff
path: root/Tests/LibCrypto
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-11-16 09:17:55 +0000
committerLinus Groh <mail@linusgroh.de>2021-11-16 10:06:53 +0000
commit58c6a156bf3e6dcf0e37a3a73ba6dd4365ce1203 (patch)
tree25a7ee6d30da8c3a5a5f37860d1cb054ab7deafd /Tests/LibCrypto
parent014840eecae67a89b220ec1e33efbb01308d49d3 (diff)
downloadserenity-58c6a156bf3e6dcf0e37a3a73ba6dd4365ce1203.zip
LibCrypto: Fix subtracting two negative `SignedBigInteger`s
Currently, we get the following results -1 - -2 = -1 -2 - -1 = 1 Correct would be: -1 - -2 = 1 -2 - -1 = -1 This was already attempted to be fixed in 7ed8970, but that change was incorrect. This directly translates to LibJS BigInts having the same incorrect behavior - it even was tested.
Diffstat (limited to 'Tests/LibCrypto')
-rw-r--r--Tests/LibCrypto/TestBigInteger.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Tests/LibCrypto/TestBigInteger.cpp b/Tests/LibCrypto/TestBigInteger.cpp
index 36b3098b21..504fb4eab1 100644
--- a/Tests/LibCrypto/TestBigInteger.cpp
+++ b/Tests/LibCrypto/TestBigInteger.cpp
@@ -543,6 +543,15 @@ TEST_CASE(test_signed_subtraction_simple_subtraction_negative_result)
EXPECT_EQ(num1.minus(num2), Crypto::SignedBigInteger { -20 });
}
+TEST_CASE(test_signed_subtraction_both_negative)
+{
+ Crypto::SignedBigInteger num1(-50);
+ Crypto::SignedBigInteger num2(-70);
+
+ EXPECT_EQ(num1.minus(num2), Crypto::SignedBigInteger { 20 });
+ EXPECT_EQ(num2.minus(num1), Crypto::SignedBigInteger { -20 });
+}
+
TEST_CASE(test_signed_subtraction_simple_subtraction_with_borrow)
{
Crypto::SignedBigInteger num1(Crypto::UnsignedBigInteger { UINT32_MAX });