林永吉的Algorithm库
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

136 righe
4.9 KiB

  1. #include "pch.h"
  2. #include "CppUnitTest.h"
  3. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  4. #define FileName_1 "../Alogrithm/config/1_ContainsNearbyDuplicate.ini"
  5. #define FileName_2 "../Alogrithm/config/2_ExcelSheetColumnTiTle.ini"
  6. #define FileName_3 "../Alogrithm/config/3_bool IsUgly.ini"
  7. #define FileName_4 "../Alogrithm/config/4_IsPalindrome.ini"
  8. #define FileName_5 "../Alogrithm/config/5_MinDepth.ini"
  9. #define FileName_6 "../Alogrithm/config/6_ContainsDuplicate.ini"
  10. #define FileName_7 "../Alogrithm/config/7_MaxDepth.ini"
  11. namespace UnitTest
  12. {
  13. TEST_CLASS(UnitTest_1)
  14. {
  15. TEST_METHOD(TestMethode1)
  16. {
  17. char Section_Name[100][10] = { 0 };
  18. int Section_Count = CalcCount(100, Section_Name, FileName_1);
  19. int array_count = 0;
  20. int* Section_Value;
  21. CString Na, Nb, nExpect;
  22. for (int i = 0; i < Section_Count; i++) {
  23. GetPrivateProfileString(Section_Name[i], "array", " ", Na.GetBuffer(200), 200, FileName_1);
  24. GetPrivateProfileString(Section_Name[i], "key", " ", Nb.GetBuffer(20), 20, FileName_1);
  25. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_1);
  26. Section_Value = str_device(Na, &array_count);
  27. bool nReal = ContainsNearbyDuplicate(Section_Value, array_count, _ttoi(Nb));
  28. Assert::AreEqual(nReal, CstrToBool(nExpect));
  29. }
  30. }
  31. };
  32. TEST_CLASS(UnitTest_2)
  33. {
  34. TEST_METHOD(TestMethode1)
  35. {
  36. char Section_Name[100][10] = { 0 };
  37. int Section_Count = CalcCount(100, Section_Name, FileName_2);
  38. CString Na, nExpect;
  39. for (int i = 0; i < Section_Count; i++) {
  40. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_2);
  41. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(100), 100, FileName_2);
  42. char* nReal = ExcelSheetColumnTitle(_ttoi(Na));
  43. Assert::AreEqual(*nReal, *nExpect);
  44. }
  45. }
  46. };
  47. TEST_CLASS(UnitTest_3)
  48. {
  49. TEST_METHOD(TestMethode3)
  50. {
  51. char Section_Name[100][10] = { 0 };
  52. int Section_Count = CalcCount(100, Section_Name, FileName_3);
  53. CString Na, nExpect;
  54. for (int i = 0; i < Section_Count; i++) {
  55. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_3);
  56. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_3);
  57. bool nReal = IsUgly(_ttoi(Na));
  58. Assert::AreEqual(nReal, CstrToBool(nExpect));
  59. }
  60. }
  61. };
  62. TEST_CLASS(UnitTest_4)
  63. {
  64. TEST_METHOD(TestMethode1)
  65. {
  66. char Section_Name[100][10] = { 0 };
  67. int Section_Count = CalcCount(100, Section_Name, FileName_4);
  68. CString Na, nExpect;
  69. for (int i = 0; i < Section_Count; i++) {
  70. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_4);
  71. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_4);
  72. bool nReal = IsPalindrome(_ttoi(Na));
  73. Assert::AreEqual(nReal, CstrToBool(nExpect));
  74. }
  75. }
  76. };
  77. TEST_CLASS(UnitTest_5)
  78. {
  79. TEST_METHOD(TestMethode1)
  80. {
  81. char Section_Name[100][10] = { 0 };
  82. int Section_Count = CalcCount(100, Section_Name, FileName_5);
  83. CString Na, nExpect;
  84. for (int i = 0; i < Section_Count; i++) {
  85. GetPrivateProfileString(Section_Name[i], "input", " ", Na.GetBuffer(200), 200, FileName_5);
  86. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_5);
  87. char return_str[100][50] = { 0 };
  88. int return_count = str_device2(Na, return_str);
  89. TreeNode* root = CreatBitTree(return_str, return_count);
  90. int nReal = MinDepth(root);
  91. Assert::AreEqual(nReal,_ttoi(nExpect));
  92. free_tree(root);
  93. }
  94. }
  95. };
  96. TEST_CLASS(UnitTest_6)
  97. {
  98. TEST_METHOD(TestMethode1)
  99. {
  100. char Section_Name[100][10] = { 0 };
  101. int Section_Count = CalcCount(100, Section_Name, FileName_6);
  102. int array_count = 0;
  103. int* Section_Value;
  104. CString Na, Nb, nExpect;
  105. for (int i = 0; i < Section_Count; i++) {
  106. GetPrivateProfileString(Section_Name[i], "input", " ", Na.GetBuffer(200), 200, FileName_6);
  107. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_6);
  108. Section_Value = str_device(Na, &array_count);
  109. bool nReal = containsDuplicate(Section_Value, array_count);
  110. Assert::AreEqual(nReal, CstrToBool(nExpect));
  111. }
  112. }
  113. };
  114. TEST_CLASS(UnitTest_7)
  115. {
  116. TEST_METHOD(TestMethode1)
  117. {
  118. char Section_Name[100][10] = { 0 };
  119. int Section_Count = CalcCount(100, Section_Name, FileName_7);
  120. CString Na, nExpect;
  121. for (int i = 0; i < Section_Count; i++) {
  122. GetPrivateProfileString(Section_Name[i], "input", " ", Na.GetBuffer(200), 200, FileName_7);
  123. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_7);
  124. char return_str[100][50] = { 0 };
  125. int return_count = str_device2(Na, return_str);
  126. TreeNode2* root = CreatBitTree2(return_str, return_count);
  127. int nReal = MaxDepth(root);
  128. Assert::AreEqual(nReal, _ttoi(nExpect));
  129. free_tree2(root);
  130. }
  131. }
  132. };
  133. }