From dfc5163d5f5143cea366b7d3aacff214574b188f Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 2 May 2016 21:13:08 +0000 Subject: [PATCH] .autotest git-svn-id: svn://ultimatepp.org/upp/trunk@9765 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- autotest/Algo/Algo.cpp | 26 ++-- autotest/CoSort/CoSort.cpp | 133 ------------------ autotest/NTLAsString/NTLAsString.cpp | 1 - autotest/NanoStrings/NanoStrings.cpp | 66 --------- autotest/NanoStrings/NanoStrings.upp | 9 -- autotest/NanoStrings/init | 4 - autotest/Sort/Sort.cpp | 4 +- autotest/ValuePick/ValuePick.cpp | 4 +- autotest/XmlNode/XmlNode.cpp | 10 +- .../initializer_list/initializer_list.cpp | 1 - 10 files changed, 24 insertions(+), 234 deletions(-) delete mode 100644 autotest/NanoStrings/NanoStrings.cpp delete mode 100644 autotest/NanoStrings/NanoStrings.upp delete mode 100644 autotest/NanoStrings/init diff --git a/autotest/Algo/Algo.cpp b/autotest/Algo/Algo.cpp index c3f254329..9b78c468c 100644 --- a/autotest/Algo/Algo.cpp +++ b/autotest/Algo/Algo.cpp @@ -6,20 +6,24 @@ using namespace Upp; CONSOLE_APP_MAIN { + StdLogSetup(LOG_COUT|LOG_FILE); + Vector x; x << 1 << 5 << 4 << 3 << 2 << 10; // 0 1 2 3 4 5 - Check(FindMin(x, 0, 2), 0); - Check(FindMax(x, 0, 3), 1); - Check(FindMax(x, 2, 3), 2); - Check(FindMax(x, 2, 4), 5); - Check(FindMin(x, 2, 4), 4); + Check(FindMin(SubRange(x, 0, 2)), 0); + Check(FindMax(SubRange(x, 0, 3)), 1); + Check(FindMax(SubRange(x, 2, 3)) + 2, 2); + Check(FindMax(SubRange(x, 2, 4)) + 2, 5); + Check(FindMin(SubRange(x, 2, 4)) + 2, 4); Sort(x); - Check(FindBinaryIter(x.Begin(), x.End(), 1) - x.Begin(), 0); - Check(FindBinaryIter(x.Begin(), x.End(), 2) - x.Begin(), 1); - Check(FindBinaryIter(x.Begin(), x.End(), 7), NULL); - Check(FindBinaryIter(x.Begin(), x.End(), 0), NULL); - Check(FindBinaryIter(x.Begin(), x.End(), 11), NULL); - Check(FindBinaryIter(x.Begin(), x.End(), 10) - x.Begin(), 5); + Check(FindBinary(x, 1), 0); + Check(FindBinary(x, 2), 1); + Check(FindBinary(x, 7), -1); + Check(FindBinary(x, 0), -1); + Check(FindBinary(x, 11), -1); + Check(FindBinary(x, 10), 5); + + LOG("================ OK"); } diff --git a/autotest/CoSort/CoSort.cpp b/autotest/CoSort/CoSort.cpp index 5ad328ff3..3795d42ef 100644 --- a/autotest/CoSort/CoSort.cpp +++ b/autotest/CoSort/CoSort.cpp @@ -3,139 +3,6 @@ using namespace Upp; -template -void Sort(CoWork& cw, I l, I h, const Less& less) -{ - const int PARALLEL_THRESHOLD = 80; - - for(;;) { - int count = int(h - l); - if(count < 2) - return; - if(count < 8) { // Final optimized SelectSort - ForwardSort(l, h, less); - return; - } - int pass = 4; - for(;;) { - I middle = l + (count >> 1); // get the middle element - OrderIter2__(l, middle, less); // sort l, middle, h-1 to find median of 3 - OrderIter2__(middle, h - 1, less); - OrderIter2__(l, middle, less); // median is now in middle - IterSwap(l + 1, middle); // move median pivot to l + 1 - I ii = l + 1; - for(I i = l + 2; i != h - 1; ++i) // do partitioning; already l <= pivot <= h - 1 - if(less(*i, *(l + 1))) - IterSwap(++ii, i); - IterSwap(ii, l + 1); // put pivot back in between partitions - I iih = ii; - while(iih + 1 != h && !less(*ii, *(iih + 1))) // Find middle range of elements equal to pivot - ++iih; - if(pass > 5 || min(ii - l, h - iih) > (max(ii - l, h - iih) >> pass)) { // partition sizes ok or we have done max attempts - if(ii - l < h - iih - 1) { // schedule or recurse on smaller partition, tail on larger - if(ii - l < PARALLEL_THRESHOLD) // too small to run in parallel? - Sort(l, ii, less); // resolve in this thread - else - cw & [=, &cw] { CoSort(cw, l, ii, less); }; // schedule for parallel execution - l = iih + 1; - } - else { - if(h - iih - 1 < PARALLEL_THRESHOLD) // too small to run in parallel? - Sort(iih + 1, h, less); // resolve in this thread - else - cw & [=, &cw] { CoSort(cw, iih + 1, h, less); }; // schedule for parallel execution - h = ii; - } - break; - } - IterSwap(l, l + (int)Random(count)); // try some other random elements for median pivot - IterSwap(middle, l + (int)Random(count)); - IterSwap(h - 1, l + (int)Random(count)); - pass++; - } - } -} - -template -void CoSort(CoWork& cw, I l, I h, const Less& less) -{ - const int PARALLEL_THRESHOLD = 80; - - for(;;) { - int count = int(h - l); - if(count < 2) - return; - if(count < 8) { // Final optimized SelectSort - ForwardSort(l, h, less); - return; - } - int pass = 4; - for(;;) { - I middle = l + (count >> 1); // get the middle element - OrderIter2__(l, middle, less); // sort l, middle, h-1 to find median of 3 - OrderIter2__(middle, h - 1, less); - OrderIter2__(l, middle, less); // median is now in middle - IterSwap(l + 1, middle); // move median pivot to l + 1 - I ii = l + 1; - for(I i = l + 2; i != h - 1; ++i) // do partitioning; already l <= pivot <= h - 1 - if(less(*i, *(l + 1))) - IterSwap(++ii, i); - - IterSwap(ii, l + 1); // put pivot back in between partitions - I iih = ii; - while(iih + 1 != h && !less(*ii, *(iih + 1))) // Find middle range of elements equal to pivot - ++iih; - // LOG("count: " << count << ", l: " << ii - l << ", h: " << h - iih); - if(pass > 5 || min(ii - l, h - iih) > (max(ii - l, h - iih) >> pass)) { // partition sizes ok or we have done max attempts - if(ii - l < h - iih - 1) { // schedule or recurse on smaller partition, tail on larger - if(ii - l < PARALLEL_THRESHOLD) // too small to run in parallel? - Sort(l, ii, less); // resolve in this thread - else { - LOG("Schedule " << count << ": " << ii - l); - cw & [=, &cw] { CoSort(cw, l, ii, less); }; // schedule for parallel execution - } - l = iih + 1; - } - else { - if(h - iih - 1 < PARALLEL_THRESHOLD) // too small to run in parallel? - Sort(iih + 1, h, less); // resolve in this thread - else { - LOG("Schedule " << count << ": " << h - iih - 1); - cw & [=, &cw] { CoSort(cw, iih + 1, h, less); }; // schedule for parallel execution - } - h = ii; - } - break; - } - // LOG("RETRY: " << count << ", l: " << ii - l << ", h: " << h - iih); - IterSwap(l, l + (int)Random(count)); // try some other random elements for median pivot - IterSwap(middle, l + (int)Random(count)); - IterSwap(h - 1, l + (int)Random(count)); - pass++; - } - } -} - -template -void CoSort(I l, I h, const Less& less) -{ - CoWork cw; - CoSort(cw, l, h, less); -} - -template -void CoSort(T& c, const Less& less) -{ - CoSort(c.Begin(), c.End(), less); -} - -template -void CoSort(T& c) -{ - typedef typename T::ValueType VT; - CoSort(c.Begin(), c.End(), StdLess()); -} - #ifdef _DEBUG #define N 100000 #else diff --git a/autotest/NTLAsString/NTLAsString.cpp b/autotest/NTLAsString/NTLAsString.cpp index bbe7c4713..80ad426dc 100644 --- a/autotest/NTLAsString/NTLAsString.cpp +++ b/autotest/NTLAsString/NTLAsString.cpp @@ -64,7 +64,6 @@ CONSOLE_APP_MAIN ArrayTest< InVector > (); ArrayTest< InArray > (); ArrayTest< Index > (); - ArrayTest< ArrayIndex > (); ArrayTest< SortedIndex > (); BiArrayTest< BiVector > (); diff --git a/autotest/NanoStrings/NanoStrings.cpp b/autotest/NanoStrings/NanoStrings.cpp deleted file mode 100644 index 533b90a09..000000000 --- a/autotest/NanoStrings/NanoStrings.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include - -using namespace Upp; - -// WARNING: 64-bit OS and 8GB RAM required to run this test - -String RandomString(int maxlen = 70) -{ - int len = Random(maxlen); - String h; - for(int i = 0; i < len; i++) - h.Cat(Random(26) + 'a'); - return h; -} - -CONSOLE_APP_MAIN -{ - StdLogSetup(LOG_COUT|LOG_FILE); - - MemoryLimitKb(8000000); - for(int sz = 0; sz < 2; sz++) { - for(int pass = 0; pass < 2; pass++) { - LOG("--------------------"); - DUMP(sz); - DUMP(pass); - { - NanoStrings ns; - Vector ws; - - ns.ZeroTerminated(sz); - - SeedRandom(); - int i = 0; - int time0 = msecs(); - while(msecs(time0) < 20000) { - if(++i % 10000000 == 0) - RLOG("Created " << i); - String s = pass ? "x" : RandomString(Random(4) ? 5 : 50); - ws.Add(ns.Add(s)); - } - - ns.DumpProfile(); - LOG("---- Strings " << MemoryUsedKb() << " KB used -------"); - LOG(MemoryProfile()); - - SeedRandom(); - for(int i = 0; i < ws.GetCount(); i++) { - if(i % 10000000 == 0) - RLOG("Tested " << i); - String s = pass ? "x" : RandomString(Random(4) ? 5 : 50); - if((sz ? String(ns.GetPtr(ws[i])) : ns.Get(ws[i])) != s) { - DUMP(i); - DUMP(ns.Get(ws[i])); - DUMP(s); - NEVER(); - } - } - LOG("Test OK"); - } - LOG("===== EMPTY " << MemoryUsedKb() << " KB used -------"); - LOG(MemoryProfile()); - } - } - - LOG("============ Everything OK ==================="); -} diff --git a/autotest/NanoStrings/NanoStrings.upp b/autotest/NanoStrings/NanoStrings.upp deleted file mode 100644 index b8c11703f..000000000 --- a/autotest/NanoStrings/NanoStrings.upp +++ /dev/null @@ -1,9 +0,0 @@ -uses - Core; - -file - NanoStrings.cpp; - -mainconfig - "" = ""; - diff --git a/autotest/NanoStrings/init b/autotest/NanoStrings/init deleted file mode 100644 index f37ac1698..000000000 --- a/autotest/NanoStrings/init +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _NanoStrings_icpp_init_stub -#define _NanoStrings_icpp_init_stub -#include "Core/init" -#endif diff --git a/autotest/Sort/Sort.cpp b/autotest/Sort/Sort.cpp index 5e9488a7b..a23571a02 100644 --- a/autotest/Sort/Sort.cpp +++ b/autotest/Sort/Sort.cpp @@ -48,11 +48,11 @@ CONSOLE_APP_MAIN { Vector data = GetIntData(); LOG("int " << data.GetCount()); - StableSortCmp(data); + StableSort(data); CheckSorted(data); Vector sdata = GetStringData(); LOG("String " << sdata.GetCount()); - StableSortCmp(sdata); + StableSort(sdata); CheckSorted(sdata); } } diff --git a/autotest/ValuePick/ValuePick.cpp b/autotest/ValuePick/ValuePick.cpp index af705b962..9ebd1e67b 100644 --- a/autotest/ValuePick/ValuePick.cpp +++ b/autotest/ValuePick/ValuePick.cpp @@ -18,13 +18,13 @@ CONSOLE_APP_MAIN Vector v; v << 5 << 1 << 3; ValueArray va = pick(v); - ASSERT(v.IsPicked()); + ASSERT(v.GetCount() == 0); TEST(va, "[5, 1, 3]"); Vector v2 = va.Pick(); TEST(v2, "[5, 1, 3]"); Sort(v2); va = pick(v2); - ASSERT(v2.IsPicked()); + ASSERT(v2.GetCount() == 0); TEST(va, "[1, 3, 5]"); } { diff --git a/autotest/XmlNode/XmlNode.cpp b/autotest/XmlNode/XmlNode.cpp index 0545cbddc..08d20dc62 100644 --- a/autotest/XmlNode/XmlNode.cpp +++ b/autotest/XmlNode/XmlNode.cpp @@ -8,13 +8,13 @@ CONSOLE_APP_MAIN XmlNode a = ParseXMLFile(GetDataFile("0.xml")); XmlNode b = pick(a); // pick copy - ASSERT(a.IsPicked()); - ASSERT(!b.IsPicked()); + ASSERT(a.GetCount() == 0); + ASSERT(b.GetCount()); DDUMP(AsXML(b, XML_HEADER|XML_DOCTYPE)); - a <<= b; - ASSERT(!a.IsPicked()); - ASSERT(!b.IsPicked()); + a = clone(b); + ASSERT(a.GetCount()); + ASSERT(b.GetCount()); DDUMP(AsXML(a, XML_HEADER|XML_DOCTYPE)); DDUMP(AsXML(b, XML_HEADER|XML_DOCTYPE)); AsXML(b, XML_HEADER|XML_DOCTYPE); diff --git a/autotest/initializer_list/initializer_list.cpp b/autotest/initializer_list/initializer_list.cpp index 176c87177..8ea752691 100644 --- a/autotest/initializer_list/initializer_list.cpp +++ b/autotest/initializer_list/initializer_list.cpp @@ -47,7 +47,6 @@ CONSOLE_APP_MAIN Test2>(); Test2>(); - Test2>(); Test2>(); Test2>();