mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
upptst: Sort test
git-svn-id: svn://ultimatepp.org/upp/trunk@5245 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
c692646687
commit
054772002a
4 changed files with 70 additions and 8 deletions
48
upptst/Sort/Sort.cpp
Normal file
48
upptst/Sort/Sort.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
Vector<String> GetStringData()
|
||||
{
|
||||
Vector<String> data;
|
||||
int n = Random(100) * Random(100) * Random(10);
|
||||
for(int i = 0; i < n; i++)
|
||||
data.Add(AsString(Random(n)));
|
||||
return data;
|
||||
}
|
||||
|
||||
Vector<int> GetIntData()
|
||||
{
|
||||
Vector<int> data;
|
||||
int n = Random(100) * Random(100) * Random(10);
|
||||
for(int i = 0; i < n; i++)
|
||||
data.Add(Random(n));
|
||||
return data;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
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<int> data = GetIntData();
|
||||
LOG("int " << data.GetCount());
|
||||
Sort(data);
|
||||
CheckSorted(data);
|
||||
Vector<String> sdata = GetStringData();
|
||||
LOG("String " << sdata.GetCount());
|
||||
Sort(sdata);
|
||||
CheckSorted(sdata);
|
||||
}
|
||||
}
|
||||
9
upptst/Sort/Sort.upp
Normal file
9
upptst/Sort/Sort.upp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
Sort.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "SSE2";
|
||||
|
||||
4
upptst/Sort/init
Normal file
4
upptst/Sort/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _Sort_icpp_init_stub
|
||||
#define _Sort_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#endif
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
StableSort.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
StableSort.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue