.autotest

git-svn-id: svn://ultimatepp.org/upp/trunk@15999 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2021-06-22 07:04:19 +00:00
parent 1f291e2d85
commit 18bc00648b
3 changed files with 229 additions and 0 deletions

161
autotest/Atoi/Atoi.cpp Normal file
View file

@ -0,0 +1,161 @@
#include <Core/Core.h>
using namespace Upp;
int TestAtoi(const char *s)
{
int result;
s = ScanInt<char, byte, uint32, int, 10>(result, s);
return s ? result : -999;
}
int64 TestAtoi64(const char *s)
{
int64 result;
s = ScanInt<char, byte, uint64, int64, 10>(result, s);
return s ? result : -999;
}
int TestAtoiHex(const char *s)
{
int result;
s = ScanInt<char, byte, uint32, int, 16>(result, s);
return s ? result : -999;
}
int TestAtoiOct(const char *s)
{
int result;
s = ScanInt<char, byte, uint32, int, 8>(result, s);
return s ? result : -999;
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
SeedRandom(0);
for(int i = 0; i < 500000; i++) {
int q = (int)Random();
ASSERT(q == TestAtoi(AsString(q)));
if(q >= 0) {
ASSERT(q == TestAtoiHex(FormatIntHex(q)));
ASSERT(q == TestAtoiOct(FormatIntOct(q, 8)));
}
}
for(int i = 0; i < 500000; i++) {
int64 q = Random64();
ASSERT(q == TestAtoi64(AsString(q)));
}
DDUMP(TestAtoi("2147483647"));
DDUMP(TestAtoi("2147483648"));
DDUMP(TestAtoi("-2147483647"));
DDUMP(TestAtoi("-2147483648"));
DDUMP(TestAtoi("-2147483649"));
DDUMP(TestAtoi("0"));
DDUMP(TestAtoi("-0"));
DDUMP(TestAtoi64("9223372036854775807"));
DDUMP(TestAtoi64("9223372036854775808"));
DDUMP(TestAtoi64("-9223372036854775807"));
DDUMP(TestAtoi64("-9223372036854775808"));
DDUMP(TestAtoi64("-9223372036854775809"));
DDUMP(TestAtoi64("0"));
DDUMP(TestAtoi64("-0"));
DDUMP(TestAtoi64(""));
DDUMP(TestAtoi64("z"));
DDUMPHEX(TestAtoiHex("f"));
DDUMPHEX(TestAtoiHex("7fffFFFF"));
DDUMP(CParser("123456").ReadInt());
DDUMP(CParser("123456").ReadInt64());
DDUMP(CParser("-123456").ReadInt());
DDUMP(CParser("-123456").ReadInt64());
DDUMP(CParser("123456").ReadNumber());
DDUMP(CParser("1010").ReadNumber(2));
DDUMP(CParser("10").ReadNumber(4));
DDUMP(CParser("123456").ReadNumber(8));
DDUMP(CParser("123456").ReadNumber(16));
DDUMP(CParser("123456").ReadNumber64());
DDUMP(CParser("10").ReadNumber(4));
DDUMP(CParser("1010").ReadNumber64(2));
DDUMP(CParser("123456").ReadNumber64(8));
DDUMP(CParser("123456").ReadNumber64(16));
CParser p("1 2 3 4 5 6");
DDUMP(p.ReadInt());
DDUMP(p.ReadInt());
DDUMP(p.ReadInt64());
DDUMP(p.ReadInt64());
DDUMP(p.ReadNumber());
DDUMP(p.ReadNumber64());
const char *s = "1 2";
DDUMP(ScanInt(s, &s));
DDUMP(ScanInt(s, &s));
DDUMP(StrInt("123456"));
DDUMP(StrInt("-123456"));
s = "1 2";
DDUMP(ScanInt64(s, &s));
DDUMP(ScanInt64(s, &s));
DDUMP(StrInt64("123456"));
DDUMP(StrInt64("-123456"));
try {
CParser("123456123456123456").ReadInt();
}
catch(CParser::Error e) {
DDUMP(e);
}
try {
CParser("xx").ReadInt();
}
catch(CParser::Error e) {
DDUMP(e);
}
try {
CParser("xx").ReadInt64();
}
catch(CParser::Error e) {
DDUMP(e);
}
try {
CParser("123456123456123456").ReadInt();
}
catch(CParser::Error e) {
DDUMP(e);
}
try {
CParser("123456123456123456123456123456123456123456123456123456").ReadNumber64(8);
}
catch(CParser::Error e) {
DDUMP(e);
}
try {
CParser("123456123456123456123456123456123456123456123456123456").ReadNumber64(16);
}
catch(CParser::Error e) {
DDUMP(e);
}
try {
CParser("123456123456123456123456123456123456123456123456123456").ReadNumber64(10);
}
catch(CParser::Error e) {
DDUMP(e);
}
DDUMP(CParser("123456123").ReadNumber64());
DDUMP(CParser("123456123").ReadNumber64(8));
DDUMP(CParser("123456123").ReadNumber64(16));
CheckLogEtalon();
}

