|
- #include "stdafx.h"
- #include "CppUnitTest.h"
- #include "Windows.h"
- #include"../jia/jia.h"
- #include"../jian/jian.h"
- #include"../chen/chen.h"
- #include"../chu/chu.h"
- #include"../chu/tof.h"
- #include <limits>
- //#include "iostream"
- //using namespace std;
-
- using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-
- namespace UnitTest1
- {
- TEST_CLASS(UnitTest1)
- {
- public:
-
-
- TEST_METHOD(TestMethod1)
- {
- // TODO: ÔÚ´ËÊäÈë²âÊÔ´úÂë
- int SUM = GetPrivateProfileInt("Len", "sum", 0, "..//ex1.ini");
- {
- for (int i = 1; i <= SUM; i++)
- {
- char SUMStr[10];
- char TestStr[10] = { "Test" };
- _itoa_s(i, SUMStr, 10);
- strcat_s(TestStr, SUMStr);
- //string str(TestStr);
- int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex1.ini");
- int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex1.ini");
- int c = 0;
- bool ret1 = Add(num1, num2, &c);
- if (ret1 == 1)
- {
- int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex1.ini");
- Assert::AreEqual(output, c);
- }
- else
- {
- LPTSTR Output = (LPTSTR)malloc(255);
- GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex1.ini");
- string s(Output);
- Assert::AreEqual(tof(s), Add(num1, num2, &c));
- }
- }
- }
- }
- TEST_METHOD(TestMethod2)
- {
- int SUB = GetPrivateProfileInt("Len", "sum", 0, "..//ex2.ini");
- {
- for (int j = 1; j <= SUB; j++)
- {
- char SUBStr[8];
- char TestStr[8] = { "Test" };
- _itoa_s(j, SUBStr, 8);
- strcat_s(TestStr, SUBStr);
- int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex2.ini");
- int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex2.ini");
-
- int d = 0;
- bool ret2 = Sub(num1, num2, &d);
- if (ret2 == 1)
- {
- int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex2.ini");
- Assert::AreEqual(output, d);
- }
- else
- {
- LPTSTR Output = (LPTSTR)malloc(255);
- GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex2.ini");
- string s(Output);
- Assert::AreEqual(tof(s), Sub(num1, num2, &d));
- }
- }
- }
- }
- TEST_METHOD(TestMethod3)
- {
- int MUL = GetPrivateProfileInt("Len", "sum", 0, "..//ex3.ini");
- {
- for (int i = 1; i <= MUL; i++)
- {
- char MULStr[8];
- char TestStr[8] = { "Test" };
- _itoa_s(i, MULStr, 8);
- strcat_s(TestStr, MULStr);
- int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex3.ini");
- int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex3.ini");
- int e = 0;
- bool ret3 = chen(num1, num2, &e);
- if (ret3 == 1)
- {
- int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex3.ini");
- Assert::AreEqual(output, e);
- }
- else
- {
- LPTSTR Output = (LPTSTR)malloc(255);
- GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex3.ini");
- string s(Output);
- Assert::AreEqual(tof(s), chen(num1, num2, &e));
- }
-
- }
- }
- }
- TEST_METHOD(TestMethod4)
- {
- int DIV = GetPrivateProfileInt("Len", "sum", 0, "..//ex4.ini");
- {
- for (int i = 1; i <= DIV; i++)
- {
- char DIVStr[8];
- char TestStr[8] = { "Test" };
- _itoa_s(i, DIVStr, 8);
- strcat_s(TestStr, DIVStr);
- int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex4.ini");
- int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex4.ini");
- int output = GetPrivateProfileInt(TestStr, "output", 0, "../ex4.ini");
-
- Assert::AreEqual(output, chu(num1, num2));
- }
- }
- }
-
- };
- }
|