-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMedianOf3QuickSortTests.cpp
More file actions
67 lines (61 loc) · 1.82 KB
/
MedianOf3QuickSortTests.cpp
File metadata and controls
67 lines (61 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "CppUnitTest.h"
#include "MedianOf3QuickSort.h"
#include <vector>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace std;
namespace AlgorithmsTests
{
TEST_CLASS(MedianOf3QuickSortTests)
{
public:
TEST_METHOD(MedianOf3QuickSortTests_WhenSortListWithOneElement_ExpectNoError)
{
// Arrange
auto sorter = new MedianOf3QuickSort();
static const int values[] = {3};
vector<int> v(values, values + sizeof(values) / sizeof(values[0]) );
// Act
sorter->Sort(v);
// Assert
Assert::IsTrue(v[0] = v[0]);
}
TEST_METHOD(MedianOf3QuickSortTests_WhenSortListWithTwoElements_ExpectSorted)
{
// Arrange
auto sorter = new MedianOf3QuickSort();
static const int values[] = {9,6};
vector<int> v (values, values + sizeof(values) / sizeof(values[0]) );
// Act
sorter->Sort(v);
// Assert
Assert::IsTrue(v[0] < v[1]);
}
TEST_METHOD(MedianOf3QuickSortTests_WhenSortListWithThreeElements_ExpectSortedLeastToGreatest)
{
// Arrange
auto sorter = new MedianOf3QuickSort();
static const int values[] = {3,9,6};
vector<int> v (values, values + sizeof(values) / sizeof(values[0]) );
// Act
sorter->Sort(v);
// Assert
Assert::IsTrue(v[0] < v[1]);
Assert::IsTrue(v[1] < v[2]);
}
TEST_METHOD(MedianOf3QuickSortTests_WhenSortUnorderedList_ExpectSortedLeastToGreatest)
{
// Arrange
auto sorter = new MedianOf3QuickSort();
static const int values[] = {6,2,7,9,5,8,1,4,3,0};
vector<int> v (values, values + sizeof(values) / sizeof(values[0]) );
// Act
sorter->Sort(v);
// Assert
std::stringstream ss;
for (int n : v)
ss << n;
string str = ss.str();
Assert::IsTrue(str == "0123456789");
}
};
}