### 2. 自动单元测试技术

#### 这里编写的是一个简单的三个数从小到大排序的算法

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>

using namespace std;

void Sort(int &x, int &y, int &z)
{
int p;
if (x > y)
{
p = y;
y = x;
x = p;
}
if (x > z)
{
p = z;
z = x;
x = p;
}
if (y > z)
{
p = z;
z = y;
y = p;
}
}

int main()
{
int a, b, c;
cin >> a >> b >> c;
Sort(a, b, c);
cout << a << " " << b << " " << c;
system("pause");
}


#### 单元测试部分代码，这里我选择了四组测试样例。

#include "stdafx.h"
#include "CppUnitTest.h"
#include "../Project2/1.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTest1
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TestMethod1)
{
int a = 2, b = 1, c = 3;
Sort(a, b, c);
Assert::AreEqual(a, 1, 0);
Assert::AreEqual(b, 2, 0);
Assert::AreEqual(c, 3, 0);
}
TEST_METHOD(TestMethod2)
{
int a = 1, b = 2, c = 3;
Sort(a, b, c);
Assert::AreEqual(a, 1, 0);
Assert::AreEqual(b, 2, 0);
Assert::AreEqual(c, 3, 0);
}
TEST_METHOD(TestMethod3)
{
int a = 3, b = 2, c = 1;
Sort(a, b, c);
Assert::AreEqual(a, 1, 0);
Assert::AreEqual(b, 2, 0);
Assert::AreEqual(c, 3, 0);
}
TEST_METHOD(TestMethod4)
{
int a = 3, b = 1, c = 2;
Sort(a, b, c);
Assert::AreEqual(a, 2, 0);
Assert::AreEqual(b, 1, 0);
Assert::AreEqual(c, 3, 0);
}

};
}