diff --git a/autotest/Sort/Sort.cpp b/autotest/Sort/Sort.cpp new file mode 100644 index 000000000..91de34a4f --- /dev/null +++ b/autotest/Sort/Sort.cpp @@ -0,0 +1,58 @@ +#include + +using namespace Upp; + +Vector GetStringData() +{ + Vector data; + int n = Random(100) * Random(100) * Random(10); + for(int i = 0; i < n; i++) + data.Add(AsString(Random(n))); + return data; +} + +Vector GetIntData() +{ + Vector data; + int n = Random(100) * Random(100) * Random(10); + for(int i = 0; i < n; i++) + data.Add(Random(n)); + return data; +} + +template +void CheckSorted(C& data) +{ + for(int i = 0; i < data.GetCount() - 1; i++) { + if(!(data[i] <= data[i + 1])) { + RDUMPC(data); + RLOG("ERROR! " << i); + Exit(1); + } + } +} + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_FILE|LOG_COUT); + for(;;) { + Vector data = GetIntData(); + LOG("int " << data.GetCount()); + Sort(data); + CheckSorted(data); + Vector sdata = GetStringData(); + LOG("String " << sdata.GetCount()); + Sort(sdata); + CheckSorted(sdata); + { + Vector data = GetIntData(); + LOG("int " << data.GetCount()); + StableSortCmp(data); + CheckSorted(data); + Vector sdata = GetStringData(); + LOG("String " << sdata.GetCount()); + StableSortCmp(sdata); + CheckSorted(sdata); + } + } +} diff --git a/autotest/Sort/Sort.upp b/autotest/Sort/Sort.upp new file mode 100644 index 000000000..c5e156710 --- /dev/null +++ b/autotest/Sort/Sort.upp @@ -0,0 +1,9 @@ +uses + Core; + +file + Sort.cpp; + +mainconfig + "" = "SSE2"; + diff --git a/autotest/Sort/init b/autotest/Sort/init new file mode 100644 index 000000000..469e7938f --- /dev/null +++ b/autotest/Sort/init @@ -0,0 +1,4 @@ +#ifndef _Sort_icpp_init_stub +#define _Sort_icpp_init_stub +#include "Core/init" +#endif