|
|
@ -1,6 +1,8 @@ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set of tests for `BigInt` class. |
|
|
|
* Author: dkanus |
|
|
|
* Copyright 2022 Anton Tarasenko |
|
|
|
* Home repo: https://www.insultplayers.ru/git/AcediaFramework/AcediaCore |
|
|
|
|
|
|
|
* License: GPL |
|
|
|
|
|
|
|
* Copyright 2022-2023 Anton Tarasenko |
|
|
|
*------------------------------------------------------------------------------ |
|
|
|
*------------------------------------------------------------------------------ |
|
|
|
* This file is part of Acedia. |
|
|
|
* This file is part of Acedia. |
|
|
|
* |
|
|
|
* |
|
|
@ -20,8 +22,7 @@ |
|
|
|
class TEST_BigInt extends TestCase |
|
|
|
class TEST_BigInt extends TestCase |
|
|
|
abstract; |
|
|
|
abstract; |
|
|
|
|
|
|
|
|
|
|
|
protected static function TESTS() |
|
|
|
protected static function TESTS() { |
|
|
|
{ |
|
|
|
|
|
|
|
// Here we use `ToString()` method to check `BigInt` creation, |
|
|
|
// Here we use `ToString()` method to check `BigInt` creation, |
|
|
|
// therefore also testing it |
|
|
|
// therefore also testing it |
|
|
|
Context("Testing creation of `BigInt`s."); |
|
|
|
Context("Testing creation of `BigInt`s."); |
|
|
@ -36,43 +37,33 @@ protected static function TESTS() |
|
|
|
Test_SubtractingValues(); |
|
|
|
Test_SubtractingValues(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function Test_Creating() |
|
|
|
protected static function Test_Creating() { |
|
|
|
{ |
|
|
|
|
|
|
|
Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ |
|
|
|
Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ |
|
|
|
"a positive `int`."); |
|
|
|
"a positive `int`."); |
|
|
|
TEST_ExpectTrue(__().math.ToBigInt(13524).ToString() == "13524"); |
|
|
|
TEST_ExpectTrue(__().math.ToBigInt(13524).ToString() == "13524"); |
|
|
|
TEST_ExpectTrue( |
|
|
|
TEST_ExpectTrue(__().math.ToBigInt(MaxInt).ToString() == "2147483647"); |
|
|
|
__().math.ToBigInt(MaxInt).ToString() == "2147483647"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ |
|
|
|
Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ |
|
|
|
"a positive integer inside `string`."); |
|
|
|
"a positive integer inside `string`."); |
|
|
|
TEST_ExpectTrue( |
|
|
|
TEST_ExpectTrue(__().math.MakeBigInt_S("2147483647").ToString() == "2147483647"); |
|
|
|
__().math.MakeBigInt_S("2147483647").ToString() |
|
|
|
|
|
|
|
== "2147483647"); |
|
|
|
|
|
|
|
TEST_ExpectTrue( |
|
|
|
TEST_ExpectTrue( |
|
|
|
__().math.MakeBigInt_S("4238756872643464981264982128742389") |
|
|
|
__().math.MakeBigInt_S("4238756872643464981264982128742389") |
|
|
|
.ToString() == "4238756872643464981264982128742389"); |
|
|
|
.ToString() == "4238756872643464981264982128742389"); |
|
|
|
|
|
|
|
|
|
|
|
Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ |
|
|
|
Issue("`ToString()` doesn't return value `BigInt` was initialized with a negative `int`."); |
|
|
|
"a negative `int`."); |
|
|
|
|
|
|
|
TEST_ExpectTrue(__().math.ToBigInt(-666).ToString() == "-666"); |
|
|
|
TEST_ExpectTrue(__().math.ToBigInt(-666).ToString() == "-666"); |
|
|
|
TEST_ExpectTrue( |
|
|
|
TEST_ExpectTrue(__().math.ToBigInt(-MaxInt).ToString() == "-2147483647"); |
|
|
|
__().math.ToBigInt(-MaxInt).ToString() == "-2147483647"); |
|
|
|
TEST_ExpectTrue(__().math.ToBigInt(-MaxInt - 1).ToString() == "-2147483648"); |
|
|
|
TEST_ExpectTrue( |
|
|
|
|
|
|
|
__().math.ToBigInt(-MaxInt - 1).ToString() == "-2147483648"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ |
|
|
|
Issue("`ToString()` doesn't return value `BigInt` was initialized with" @ |
|
|
|
"a negative integer inside `string`."); |
|
|
|
"a negative integer inside `string`."); |
|
|
|
TEST_ExpectTrue( |
|
|
|
TEST_ExpectTrue(__().math.MakeBigInt_S("-2147483648").ToString() == "-2147483648"); |
|
|
|
__().math.MakeBigInt_S("-2147483648").ToString() |
|
|
|
|
|
|
|
== "-2147483648"); |
|
|
|
|
|
|
|
TEST_ExpectTrue( |
|
|
|
TEST_ExpectTrue( |
|
|
|
__().math.MakeBigInt_S("-238473846327894632879097410348127") |
|
|
|
__().math.MakeBigInt_S("-238473846327894632879097410348127") |
|
|
|
.ToString() == "-238473846327894632879097410348127"); |
|
|
|
.ToString() == "-238473846327894632879097410348127"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function Test_ToText() |
|
|
|
protected static function Test_ToText() { |
|
|
|
{ |
|
|
|
|
|
|
|
Issue("`ToText()` doesn't return value `BigInt` was initialized with" @ |
|
|
|
Issue("`ToText()` doesn't return value `BigInt` was initialized with" @ |
|
|
|
"a positive integer inside `string`."); |
|
|
|
"a positive integer inside `string`."); |
|
|
|
TEST_ExpectTrue(__().math |
|
|
|
TEST_ExpectTrue(__().math |
|
|
@ -96,20 +87,19 @@ protected static function Test_ToText() |
|
|
|
.ToString() == "-9827657892365923510176386357863078603212901078175829"); |
|
|
|
.ToString() == "-9827657892365923510176386357863078603212901078175829"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function Test_AddingValues() |
|
|
|
protected static function Test_AddingValues() { |
|
|
|
{ |
|
|
|
|
|
|
|
SubTest_AddingSameSignValues(); |
|
|
|
SubTest_AddingSameSignValues(); |
|
|
|
SubTest_AddingDifferentSignValues(); |
|
|
|
SubTest_AddingDifferentSignValues(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function SubTest_AddingSameSignValues() |
|
|
|
protected static function SubTest_AddingSameSignValues() { |
|
|
|
{ |
|
|
|
|
|
|
|
local BigInt main, addition; |
|
|
|
local BigInt main, addition; |
|
|
|
|
|
|
|
|
|
|
|
Issue("Two positive `BigInt`s are incorrectly added."); |
|
|
|
Issue("Two positive `BigInt`s are incorrectly added."); |
|
|
|
main = __().math.MakeBigInt_S("927641962323462271784269213864"); |
|
|
|
main = __().math.MakeBigInt_S("927641962323462271784269213864"); |
|
|
|
addition = __().math.MakeBigInt_S("16324234842947239847239239"); |
|
|
|
addition = __().math.MakeBigInt_S("16324234842947239847239239"); |
|
|
|
main.Add(addition); |
|
|
|
main.Add(addition); |
|
|
|
|
|
|
|
Log("UMBRA" @ main.ToString()); |
|
|
|
TEST_ExpectTrue(main.ToString() == "927658286558305219024116453103"); |
|
|
|
TEST_ExpectTrue(main.ToString() == "927658286558305219024116453103"); |
|
|
|
main = __().math.MakeBigInt_S("16324234842947239847239239"); |
|
|
|
main = __().math.MakeBigInt_S("16324234842947239847239239"); |
|
|
|
addition = __().math.MakeBigInt_S("927641962323462271784269213864"); |
|
|
|
addition = __().math.MakeBigInt_S("927641962323462271784269213864"); |
|
|
@ -135,8 +125,7 @@ protected static function SubTest_AddingSameSignValues() |
|
|
|
TEST_ExpectTrue(main.ToString() == "-1457931745873178552"); |
|
|
|
TEST_ExpectTrue(main.ToString() == "-1457931745873178552"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function SubTest_AddingDifferentSignValues() |
|
|
|
protected static function SubTest_AddingDifferentSignValues() { |
|
|
|
{ |
|
|
|
|
|
|
|
local BigInt main, addition; |
|
|
|
local BigInt main, addition; |
|
|
|
|
|
|
|
|
|
|
|
Issue("Negative `BigInt`s is incorrectly added to positive one."); |
|
|
|
Issue("Negative `BigInt`s is incorrectly added to positive one."); |
|
|
@ -168,14 +157,12 @@ protected static function SubTest_AddingDifferentSignValues() |
|
|
|
TEST_ExpectTrue(main.ToString() == "0"); |
|
|
|
TEST_ExpectTrue(main.ToString() == "0"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function Test_SubtractingValues() |
|
|
|
protected static function Test_SubtractingValues() { |
|
|
|
{ |
|
|
|
|
|
|
|
SubTest_SubtractingSameSignValues(); |
|
|
|
SubTest_SubtractingSameSignValues(); |
|
|
|
SubTest_SubtractingDifferentSignValues(); |
|
|
|
SubTest_SubtractingDifferentSignValues(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function SubTest_SubtractingSameSignValues() |
|
|
|
protected static function SubTest_SubtractingSameSignValues() { |
|
|
|
{ |
|
|
|
|
|
|
|
local BigInt main, sub; |
|
|
|
local BigInt main, sub; |
|
|
|
|
|
|
|
|
|
|
|
Issue("Two positive `BigInt`s are incorrectly subtracted."); |
|
|
|
Issue("Two positive `BigInt`s are incorrectly subtracted."); |
|
|
@ -207,8 +194,7 @@ protected static function SubTest_SubtractingSameSignValues() |
|
|
|
TEST_ExpectTrue(main.ToString() == "0"); |
|
|
|
TEST_ExpectTrue(main.ToString() == "0"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function SubTest_SubtractingDifferentSignValues() |
|
|
|
protected static function SubTest_SubtractingDifferentSignValues() { |
|
|
|
{ |
|
|
|
|
|
|
|
local BigInt main, sub; |
|
|
|
local BigInt main, sub; |
|
|
|
|
|
|
|
|
|
|
|
Issue("Negative `BigInt`s is incorrectly subtracted from positive one."); |
|
|
|
Issue("Negative `BigInt`s is incorrectly subtracted from positive one."); |
|
|
@ -240,8 +226,7 @@ protected static function SubTest_SubtractingDifferentSignValues() |
|
|
|
TEST_ExpectTrue(main.ToString() == "-1457931745873178552"); |
|
|
|
TEST_ExpectTrue(main.ToString() == "-1457931745873178552"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected static function Test_ToInt() |
|
|
|
protected static function Test_ToInt() { |
|
|
|
{ |
|
|
|
|
|
|
|
Issue("Testing conversion for non-overflowing values."); |
|
|
|
Issue("Testing conversion for non-overflowing values."); |
|
|
|
TEST_ExpectTrue(__().math.MakeBigInt_S("0").ToInt() == 0); |
|
|
|
TEST_ExpectTrue(__().math.MakeBigInt_S("0").ToInt() == 0); |
|
|
|
TEST_ExpectTrue(__().math.MakeBigInt_S("-0").ToInt() == 0); |
|
|
|
TEST_ExpectTrue(__().math.MakeBigInt_S("-0").ToInt() == 0); |
|
|
@ -264,8 +249,7 @@ protected static function Test_ToInt() |
|
|
|
__().math.MakeBigInt_S("-32545657348437563873").ToInt() == -2147483648); |
|
|
|
__().math.MakeBigInt_S("-32545657348437563873").ToInt() == -2147483648); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
defaultproperties |
|
|
|
defaultproperties { |
|
|
|
{ |
|
|
|
caseGroup = "Math" |
|
|
|
caseGroup = "Math" |
|
|
|
caseName = "BigInt" |
|
|
|
caseName = "BigInt" |
|
|
|
|
|
|
|
} |
|
|
|
} |