标签:
#ifndef MERGESORT_H--------------------------------------------------- 实际测试-----------------------------------------------------------------------
int main(void) {
{
int array[]={0, 9, 1, 8, 2, 7, 3, 6, 4, 5};
std::vector<int> testVector(array, array+ sizeof(array)/sizeof(array[0]));
mergeSort(testVector, compare_sorts, &userDefinedObject);
int expected[]={0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for(int i=0; i<sizeof(array)/sizeof(array[0]); ++i)
{
if(array[i] != expected[i])
{
cout << "sorts: "<<i<<endl;
}
}
}
{
Node array[] = {Node(5,0), Node(10,1), Node(5,2), Node(0,3)};
std::vector<Node> testVector(array, array + sizeof(array)/sizeof(array[0]));
mergeSort(testVector, compare_stableSorts, &userDefinedObject);
Node expected[]={Node(0,3), Node(5,0), Node(5,2), Node(10,1)};
for(int i=0; i<sizeof(array)/sizeof(array[0]); ++i)
{
if(array[i].value != expected[i].value || array[i].index != expected[i].index)
{
cout << "stable sorts:" << i << endl;
}
}
}
{
BoundingSphere array[]={BoundingSphere(Cartesian3(-2.0, 0.0, 0.0), 1.0),
BoundingSphere(Cartesian3(-1.0, 0.0, 0.0), 1.0),
BoundingSphere(Cartesian3(-3.0, 0.0, 0.0), 1.0)
};
BoundingSphere expected[]={BoundingSphere(Cartesian3(-3.0, 0.0, 0.0), 1.0),
BoundingSphere(Cartesian3(-2.0, 0.0, 0.0), 1.0),
BoundingSphere(Cartesian3(-1.0, 0.0, 0.0), 1.0),
};
std::vector<BoundingSphere> testVector(array, array + sizeof(array)/sizeof(array[0]));
mergeSort(testVector, compare_object, &userDefinedObject);
for(int i=0; i<sizeof(array)/sizeof(array[0]); ++i)
{
if(!(array[i].equals( expected[i])))
{
cout << "sorts with user defined object:" << i << endl;
}
}
}
}
标签:
原文地址:http://blog.csdn.net/zangle260/article/details/42143855