diff --git a/sources/Data/Database/BigInt.uc b/sources/BaseRealm/API/Math/BigInt.uc similarity index 74% rename from sources/Data/Database/BigInt.uc rename to sources/BaseRealm/API/Math/BigInt.uc index 9bf2d9f..e9cf51e 100644 --- a/sources/Data/Database/BigInt.uc +++ b/sources/BaseRealm/API/Math/BigInt.uc @@ -41,10 +41,13 @@ var private bool negative; // Valid `BigInt` should not have this array empty. var private array digits; +private const ALMOST_MAX_INT = 147483647; +private const DIGITS_IN_MAX_INT = 10; + protected function Constructor() { // Init with zero - digits[0] = 0; + SetZero(); } protected function Finalizer() @@ -53,26 +56,32 @@ protected function Finalizer() digits.length = 0; } +// ??? +private function BigInt SetZero() +{ + negative = false; + digits.length = 1; + digits[0] = 0; + return self; +} + // Minimal `int` value `-2,147,483,648` is slightly a pain to handle, so just // use this pre-made constructor for it -private static function BigInt CreateMinimalNegative() +private function BigInt SetMinimalNegative() { - local array newDigits; - local BigInt result; - newDigits[0] = 8; - newDigits[1] = 4; - newDigits[2] = 6; - newDigits[3] = 3; - newDigits[4] = 8; - newDigits[5] = 4; - newDigits[6] = 7; - newDigits[7] = 4; - newDigits[8] = 1; - newDigits[9] = 2; - result = BigInt(__().memory.Allocate(class'BigInt')); - result.digits = newDigits; - result.negative = true; - return result; + negative = true; + digits.length = 10; + digits[0] = 8; + digits[1] = 4; + digits[2] = 6; + digits[3] = 3; + digits[4] = 8; + digits[5] = 4; + digits[6] = 7; + digits[7] = 4; + digits[8] = 1; + digits[9] = 2; + return self; } // Removes unnecessary zeroes from leading digit positions `digits`. @@ -92,79 +101,71 @@ private final function TrimLeadingZeroes() zeroesToRemove += 1; } // `digits` must not be empty, enforce `0` value in that case - if (zeroesToRemove >= digits.length) - { - digits.length = 1; - digits[0] = 0; - negative = false; + if (zeroesToRemove >= digits.length) { + SetZero(); } else { digits.length = digits.length - zeroesToRemove; } } -public final static function BigInt FromInt(int value) +public final function BigInt SetInt(int value) { - local bool valueIsNegative; - local array newDigits; - local BigInt result; local MathAPI.IntegerDivisionResult divisionResult; + negative = false; + digits.length = 0; if (value < 0) { // Treat special case of minimal `int` value `-2,147,483,648` that // won't fit into positive `int` as special and use pre-made // specialized constructor `CreateMinimalNegative()` if (value < -MaxInt) { - return CreateMinimalNegative(); + return SetMinimalNegative(); } else { - valueIsNegative = true; + negative = true; value *= -1; } } if (value == 0) { - newDigits[0] = 0; + digits[0] = 0; } else { while (value > 0) { divisionResult = __().math.IntegerDivision(value, 10); - value = divisionResult.quotient; - newDigits[newDigits.length] = divisionResult.remainder; + value = divisionResult.quotient; + digits[digits.length] = divisionResult.remainder; } } - result = BigInt(__().memory.Allocate(class'BigInt')); - result.digits = newDigits; - result.negative = valueIsNegative; - result.TrimLeadingZeroes(); - return result; + TrimLeadingZeroes(); + return self; } -public final static function BigInt FromDecimal(BaseText value) +public final function BigInt Set(BaseText value) { local int i; - local bool valueIsNegative; local byte nextDigit; - local array newDigits; local Parser parser; - local BigInt result; local Basetext.Character nextCharacter; if (value == none) { return none; } parser = value.Parse(); - if (parser.Match(P("-")).Ok()) - { - valueIsNegative = true; - parser.Confirm(); - } + negative = parser.Match(P("-")).Ok(); + parser.Confirm(); parser.R(); - newDigits.length = parser.GetRemainingLength(); - i = newDigits.length - 1; + digits.length = parser.GetRemainingLength(); + /*if (digits.length <= 0) + { + parser.FreeSelf(); + return SetZero(); + }*/ + i = digits.length - 1; while (!parser.HasFinished()) { // This should not happen, but just in case @@ -173,26 +174,22 @@ public final static function BigInt FromDecimal(BaseText value) } parser.MCharacter(nextCharacter); nextDigit = Clamp(__().text.CharacterToInt(nextCharacter), 0, 9); - newDigits[i] = nextDigit; + digits[i] = nextDigit; i -= 1; } - result = BigInt(__().memory.Allocate(class'BigInt')); - result.digits = newDigits; - result.negative = valueIsNegative; parser.FreeSelf(); - result.TrimLeadingZeroes(); - return result; + TrimLeadingZeroes(); + return self; } -public final static function BigInt FromDecimal_S(string value) +public final function BigInt Set_S(string value) { - local MutableText wrapper; - local BigInt result; + local MutableText wrapper; wrapper = __().text.FromStringM(value); - result = FromDecimal(wrapper); + Set(wrapper); wrapper.FreeSelf(); - return result; + return self; } public function BigIntCompareResult _compareModulus(BigInt other) @@ -284,9 +281,7 @@ private function _sub(BigInt other) resultForModulus = _compareModulus(other); if (resultForModulus == BICR_Equal) { - negative = false; - digits.length = 1; - digits[0] = 0; + SetZero(); return; } if (resultForModulus == BICR_Less) @@ -334,23 +329,72 @@ public function BigInt AddInt(int other) { local BigInt otherObject; - otherObject = FromInt(other); + otherObject = _.math.ToBigInt(other); Add(otherObject); _.memory.Free(otherObject); return self; } -/*public function BigInt Multiply(BigInt other); -public function BigInt MultiplyInt(int other); +public function BigInt Subtract(BigInt other) +{ + if (negative != other.negative) { + _add(other); + } + else { + _sub(other); + } + return self; +} + +public function BigInt SubtractInt(int other) +{ + local BigInt otherObject; -public function bool IsNegative(); -public function (int other); + otherObject = _.math.ToBigInt(other); + Add(otherObject); + _.memory.Free(otherObject); + return self; +} -public function int ToInt(); +public function bool IsNegative() +{ + return negative; +} -public function Text ToText(); +public function int ToInt() +{ + local int i; + local int accumulator; + local int mostSignificantDigit; -public function Text ToText_M();*/ + if (digits.lenght <= 0) { + return 0; + } + if (digits.lenght > DIGITS_IN_MAX_INT) + { + if (negative) { + return (-MaxInt - 1); + } + else { + return MaxInt; + } + } + mostSignificantDigit = -1; + if (digits.lenght == DIGITS_IN_MAX_INT) + { + mostSignificantDigit = digits[digits.length - 1]; + digits[i] = DIGITS_IN_MAX_INT - 1; + } + // At most `DIGITS_IN_MAX_INT - 1` iterations + for (i = 0; i < digits.length; i += 1) + {//ALMOST_MAX_INT + accumulator *= 10; + accumulator += digits[i]; + } + if (mostSignificantDigit < 0) { + return accumulator; + } +} public function Text ToText() { diff --git a/sources/BaseRealm/API/Math/MathAPI.uc b/sources/BaseRealm/API/Math/MathAPI.uc index bc948b7..8b004f1 100644 --- a/sources/BaseRealm/API/Math/MathAPI.uc +++ b/sources/BaseRealm/API/Math/MathAPI.uc @@ -31,6 +31,30 @@ struct IntegerDivisionResult var int remainder; }; +public function BigInt ToBigInt(int value) +{ + local BigInt result; + + result = BigInt(_.memory.Allocate(class'BigInt')); + return result.SetInt(value); +} + +public function BigInt MakeBigInt(Text value) +{ + local BigInt result; + + result = BigInt(_.memory.Allocate(class'BigInt')); + return result.Set(value); +} + +public function BigInt MakeBigInt_S(string value) +{ + local BigInt result; + + result = BigInt(_.memory.Allocate(class'BigInt')); + return result.Set_S(value); +} + /** * Computes remainder of the integer division of `number` by `divisor`. * diff --git a/sources/BaseRealm/API/Math/Tests/TEST_BigInt.uc b/sources/BaseRealm/API/Math/Tests/TEST_BigInt.uc new file mode 100644 index 0000000..84b03f9 --- /dev/null +++ b/sources/BaseRealm/API/Math/Tests/TEST_BigInt.uc @@ -0,0 +1,246 @@ +/** + * Set of tests for `BigInt` class. + * Copyright 2022 Anton Tarasenko + *------------------------------------------------------------------------------ + * This file is part of Acedia. + * + * Acedia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License, or + * (at your option) any later version. + * + * Acedia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Acedia. If not, see . + */ +class TEST_BigInt extends TestCase + abstract; + +protected static function TESTS() +{ + // Here we use `ToString()` method to check `BigInt` creation, + // therefore also testing it + Test_Creating(); + // So here we nee to test `ToText()` methods separately + Test_ToText(); + Context("Testing basic arithmetic operations on `BigInt`s."); + Test_AddingValues(); + Test_SubtractingValues(); +} + +protected static function Test_Creating() +{ + Context("Testing creation of `BigInt`s."); + Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ + "a positive `int`."); + TEST_ExpectTrue(__().math.ToBigInt(13524).ToString() == "13524"); + TEST_ExpectTrue( + __().math.ToBigInt(MaxInt).ToString() == "2147483647"); + + Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ + "a positive integer inside `string`."); + TEST_ExpectTrue( + __().math.MakeBigInt_S("2147483647").ToString() + == "2147483647"); + TEST_ExpectTrue( + __().math.MakeBigInt_S("4238756872643464981264982128742389") + .ToString() == "4238756872643464981264982128742389"); + + Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ + "a negative `int`."); + TEST_ExpectTrue(__().math.ToBigInt(-666).ToString() == "-666"); + TEST_ExpectTrue( + __().math.ToBigInt(-MaxInt).ToString() == "-2147483647"); + TEST_ExpectTrue( + __().math.ToBigInt(-MaxInt - 1).ToString() == "-2147483648"); + + Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ + "a negative integer inside `string`."); + TEST_ExpectTrue( + __().math.MakeBigInt_S("-2147483648").ToString() + == "-2147483648"); + TEST_ExpectTrue( + __().math.MakeBigInt_S("-238473846327894632879097410348127") + .ToString() == "-238473846327894632879097410348127"); +} + +protected static function Test_ToText() +{ + Context("Testing `ToText()` method of `BigInt`s."); + Issue("`ToText()` doesn't return value `BigInt` was initialized with" @ + "a positive integer inside `string`."); + TEST_ExpectTrue(__().math + .MakeBigInt_S("2147483647") + .ToText() + .ToString() == "2147483647"); + TEST_ExpectTrue(__().math + .MakeBigInt_S("65784236592763459236597823645978236592378659110571388") + .ToText() + .ToString() == "65784236592763459236597823645978236592378659110571388"); + + Issue("`ToText()` doesn't return value `BigInt` was initialized with" @ + "a negative integer inside `string`."); + TEST_ExpectTrue(__().math + .MakeBigInt_S("-2147483648") + .ToText() + .ToString() == "-2147483648"); + TEST_ExpectTrue(__().math + .MakeBigInt_S("-9827657892365923510176386357863078603212901078175829") + .ToText() + .ToString() == "-9827657892365923510176386357863078603212901078175829"); +} + +protected static function Test_AddingValues() +{ + SubTest_AddingSameSignValues(); + SubTest_AddingDifferentSignValues(); +} + +protected static function SubTest_AddingSameSignValues() +{ + local BigInt main, addition; + + Issue("Two positive `BigInt`s are incorrectly added."); + main = __().math.MakeBigInt_S("927641962323462271784269213864"); + addition = __().math.MakeBigInt_S("16324234842947239847239239"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "927658286558305219024116453103"); + main = __().math.MakeBigInt_S("16324234842947239847239239"); + addition = __().math.MakeBigInt_S("927641962323462271784269213864"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "927658286558305219024116453103"); + main = __().math.MakeBigInt_S("728965872936589276"); + addition = __().math.MakeBigInt_S("728965872936589276"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "1457931745873178552"); + + Issue("Two negative `BigInt`s are incorrectly added."); + main = __().math.MakeBigInt_S("-27641962323462271784269213864"); + addition = __().math.MakeBigInt_S("-6324234842947239847239239"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "-27648286558305219024116453103"); + main = __().math.MakeBigInt_S("-16324234842947239847239239"); + addition = __().math.MakeBigInt_S("-927641962323462271784269213864"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "-927658286558305219024116453103"); + main = __().math.MakeBigInt_S("-728965872936589276"); + addition = __().math.MakeBigInt_S("-728965872936589276"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "-1457931745873178552"); +} + +protected static function SubTest_AddingDifferentSignValues() +{ + local BigInt main, addition; + + Issue("Negative `BigInt`s is incorrectly added to positive one."); + main = __().math.MakeBigInt_S("927641962323462271784269213864"); + addition = __().math.MakeBigInt_S("-1632423484294239847239239"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "927640329899977977544421974625"); + main = __().math.MakeBigInt_S("16324234842947239847239239"); + addition = __().math.MakeBigInt_S("-927641962323462271784269213864"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "-927625638088619324544421974625"); + main = __().math.MakeBigInt_S("728965872936589276"); + addition = __().math.MakeBigInt_S("-728965872936589276"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "0"); + + Issue("Positive `BigInt`s is incorrectly added to negative one."); + main = __().math.MakeBigInt_S("-27641962323462271784269213864"); + addition = __().math.MakeBigInt_S("6324234842947239847239239"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "-27635638088619324544421974625"); + main = __().math.MakeBigInt_S("-16324234842947239847239239"); + addition = __().math.MakeBigInt_S("927641962323462271784269213864"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "927625638088619324544421974625"); + main = __().math.MakeBigInt_S("-728965872936589276"); + addition = __().math.MakeBigInt_S("728965872936589276"); + main.Add(addition); + TEST_ExpectTrue(main.ToString() == "0"); +} + +protected static function Test_SubtractingValues() +{ + SubTest_SubtractingSameSignValues(); + SubTest_SubtractingDifferentSignValues(); +} + +protected static function SubTest_SubtractingSameSignValues() +{ + local BigInt main, sub; + + Issue("Two positive `BigInt`s are incorrectly subtracted."); + main = __().math.MakeBigInt_S("213721893712893789123798123912"); + sub = __().math.MakeBigInt_S("91283172381723712893718931"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "213630610540512065410904404981"); + main = __().math.MakeBigInt_S("328478923749827489237948"); + sub = __().math.MakeBigInt_S("652578623458293527957923579235792529"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "-652578623457965049034173751746554581"); + main = __().math.MakeBigInt_S("728965872936589276"); + sub = __().math.MakeBigInt_S("728965872936589276"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "0"); + + Issue("Two negative `BigInt`s are incorrectly subtracted."); + main = __().math.MakeBigInt_S("-47283948923742901278492345984"); + sub = __().math.MakeBigInt_S("-234782394728937402983200234"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "-47049166529013963875509145750"); + main = __().math.MakeBigInt_S("-8920758902379"); + sub = __().math.MakeBigInt_S("-2975234896823956283952"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "2975234887903197381573"); + main = __().math.MakeBigInt_S("-728965872936589276"); + sub = __().math.MakeBigInt_S("-728965872936589276"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "0"); +} +//Negative `BigInt`s is incorrectly subtracted from positive one. [2] +protected static function SubTest_SubtractingDifferentSignValues() +{ + local BigInt main, sub; + + Issue("Negative `BigInt`s is incorrectly subtracted from positive one."); + main = __().math.MakeBigInt_S("927641962323462271784269213864"); + sub = __().math.MakeBigInt_S("-1632423484294239847239239"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "927643594746946566024116453103"); + main = __().math.MakeBigInt_S("16324234842947239847239239"); + sub = __().math.MakeBigInt_S("-927641962323462271784269213864"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "927658286558305219024116453103"); + main = __().math.MakeBigInt_S("728965872936589276"); + sub = __().math.MakeBigInt_S("-728965872936589276"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "1457931745873178552"); + + Issue("Positive `BigInt`s is incorrectly subtracted from negative one."); + main = __().math.MakeBigInt_S("-27641962323462271784269213864"); + sub = __().math.MakeBigInt_S("6324234842947239847239239"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "-27648286558305219024116453103"); + main = __().math.MakeBigInt_S("-16324234842947239847239239"); + sub = __().math.MakeBigInt_S("927641962323462271784269213864"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "-927658286558305219024116453103"); + main = __().math.MakeBigInt_S("-728965872936589276"); + sub = __().math.MakeBigInt_S("728965872936589276"); + main.Subtract(sub); + TEST_ExpectTrue(main.ToString() == "-1457931745873178552"); + Log("UMBRA TEST"); +} + +defaultproperties +{ + caseGroup = "Math" + caseName = "BigInt" +} \ No newline at end of file diff --git a/sources/Data/Database/Tests/TEST_BigInt.uc b/sources/Data/Database/Tests/TEST_BigInt.uc deleted file mode 100644 index 9e23360..0000000 --- a/sources/Data/Database/Tests/TEST_BigInt.uc +++ /dev/null @@ -1,176 +0,0 @@ -/** - * Set of tests for `BigInt` class. - * Copyright 2022 Anton Tarasenko - *------------------------------------------------------------------------------ - * This file is part of Acedia. - * - * Acedia is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 3 of the License, or - * (at your option) any later version. - * - * Acedia is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Acedia. If not, see . - */ -class TEST_BigInt extends TestCase - abstract; - -protected static function TESTS() -{ - // Here we use `ToString()` method to check `BigInt` creation, - // therefore also testing it - Test_Creating(); - // So here we nee to test `ToText()` methods separately - Test_ToText(); - Context("Testing basic arithmetic operations on `BigInt`s."); - Test_AddingValues(); -} - -protected static function Test_Creating() -{ - Context("Testing creation of `BigInt`s."); - Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ - "a positive `int`."); - TEST_ExpectTrue(class'BigInt'.static.FromInt(13524).ToString() == "13524"); - TEST_ExpectTrue( - class'BigInt'.static.FromInt(MaxInt).ToString() == "2147483647"); - - Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ - "a positive integer inside `string`."); - TEST_ExpectTrue( - class'BigInt'.static.FromDecimal_S("2147483647").ToString() - == "2147483647"); - TEST_ExpectTrue( - class'BigInt'.static.FromDecimal_S("4238756872643464981264982128742389") - .ToString() == "4238756872643464981264982128742389"); - - Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ - "a negative `int`."); - TEST_ExpectTrue(class'BigInt'.static.FromInt(-666).ToString() == "-666"); - TEST_ExpectTrue( - class'BigInt'.static.FromInt(-MaxInt).ToString() == "-2147483647"); - TEST_ExpectTrue( - class'BigInt'.static.FromInt(-MaxInt - 1).ToString() == "-2147483648"); - - Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ - "a negative integer inside `string`."); - TEST_ExpectTrue( - class'BigInt'.static.FromDecimal_S("-2147483648").ToString() - == "-2147483648"); - TEST_ExpectTrue( - class'BigInt'.static.FromDecimal_S("-238473846327894632879097410348127") - .ToString() == "-238473846327894632879097410348127"); -} - -protected static function Test_ToText() -{ - Context("Testing `ToText()` method of `BigInt`s."); - Issue("`ToText()` doesn't return value `BigInt` was initialized with" @ - "a positive integer inside `string`."); - TEST_ExpectTrue(class'BigInt'.static - .FromDecimal_S("2147483647") - .ToText() - .ToString() == "2147483647"); - TEST_ExpectTrue(class'BigInt'.static - .FromDecimal_S("65784236592763459236597823645978236592378659110571388") - .ToText() - .ToString() == "65784236592763459236597823645978236592378659110571388"); - - Issue("`ToText()` doesn't return value `BigInt` was initialized with" @ - "a negative integer inside `string`."); - TEST_ExpectTrue(class'BigInt'.static - .FromDecimal_S("-2147483648") - .ToText() - .ToString() == "-2147483648"); - TEST_ExpectTrue(class'BigInt'.static - .FromDecimal_S("-9827657892365923510176386357863078603212901078175829") - .ToText() - .ToString() == "-9827657892365923510176386357863078603212901078175829"); -} - -protected static function Test_AddingValues() -{ - SubTest_AddingSameSignValues(); - SubTest_AddingDifferentSignValues(); -} - -protected static function SubTest_AddingSameSignValues() -{ - local BigInt main, addition; - - Issue("Two positive `BigInt`s are incorrectly added."); - main = class'BigInt'.static.FromDecimal_S("927641962323462271784269213864"); - addition = class'BigInt'.static.FromDecimal_S("16324234842947239847239239"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "927658286558305219024116453103"); - main = class'BigInt'.static.FromDecimal_S("16324234842947239847239239"); - addition = class'BigInt'.static - .FromDecimal_S("927641962323462271784269213864"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "927658286558305219024116453103"); - main = class'BigInt'.static.FromDecimal_S("728965872936589276"); - addition = class'BigInt'.static.FromDecimal_S("728965872936589276"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "1457931745873178552"); - - Issue("Two negative `BigInt`s are incorrectly added."); - main = class'BigInt'.static.FromDecimal_S("-27641962323462271784269213864"); - addition = class'BigInt'.static.FromDecimal_S("-6324234842947239847239239"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "-27648286558305219024116453103"); - main = class'BigInt'.static.FromDecimal_S("-16324234842947239847239239"); - addition = class'BigInt'.static - .FromDecimal_S("-927641962323462271784269213864"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "-927658286558305219024116453103"); - main = class'BigInt'.static.FromDecimal_S("-728965872936589276"); - addition = class'BigInt'.static.FromDecimal_S("-728965872936589276"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "-1457931745873178552"); -} - -protected static function SubTest_AddingDifferentSignValues() -{ - local BigInt main, addition; - - Issue("Negative `BigInt`s is incorrectly added to positive one."); - main = class'BigInt'.static.FromDecimal_S("927641962323462271784269213864"); - addition = class'BigInt'.static.FromDecimal_S("-1632423484294239847239239"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "927640329899977977544421974625"); - main = class'BigInt'.static.FromDecimal_S("16324234842947239847239239"); - addition = class'BigInt'.static - .FromDecimal_S("-927641962323462271784269213864"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "-927625638088619324544421974625"); - main = class'BigInt'.static.FromDecimal_S("728965872936589276"); - addition = class'BigInt'.static.FromDecimal_S("-728965872936589276"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "0"); - - Issue("Positive `BigInt`s is incorrectly added to negative one."); - main = class'BigInt'.static.FromDecimal_S("-27641962323462271784269213864"); - addition = class'BigInt'.static.FromDecimal_S("6324234842947239847239239"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "-27635638088619324544421974625"); - main = class'BigInt'.static.FromDecimal_S("-16324234842947239847239239"); - addition = class'BigInt'.static - .FromDecimal_S("927641962323462271784269213864"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "927625638088619324544421974625"); - main = class'BigInt'.static.FromDecimal_S("-728965872936589276"); - addition = class'BigInt'.static.FromDecimal_S("728965872936589276"); - main.Add(addition); - TEST_ExpectTrue(main.ToString() == "0"); -} - -defaultproperties -{ - caseGroup = "Database" - caseName = "BigInt" -} \ No newline at end of file