-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertionSortTests.cpp
More file actions
40 lines (36 loc) · 1016 Bytes
/
InsertionSortTests.cpp
File metadata and controls
40 lines (36 loc) · 1016 Bytes
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
#pragma once
#include "CppUnitTest.h"
#include "InsertionSort.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace std;
namespace AlgorithmsTests
{
TEST_CLASS(InsertionSortTests)
{
TEST_METHOD(InsertionSortTests_WhenSingleElement_ExpectNoChanges)
{
// Arrange
static const int values[] = {1};
vector<int> v(values, values + sizeof(values) / sizeof(values[0]));
auto sorter = new InsertionSort();
// Act
sorter->Sort(v);
// Assert
Assert::IsTrue(v[0] = 1);
}
TEST_METHOD(InsertionSortTests_WhenSortUnsortedArray_ExpectSortedLeastToGreatest)
{
// Arrange
static const int values[] = {2,6,4,8,9,1,0,3,5,7};
vector<int> v(values, values + sizeof(values) / sizeof(values[0]));
auto sorter = new InsertionSort();
// Act
sorter->Sort(v);
// Assert
std::stringstream ss;
for(int n : v)
ss << n;
Assert::IsTrue("0123456789" == ss.str());
}
};
}