您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

133 行
3.5 KiB

  1. #include "stdafx.h"
  2. #include "CppUnitTest.h"
  3. #include "Windows.h"
  4. #include"../jia/jia.h"
  5. #include"../jian/jian.h"
  6. #include"../chen/chen.h"
  7. #include"../chu/chu.h"
  8. #include"../chu/tof.h"
  9. #include <limits>
  10. //#include "iostream"
  11. //using namespace std;
  12. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  13. namespace UnitTest1
  14. {
  15. TEST_CLASS(UnitTest1)
  16. {
  17. public:
  18. TEST_METHOD(TestMethod1)
  19. {
  20. // TODO: ÔÚ´ËÊäÈë²âÊÔ´úÂë
  21. int SUM = GetPrivateProfileInt("Len", "sum", 0, "..//ex1.ini");
  22. {
  23. for (int i = 1; i <= SUM; i++)
  24. {
  25. char SUMStr[10];
  26. char TestStr[10] = { "Test" };
  27. _itoa_s(i, SUMStr, 10);
  28. strcat_s(TestStr, SUMStr);
  29. //string str(TestStr);
  30. int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex1.ini");
  31. int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex1.ini");
  32. int c = 0;
  33. bool ret1 = Add(num1, num2, &c);
  34. if (ret1 == 1)
  35. {
  36. int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex1.ini");
  37. Assert::AreEqual(output, c);
  38. }
  39. else
  40. {
  41. LPTSTR Output = (LPTSTR)malloc(255);
  42. GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex1.ini");
  43. string s(Output);
  44. Assert::AreEqual(tof(s), Add(num1, num2, &c));
  45. }
  46. }
  47. }
  48. }
  49. TEST_METHOD(TestMethod2)
  50. {
  51. int SUB = GetPrivateProfileInt("Len", "sum", 0, "..//ex2.ini");
  52. {
  53. for (int j = 1; j <= SUB; j++)
  54. {
  55. char SUBStr[8];
  56. char TestStr[8] = { "Test" };
  57. _itoa_s(j, SUBStr, 8);
  58. strcat_s(TestStr, SUBStr);
  59. int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex2.ini");
  60. int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex2.ini");
  61. int d = 0;
  62. bool ret2 = Sub(num1, num2, &d);
  63. if (ret2 == 1)
  64. {
  65. int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex2.ini");
  66. Assert::AreEqual(output, d);
  67. }
  68. else
  69. {
  70. LPTSTR Output = (LPTSTR)malloc(255);
  71. GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex2.ini");
  72. string s(Output);
  73. Assert::AreEqual(tof(s), Sub(num1, num2, &d));
  74. }
  75. }
  76. }
  77. }
  78. TEST_METHOD(TestMethod3)
  79. {
  80. int MUL = GetPrivateProfileInt("Len", "sum", 0, "..//ex3.ini");
  81. {
  82. for (int i = 1; i <= MUL; i++)
  83. {
  84. char MULStr[8];
  85. char TestStr[8] = { "Test" };
  86. _itoa_s(i, MULStr, 8);
  87. strcat_s(TestStr, MULStr);
  88. int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex3.ini");
  89. int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex3.ini");
  90. int e = 0;
  91. bool ret3 = chen(num1, num2, &e);
  92. if (ret3 == 1)
  93. {
  94. int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex3.ini");
  95. Assert::AreEqual(output, e);
  96. }
  97. else
  98. {
  99. LPTSTR Output = (LPTSTR)malloc(255);
  100. GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex3.ini");
  101. string s(Output);
  102. Assert::AreEqual(tof(s), chen(num1, num2, &e));
  103. }
  104. }
  105. }
  106. }
  107. TEST_METHOD(TestMethod4)
  108. {
  109. int DIV = GetPrivateProfileInt("Len", "sum", 0, "..//ex4.ini");
  110. {
  111. for (int i = 1; i <= DIV; i++)
  112. {
  113. char DIVStr[8];
  114. char TestStr[8] = { "Test" };
  115. _itoa_s(i, DIVStr, 8);
  116. strcat_s(TestStr, DIVStr);
  117. int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex4.ini");
  118. int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex4.ini");
  119. int output = GetPrivateProfileInt(TestStr, "output", 0, "../ex4.ini");
  120. Assert::AreEqual(output, chu(num1, num2));
  121. }
  122. }
  123. }
  124. };
  125. }