这是林永吉的算法题仓库
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.

88 righe
2.7 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. namespace test1
  9. {
  10. TEST_CLASS(UnitTest_1)
  11. {
  12. TEST_METHOD(TestMethode1)
  13. {
  14. char Section_Name[100][10] = { 0 };
  15. int Section_Count = CalcCount(100, Section_Name, FileName_1);
  16. int array_count = 0;
  17. int* Section_Value;
  18. CString Na, Nb, nExpect;
  19. for (int i = 0; i < Section_Count; i++) {
  20. GetPrivateProfileString(Section_Name[i], "array", " ", Na.GetBuffer(200), 200, FileName_1);
  21. GetPrivateProfileString(Section_Name[i], "key", " ", Nb.GetBuffer(20), 20, FileName_1);
  22. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_1);
  23. Section_Value = str_device(Na, &array_count);
  24. bool nReal = ContainsNearbyDuplicate(Section_Value, array_count, _ttoi(Nb));
  25. Assert::AreEqual(nReal, CstrToBool(nExpect));
  26. }
  27. }
  28. };
  29. }
  30. namespace test2
  31. {
  32. TEST_CLASS(UnitTest_1)
  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. }
  48. namespace test3
  49. {
  50. TEST_CLASS(UnitTest_1)
  51. {
  52. TEST_METHOD(TestMethode1)
  53. {
  54. char Section_Name[100][10] = { 0 };
  55. int Section_Count = CalcCount(100, Section_Name, FileName_3);
  56. CString Na, nExpect;
  57. for (int i = 0; i < Section_Count; i++) {
  58. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_3);
  59. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_3);
  60. bool nReal = IsUgly(_ttoi(Na));
  61. Assert::AreEqual(nReal, CstrToBool(nExpect));
  62. }
  63. }
  64. };
  65. }
  66. namespace test4
  67. {
  68. TEST_CLASS(UnitTest_4)
  69. {
  70. TEST_METHOD(TestMethode1)
  71. {
  72. char Section_Name[100][10] = { 0 };
  73. int Section_Count = CalcCount(100, Section_Name, FileName_4);
  74. CString Na, nExpect;
  75. for (int i = 0; i < Section_Count; i++) {
  76. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_4);
  77. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_4);
  78. bool nReal = IsPalindrome(_ttoi(Na));
  79. Assert::AreEqual(nReal, CstrToBool(nExpect));
  80. }
  81. }
  82. };
  83. }