林永吉的Algorithm库
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

116 řádky
4.1 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. namespace UnitTest
  11. {
  12. TEST_CLASS(UnitTest_1)
  13. {
  14. TEST_METHOD(TestMethode1)
  15. {
  16. char Section_Name[100][10] = { 0 };
  17. int Section_Count = CalcCount(100, Section_Name, FileName_1);
  18. int array_count = 0;
  19. int* Section_Value;
  20. CString Na, Nb, nExpect;
  21. for (int i = 0; i < Section_Count; i++) {
  22. GetPrivateProfileString(Section_Name[i], "array", " ", Na.GetBuffer(200), 200, FileName_1);
  23. GetPrivateProfileString(Section_Name[i], "key", " ", Nb.GetBuffer(20), 20, FileName_1);
  24. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_1);
  25. Section_Value = str_device(Na, &array_count);
  26. bool nReal = ContainsNearbyDuplicate(Section_Value, array_count, _ttoi(Nb));
  27. Assert::AreEqual(nReal, CstrToBool(nExpect));
  28. }
  29. }
  30. };
  31. TEST_CLASS(UnitTest_2)
  32. {
  33. TEST_METHOD(TestMethode1)
  34. {
  35. char Section_Name[100][10] = { 0 };
  36. int Section_Count = CalcCount(100, Section_Name, FileName_2);
  37. CString Na, nExpect;
  38. for (int i = 0; i < Section_Count; i++) {
  39. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_2);
  40. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(100), 100, FileName_2);
  41. char* nReal = ExcelSheetColumnTitle(_ttoi(Na));
  42. Assert::AreEqual(*nReal, *nExpect);
  43. }
  44. }
  45. };
  46. TEST_CLASS(UnitTest_3)
  47. {
  48. TEST_METHOD(TestMethode3)
  49. {
  50. char Section_Name[100][10] = { 0 };
  51. int Section_Count = CalcCount(100, Section_Name, FileName_3);
  52. CString Na, nExpect;
  53. for (int i = 0; i < Section_Count; i++) {
  54. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_3);
  55. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_3);
  56. bool nReal = IsUgly(_ttoi(Na));
  57. Assert::AreEqual(nReal, CstrToBool(nExpect));
  58. }
  59. }
  60. };
  61. TEST_CLASS(UnitTest_4)
  62. {
  63. TEST_METHOD(TestMethode1)
  64. {
  65. char Section_Name[100][10] = { 0 };
  66. int Section_Count = CalcCount(100, Section_Name, FileName_4);
  67. CString Na, nExpect;
  68. for (int i = 0; i < Section_Count; i++) {
  69. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_4);
  70. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_4);
  71. bool nReal = IsPalindrome(_ttoi(Na));
  72. Assert::AreEqual(nReal, CstrToBool(nExpect));
  73. }
  74. }
  75. };
  76. TEST_CLASS(UnitTest_5)
  77. {
  78. TEST_METHOD(TestMethode1)
  79. {
  80. char Section_Name[100][10] = { 0 };
  81. int Section_Count = CalcCount(100, Section_Name, FileName_5);
  82. CString Na, nExpect;
  83. for (int i = 0; i < Section_Count; i++) {
  84. GetPrivateProfileString(Section_Name[i], "input", " ", Na.GetBuffer(200), 200, FileName_5);
  85. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_5);
  86. char return_str[100][50] = { 0 };
  87. int return_count = str_device2(Na, return_str);
  88. TreeNode* root = CreatBitTree(return_str, return_count);
  89. int nReal = MinDepth(root);
  90. Assert::AreEqual(nReal,_ttoi(nExpect));
  91. free_tree(root);
  92. }
  93. }
  94. };
  95. TEST_CLASS(UnitTest_6)
  96. {
  97. TEST_METHOD(TestMethode1)
  98. {
  99. char Section_Name[100][10] = { 0 };
  100. int Section_Count = CalcCount(100, Section_Name, FileName_6);
  101. int array_count = 0;
  102. int* Section_Value;
  103. CString Na, Nb, nExpect;
  104. for (int i = 0; i < Section_Count; i++) {
  105. GetPrivateProfileString(Section_Name[i], "input", " ", Na.GetBuffer(200), 200, FileName_6);
  106. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_6);
  107. Section_Value = str_device(Na, &array_count);
  108. bool nReal = containsDuplicate(Section_Value, array_count);
  109. Assert::AreEqual(nReal, CstrToBool(nExpect));
  110. }
  111. }
  112. };
  113. }