Last active
December 13, 2017 15:50
-
-
Save dimka11/a9739d44c151593ca0c73d0b89292588 to your computer and use it in GitHub Desktop.
QSort Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include "CppUnitTest.h" | |
#include <iostream> | |
using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |
namespace UnitTest2 | |
{ | |
TEST_CLASS(UnitTest1) | |
{ | |
public: | |
int vector[6] = { 14, 10, 11, 19, 2, 25 }; // наш массив | |
bool ArrayAreEqual; // "флаг" | |
int static compare(const void * x1, const void * x2) // функция сравнения элементов массива для quicksort | |
{ | |
return (*(int*)x1 - *(int*)x2); // если результат вычитания равен 0, то числа равны, < 0: x1 < x2; > 0: x1 > x2 | |
} | |
TEST_METHOD(TestMethod1) | |
{ | |
qsort(vector, 6, sizeof(int), compare); // сортируем массив чисел vector[6] | |
// for (int ix = 0; ix < 6; ix++) // вывод на экран | |
// std::cout << vector[ix] << " "; // вывод на экран | |
int TestVector[6] = { 2,10,11,14,19,25 }; // предварительнол отсортированный вектор, с которым сравниваем, наш после соритировки | |
if (std::equal(std::begin(vector), std::end(vector), std::begin(TestVector))) // функция поэлементного сравнения массивов | |
// std::equal(std::begin(vector) - 1-й эл-т массива, std::end(vector) - последний эл-т массива, std::begin(TestVector) - 1-й эл-т массива с которым сравниваем | |
{ | |
ArrayAreEqual = true; // элементы массивов одинаковы | |
} | |
else | |
{ | |
ArrayAreEqual = false; // эл-ты массивов отличаются | |
} | |
Assert::IsTrue(ArrayAreEqual); // проверяет значение флага ArrayAreEqual | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment