ultimatepp/autotest/StringCompare/StringCompare.cpp
cxl c6c2439cf3 .autotest
git-svn-id: svn://ultimatepp.org/upp/trunk@14421 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2020-05-02 08:58:56 +00:00

57 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <Core/Core.h>
#define LDUMP(x) // DUMP(x)
#define LLOGHEXDUMP(a, b) // LOGHEXDUMP(a, b)
using namespace Upp;
#ifdef CPU_ARM
#define N 2000000
#else
#define N 10000000
#endif
int RandomChar()
{
return '0' + Random(64);
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
String a = "1911s";
String b = "191112 in Scottish football";
ASSERT(a < b);
for(int q = 0; q < N; q++) {
LDUMP(q);
if(q % 10000 == 0)
Cout() << q << '\n';
int eq = rand() % 40;
int l1 = rand() % 40;
int l2 = rand() % 40;
String a, b;
for(int i = 0; i < eq; i++)
a.Cat(RandomChar());
b = a;
ASSERT(a.Compare(b) == 0);
for(int i = 0; i < l1; i++)
a.Cat(RandomChar());
for(int i = 0; i < l2; i++)
b.Cat(RandomChar());
int l = min(l1, l2) + eq;
LDUMP(a);
LDUMP(b);
LLOGHEXDUMP(a, a.GetLength());
LLOGHEXDUMP(b, b.GetLength());
LDUMP(a.Compare(b));
LDUMP(strcmp(a, b));
LDUMP(strcmp(~a, ~b));
ASSERT(sgn(strcmp(a, b)) == sgn(a.Compare(b)));
ASSERT(a.Compare(a) == 0);
ASSERT(b.Compare(b) == 0);
}
LOG("------------ OK");
}