From 6f3be8252ecdac2b388ee060076e4e090a687468 Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 2 Apr 2014 19:28:04 +0000 Subject: [PATCH] .autotest git-svn-id: svn://ultimatepp.org/upp/trunk@7148 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- autotest/Sort/Sort.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++ autotest/Sort/Sort.upp | 9 +++++++ autotest/Sort/init | 4 +++ 3 files changed, 71 insertions(+) create mode 100644 autotest/Sort/Sort.cpp create mode 100644 autotest/Sort/Sort.upp create mode 100644 autotest/Sort/init 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