|
| 1 | +//------------------------------------------------------------------------------------------------------- |
| 2 | +// Copyright (C) Microsoft. All rights reserved. |
| 3 | +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. |
| 4 | +//------------------------------------------------------------------------------------------------------- |
| 5 | + |
| 6 | +#include "stdafx.h" |
| 7 | +#pragma warning(disable:26434) // Function definition hides non-virtual function in base class |
| 8 | +#pragma warning(disable:26439) // Implicit noexcept |
| 9 | +#pragma warning(disable:26451) // Arithmetic overflow |
| 10 | +#pragma warning(disable:26495) // Uninitialized member variable |
| 11 | +#include "catch.hpp" |
| 12 | + |
| 13 | +#pragma warning(disable:4100) // unreferenced formal parameter |
| 14 | +#pragma warning(disable:6387) // suppressing preFAST which raises warning for passing null to the JsRT APIs |
| 15 | +#pragma warning(disable:6262) // CATCH is using stack variables to report errors, suppressing the preFAST warning. |
| 16 | + |
| 17 | +namespace JavascriptBigIntTests |
| 18 | +{ |
| 19 | + void Test_AddDigit(digit_t digit1, digit_t digit2, digit_t * carry, digit_t expectedResult, digit_t expectedCarry) |
| 20 | + { |
| 21 | + REQUIRE(g_testHooksLoaded); |
| 22 | + |
| 23 | + digit_t res = g_testHooks.pfAddDigit(digit1, digit2, carry); |
| 24 | + |
| 25 | + //test to check that the result from call to AddDigit is the expected value |
| 26 | + REQUIRE(res == expectedResult); |
| 27 | + REQUIRE(expectedCarry == *carry); |
| 28 | + } |
| 29 | + |
| 30 | + void Test_SubDigit(digit_t digit1, digit_t digit2, digit_t * borrow, digit_t expectedResult, digit_t expectedBorrow) |
| 31 | + { |
| 32 | + REQUIRE(g_testHooksLoaded); |
| 33 | + |
| 34 | + digit_t res = g_testHooks.pfSubDigit(digit1, digit2, borrow); |
| 35 | + |
| 36 | + //test to check that the result from call to SubtractDigit is the expected value |
| 37 | + REQUIRE(res == expectedResult); |
| 38 | + REQUIRE(*borrow == expectedBorrow); |
| 39 | + } |
| 40 | + |
| 41 | + void Test_MulDigit(digit_t digit1, digit_t digit2, digit_t * high, digit_t expectedResult, digit_t expectedHigh) |
| 42 | + { |
| 43 | + REQUIRE(g_testHooksLoaded); |
| 44 | + |
| 45 | + digit_t res = g_testHooks.pfMulDigit(digit1, digit2, high); |
| 46 | + |
| 47 | + //test to check that the result from call to SubtractDigit is the expected value |
| 48 | + REQUIRE(res == expectedResult); |
| 49 | + REQUIRE(*high == expectedHigh); |
| 50 | + } |
| 51 | + |
| 52 | + TEST_CASE("AddDigit", "[JavascriptBigIntTests]") |
| 53 | + { |
| 54 | + digit_t carry = 0; |
| 55 | + Test_AddDigit(1, 2, &carry, 3, 0); |
| 56 | + |
| 57 | + digit_t d1 = UINTPTR_MAX; |
| 58 | + digit_t d2 = UINTPTR_MAX; |
| 59 | + carry = 0; |
| 60 | + Test_AddDigit(d1, d2, &carry, UINTPTR_MAX-1, 1); |
| 61 | + } |
| 62 | + |
| 63 | + TEST_CASE("SubDigit", "[JavascriptBigIntTests]") |
| 64 | + { |
| 65 | + digit_t borrow = 0; |
| 66 | + Test_SubDigit(3, 2, &borrow, 1, 0); |
| 67 | + |
| 68 | + digit_t d1 = 0; |
| 69 | + digit_t d2 = 1; |
| 70 | + borrow = 0; |
| 71 | + Test_SubDigit(d1, d2, &borrow, UINTPTR_MAX, 1); |
| 72 | + } |
| 73 | + |
| 74 | + TEST_CASE("MulDigit", "[JavascriptBigIntTests]") |
| 75 | + { |
| 76 | + digit_t high = 0; |
| 77 | + Test_MulDigit(3, 2, &high, 6, 0); |
| 78 | + |
| 79 | + digit_t d1 = UINTPTR_MAX; |
| 80 | + digit_t d2 = 2; |
| 81 | + high = 0; |
| 82 | + Test_MulDigit(d1, d2, &high, UINTPTR_MAX-1, 1); |
| 83 | + } |
| 84 | +} |
0 commit comments