这是林永吉的算法题仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.5 KiB

  1. #include "pch.h"
  2. #include "CppUnitTest.h"
  3. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  4. #define FileName_1 "../code/config/1_ContainsNearbyDuplicate.ini"
  5. #define FileName_2 "../code/config/2_ExcelSheetColumnTiTle.ini"
  6. #define FileName_3 "../code/config/3_IsUgly.ini"
  7. #define FileName_4 "../code/config/4_IsPalindrome.ini"
  8. #define FileName_5 "../code/config/5_MinDepth.ini"
  9. namespace test1
  10. {
  11. TEST_CLASS(UnitTest_1)
  12. {
  13. TEST_METHOD(TestMethode1)
  14. {
  15. char Section_Name[100][10] = { 0 };
  16. int Section_Count = CalcCount(100, Section_Name, FileName_1);
  17. int array_count = 0;
  18. int* Section_Value;
  19. CString Na, Nb, nExpect;
  20. for (int i = 0; i < Section_Count; i++) {
  21. GetPrivateProfileString(Section_Name[i], "array", " ", Na.GetBuffer(200), 200, FileName_1);
  22. GetPrivateProfileString(Section_Name[i], "key", " ", Nb.GetBuffer(20), 20, FileName_1);
  23. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_1);
  24. Section_Value = str_device(Na, &array_count);
  25. bool nReal = ContainsNearbyDuplicate(Section_Value, array_count, _ttoi(Nb));
  26. Assert::AreEqual(nReal, CstrToBool(nExpect));
  27. }
  28. }
  29. };
  30. }
  31. namespace test2
  32. {
  33. TEST_CLASS(UnitTest_1)
  34. {
  35. TEST_METHOD(TestMethode1)
  36. {
  37. char Section_Name[100][10] = { 0 };
  38. int Section_Count = CalcCount(100, Section_Name, FileName_2);
  39. CString Na, nExpect;
  40. for (int i = 0; i < Section_Count; i++) {
  41. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_2);
  42. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(100), 100, FileName_2);
  43. char* nReal = ExcelSheetColumnTitle(_ttoi(Na));
  44. Assert::AreEqual(nReal, nExpect);
  45. }
  46. }
  47. };
  48. }
  49. namespace test3
  50. {
  51. TEST_CLASS(UnitTest_1)
  52. {
  53. TEST_METHOD(TestMethode1)
  54. {
  55. char Section_Name[100][10] = { 0 };
  56. int Section_Count = CalcCount(100, Section_Name, FileName_3);
  57. CString Na, nExpect;
  58. for (int i = 0; i < Section_Count; i++) {
  59. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_3);
  60. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_3);
  61. bool nReal = IsUgly(_ttoi(Na));
  62. Assert::AreEqual(nReal, CstrToBool(nExpect));
  63. }
  64. }
  65. };
  66. }
  67. namespace test4
  68. {
  69. TEST_CLASS(UnitTest_4)
  70. {
  71. TEST_METHOD(TestMethode1)
  72. {
  73. char Section_Name[100][10] = { 0 };
  74. int Section_Count = CalcCount(100, Section_Name, FileName_4);
  75. CString Na, nExpect;
  76. for (int i = 0; i < Section_Count; i++) {
  77. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_4);
  78. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_4);
  79. bool nReal = IsPalindrome(_ttoi(Na));
  80. Assert::AreEqual(nReal, CstrToBool(nExpect));
  81. }
  82. }
  83. };
  84. }
  85. namespace test5
  86. {
  87. TEST_CLASS(UnitTest_5)
  88. {
  89. TEST_METHOD(TestMethode1)
  90. {
  91. char Section_Name[100][10] = { 0 };
  92. int Section_Count = CalcCount(100, Section_Name, FileName_5);
  93. CString Na, nExpect;
  94. for (int i = 0; i < Section_Count; i++) {
  95. GetPrivateProfileString(Section_Name[i], "input", " ", Na.GetBuffer(200), 200, FileName_5);
  96. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_5);
  97. char return_str[100][50] = { 0 };
  98. int return_count = str_device2(Na, return_str);
  99. TreeNode* root = CreatBitTree(return_str, return_count);
  100. int nReal = MinDepth(root);
  101. Assert::AreEqual(nReal, _ttoi(nExpect));
  102. free_tree(root);
  103. }
  104. }
  105. };
  106. }