#include #include #include #include "SortedList.h" using namespace std; class Integer { int value; public: explicit Integer(int v=0) : value(v) {} int intValue() const { return value; } bool operator==(const Integer& i) const { return value==i.value; } bool operator<=(const Integer& i) const { return value<=i.value; } bool operator<(const Integer& i) const { return value=(const Integer& i) const { return value>=i.value; } bool operator>(const Integer& i) const { return value>i.value; } }; ostream& operator<<(ostream& os,const Integer &i) { os < *,vector > Pair; void print(const Pair &P) { cout <<"Sorted List:"; for (int i=1; i<=P.first->size(); i++) cout <<" "<get(i); cout < bool isSorted(const SortedList &L) { for (int i=1; i L.get(i+1)) return false; return true; } double compare(const Pair& P) // return the number of points, max: 0.4 { print(P); SortedList *L=P.first;; const vector &A=P.second; double points=0.0; if (A.size()==L->size()) points += 0.05; if (isSorted(*L)) points += 0.05; int count=0; for (int i=0; isize() && A[i]==L->get(i+1).intValue()) count++; } if (count>A.size()-3) points += 0.2-0.05*(A.size()-count); // test count() int idcount=1; count=0; int maxcount=0; for (int i=1; icount(Integer(A[i-1]))==idcount) count++; idcount=1; } } maxcount++; if (L->count(Integer(A[A.size()-1]))==idcount) count++; if (count>maxcount-3) points += 0.1-0.025*(maxcount-count); return points; } Pair generate(int size,int minindex,int maxindex) // for minindex and maxindex: non-positive values mean size()+1-index { SortedList *L=new SortedList; vector A(size); int mini,maxi; for (int i=0; isize()+1-maxindex; else maxi=maxindex; if (minindex<=0) mini=L->size()+1-minindex; else mini=minindex; int item=rand()%20; L->add(rand()%(maxi-mini+1)+mini,Integer(item)); A[i]=item; } sort(A.begin(),A.end()); return Pair(L,A); } int main() { double points=0.0; double maxpoints=0.0; srand(20062); // 5 tests, each 0.4 points: cout <<"Test 1."<List::remove(8); P.second.erase(P.second.begin()+7); points += compare(P)/2.0; P.first->List::remove(20); P.second.erase(P.second.begin()+19); points += compare(P)/2.0; delete P.first; } catch (exception e) { // no exception expected cout <<"Unexpected exception"<remove(Integer(11)); P.second.erase(remove(P.second.begin(), P.second.end(), 11L), P.second.end()); points += compare(P); } catch (exception e) { // no exception expected cout <<"Unexpected exception"<