10
autotest/Atoi/Atoi.upp Normal file
View file

@ -0,0 +1,10 @@
uses
Core;
file
Etalon.log,
Atoi.cpp;
mainconfig
"" = "";

58
autotest/Atoi/Etalon.log Normal file
View file

@ -0,0 +1,58 @@
* C:\upp\out\autotest\CLANGx64.Debug.Debug_Full\Atoi.exe 22.06.2021 08:44:47, user: cxl
TestAtoi("2147483647") = 2147483647
TestAtoi("2147483648") = -999
TestAtoi("-2147483647") = -2147483647
TestAtoi("-2147483648") =
TestAtoi("-2147483649") = -999
TestAtoi("0") = 0
TestAtoi("-0") = 0
TestAtoi64("9223372036854775807") = 9223372036854775807
TestAtoi64("9223372036854775808") = -999
TestAtoi64("-9223372036854775807") = -9223372036854775807
TestAtoi64("-9223372036854775808") =
TestAtoi64("-9223372036854775809") = -999
TestAtoi64("0") = 0
TestAtoi64("-0") = 0
TestAtoi64("") = -999
TestAtoi64("z") = -999
TestAtoiHex("f") = 0xf
TestAtoiHex("7fffFFFF") = 0x7fffffff
CParser("123456").ReadInt() = 123456
CParser("123456").ReadInt64() = 123456
CParser("-123456").ReadInt() = -123456
CParser("-123456").ReadInt64() = -123456
CParser("123456").ReadNumber() = 123456
CParser("1010").ReadNumber(2) = 10
CParser("10").ReadNumber(4) = 4
CParser("123456").ReadNumber(8) = 42798
CParser("123456").ReadNumber(16) = 1193046
CParser("123456").ReadNumber64() = 123456
CParser("10").ReadNumber(4) = 4
CParser("1010").ReadNumber64(2) = 10
CParser("123456").ReadNumber64(8) = 42798
CParser("123456").ReadNumber64(16) = 1193046
p.ReadInt() = 1
p.ReadInt() = 2
p.ReadInt64() = 3
p.ReadInt64() = 4
p.ReadNumber() = 5
p.ReadNumber64() = 6
ScanInt(s, &s) = 1
ScanInt(s, &s) = 2
StrInt("123456") = 123456
StrInt("-123456") = -123456
ScanInt64(s, &s) = 1
ScanInt64(s, &s) = 2
StrInt64("123456") = 123456
StrInt64("-123456") = -123456
e = (1,1): number is too big
e = (1,1): missing number
e = (1,1): missing number
e = (1,1): number is too big
e = (1,1): number is too big
e = (1,1): number is too big
e = (1,1): number is too big
CParser("123456123").ReadNumber64() = 123456123
CParser("123456123").ReadNumber64(8) = 21912659
CParser("123456123").ReadNumber64(16) = 591749411