school/cs235/lab08/qstest.cpp

302 lines
9.8 KiB
C++
Raw Normal View History

2016-04-06 20:46:10 -07:00
#include "qstest.h"
bool qstest::testSortAll(QSInterface* test) {
sorter s;
int temp[20] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9, 53, 24, 64, 75, 132, 74, 24, 64, 745, 21};
int temp1[20] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9, 53, 24, 64, 75, 132, 74, 24, 64, 745, 21};
test->sortAll(temp, 20);
s.sortAll(temp1, 20);
for(unsigned int i = 0; i < 20; i++) {
if(temp[i] != temp1[i])
return false;
}
return true;;
}
bool qstest::testSort(QSInterface* test) {
sorter s;
int temp[20] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9, 53, 24, 64, 75, 132, 74, 24, 64, 745, 21};
int temp1[20] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9, 53, 24, 64, 75, 132, 74, 24, 64, 745, 21};
test->sort(temp, 20, 3, 15);
s.sort(temp1, 20, 3, 15);
for(unsigned int i = 0; i < 20; i++) {
if(temp[i] != temp1[i])
return false;
}
int temp2[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int temp3[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->sort(temp2, 10, 0, 9);
s.sort(temp3, 10, 0, 9);
for(unsigned int i = 0; i < 10; i++) {
if(temp2[i] != temp3[i])
return false;
}
int temp4[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int temp5[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->sort(temp4, 10, -1, 4);
s.sort(temp5, 10, -1, 4);
for(unsigned int i = 0; i < 10; i++) {
if(temp4[i] != temp5[i])
return false;
}
int temp6[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int temp7[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->sort(temp6, 10, 3, 7);
s.sort(temp7, 10, 3, 7);
for(unsigned int i = 0; i < 10; i++) {
if(temp6[i] != temp7[i])
return false;
}
int temp8[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int temp9[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->sort(temp8, 10, 3, 10);
s.sort(temp9, 10, 3, 10);
for(unsigned int i = 0; i < 10; i++) {
if(temp8[i] != temp9[i])
return false;
}
int tempa[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int tempb[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->sort(tempa, 10, 4, 4);
s.sort(tempb, 10, 4, 4);
for(unsigned int i = 0; i < 10; i++) {
if(tempa[i] != tempb[i])
return false;
}
int tempc[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int tempd[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->sort(tempc, 10, 4, 2);
s.sort(tempd, 10, 4, 2);
for(unsigned int i = 0; i < 10; i++) {
if(tempc[i] != tempd[i])
return false;
}
int tempe[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int tempf[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->sort(tempe, 10, 4, -1);
s.sort(tempf, 10, 4, -1);
for(unsigned int i = 0; i < 10; i++) {
if(tempe[i] != tempf[i])
return false;
}
return true;
}
bool qstest::testMedianOfThree(QSInterface* test) {
sorter s;
int what[9] = {5, 5, 5, 5, 1, 5, 5, 5, 5};
int what1[9] = {5, 5, 5, 5, 1, 5, 5, 5, 5};
test->medianOfThree(what, 9, 0, 8);
s.medianOfThree(what1, 9, 0, 8);
for(unsigned int i = 0; i < 9; i++) {
if(what[i] != what1[i])
return false;
}
int temp[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int temp1[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->medianOfThree(temp, 10, 0, 9);
s.medianOfThree(temp1, 10, 0, 9);
for(unsigned int i = 0; i < 10; i++) {
if(temp[i] != temp1[i])
return false;
}
int temp2[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int temp3[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->medianOfThree(temp2, 10, 2, 9);
s.medianOfThree(temp3, 10, 2, 9);
for(unsigned int i = 0; i < 10; i++) {
if(temp2[i] != temp3[i])
return false;
}
int temp4[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int temp5[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->medianOfThree(temp4, 10, -2, 9);
s.medianOfThree(temp5, 10, -2, 9);
for(unsigned int i = 0; i < 10; i++) {
if(temp4[i] != temp5[i])
return false;
}
int temp6[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int temp7[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->medianOfThree(temp6, 10, 2, -9);
s.medianOfThree(temp7, 10, 2, -9);
for(unsigned int i = 0; i < 10; i++) {
if(temp6[i] != temp7[i])
return false;
}
int temp8[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int temp9[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->medianOfThree(temp8, 10, 7, 5);
s.medianOfThree(temp9, 10, 7, 5);
for(unsigned int i = 0; i < 10; i++) {
if(temp8[i] != temp9[i])
return false;
}
int tempa[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int tempb[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->medianOfThree(tempa, 10, 7, 10);
s.medianOfThree(tempb, 10, 7, 10);
for(unsigned int i = 0; i < 10; i++) {
if(tempa[i] != tempb[i])
return false;
}
int tempc[1] = {4};
int tempd[1] = {4};
test->medianOfThree(tempc, 10, 0, 0);
s.medianOfThree(tempd, 10, 0, 0);
for(unsigned int i = 0; i < 1; i++) {
if(tempc[i] != tempd[i])
return false;
}
int tempe[2] = {4, 8};
int tempf[2] = {4, 8};
test->medianOfThree(tempe, 10, 0, 1);
s.medianOfThree(tempf, 10, 0, 1);
for(unsigned int i = 1; i < 2; i++) {
if(tempe[i] != tempf[i])
return false;
}
int tempg[3] = {4, 8, 3};
int temph[3] = {4, 8, 3};
test->medianOfThree(tempg, 10, 0, 2);
s.medianOfThree(temph, 10, 0, 2);
for(unsigned int i = 3; i < 1; i++) {
if(tempg[i] != temph[i])
return false;
}
int tempi[4] = {4, 8, 3, 6};
int tempj[4] = {4, 8, 3, 6};
test->medianOfThree(tempi, 10, 0, 3);
s.medianOfThree(tempj, 10, 0, 3);
for(unsigned int i = 0; i < 4; i++) {
if(tempi[i] != tempj[i])
return false;
}
int tempk[4] = {4, 8, 3, 6};
int templ[4] = {4, 8, 3, 6};
test->medianOfThree(tempk, 10, 0, 5);
s.medianOfThree(templ, 10, 0, 5);
for(unsigned int i = 0; i < 4; i++) {
if(tempk[i] != templ[i])
return false;
}
return true;;
}
bool qstest::testPartition(QSInterface* test) {
sorter s;
// int size[1] = {7};
// int size1[1] = {7};
// if(test->partition(size, 1, 0, 0) != s.partition(size1, 1, 0, 0)) {
// return false;
// }
// for(unsigned int i = 0; i < 1; i++) {
// if(size[i] != size1[i])
// return false;
// }
int size2[2] = {7, 1};
int size3[2] = {7, 1};
if(test->partition(size2, 2, 0, 1) != s.partition(size3, 2, 0, 1)) {
return false;
}
for(unsigned int i = 0; i < 2; i++) {
if(size2[i] != size3[i])
return false;
}
int temp[14] = {6, 1, 6, 2, 0, 0, 5, 8, 2, 8, 1, 9, 6, 4};
int temp1[14] = {6, 1, 6, 2, 0, 0, 5, 8, 2, 8, 1, 9, 6, 4};
if(test->partition(temp, 14, 0, 14) != s.partition(temp1, 14, 0, 14)) {
return false;
}
for(unsigned int i = 0; i < 14; i++) {
if(temp[i] != temp1[i])
return false;
}
int temp2[20] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9, 53, 24, 64, 75, 132, 74, 24, 64, 745, 21};
int temp3[20] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9, 53, 24, 64, 75, 132, 74, 24, 64, 745, 21};
if(test->partition(temp2, 20, 0, 19) != s.partition(temp3, 20, 0, 19)) {
return false;
}
for(unsigned int i = 0; i < 20; i++) {
if(temp2[i] != temp3[i])
return false;
}
int temp4[14] = {6, 1, 6, 2, 0, 0, 5, 8, 2, 8, 1, 9, 6, 4};
int temp5[14] = {6, 1, 6, 2, 0, 0, 5, 8, 2, 8, 1, 9, 6, 4};
if(test->partition(temp4, 14, -1, 13) != s.partition(temp5, 14, -1, 13)) {
return false;
}
for(unsigned int i = 0; i < 14; i++) {
if(temp4[i] != temp5[i])
return false;
}
int temp6[14] = {6, 1, 6, 2, 0, 0, 5, 8, 2, 8, 1, 9, 6, 4};
int temp7[14] = {6, 1, 6, 2, 0, 0, 5, 8, 2, 8, 1, 9, 6, 4};
if(test->partition(temp6, 14, 6, 2) != s.partition(temp7, 14, 6, 2)) {
return false;
}
for(unsigned int i = 0; i < 14; i++) {
if(temp6[i] != temp7[i])
return false;
}
int temp8[14] = {6, 1, 6, 2, 0, 0, 5, 8, 2, 8, 1, 9, 6, 4};
int temp9[14] = {6, 1, 6, 2, 0, 0, 5, 8, 2, 8, 1, 9, 6, 4};
if(test->partition(temp8, 14, 6, -2) != s.partition(temp9, 14, 6, -2)) {
return false;
}
for(unsigned int i = 0; i < 14; i++) {
if(temp8[i] != temp9[i])
return false;
}
return true;
}
bool qstest::testSwap(QSInterface* test) {
sorter s;
int temp[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
int temp1[10] = {4, 7, 3, 8, 12, -2, 41, 63, 2, 9};
test->swap(temp, 10, 0, 9);
s.swap(temp1, 10, 0, 9);
for(unsigned int i = 0; i < 10; i++) {
if(temp[i] != temp1[i])
return false;
}
test->swap(temp, 10, -1, 9);
s.swap(temp1, 10, -1, 9);
for(unsigned int i = 0; i < 10; i++) {
if(temp[i] != temp1[i])
return false;
}
test->swap(temp, 10, 3, 6);
s.swap(temp1, 10, 3, 6);
for(unsigned int i = 0; i < 10; i++) {
if(temp[i] != temp1[i])
return false;
}
test->swap(temp, 10, 8, 10);
s.swap(temp1, 10, 8, 10);
for(unsigned int i = 0; i < 10; i++) {
if(temp[i] != temp1[i])
return false;
}
test->swap(temp, 10, 8, 8);
s.swap(temp1, 10, 8, 8);
for(unsigned int i = 0; i < 10; i++) {
if(temp[i] != temp1[i])
return false;
}
test->swap(temp, 10, 8, 2);
s.swap(temp1, 10, 8, 2);
for(unsigned int i = 0; i < 10; i++) {
if(temp[i] != temp1[i])
return false;
}
test->swap(temp, 10, 8, -2);
s.swap(temp1, 10, 8, -2);
for(unsigned int i = 0; i < 10; i++) {
if(temp[i] != temp1[i])
return false;
}
return true;;
}