林永吉的Algorithm库
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

96 satır
3.4 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_6 "../Alogrithm/config/6_ContainsDuplicate.ini"
  9. namespace UnitTest
  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. TEST_CLASS(UnitTest_2)
  31. {
  32. TEST_METHOD(TestMethode1)
  33. {
  34. char Section_Name[100][10] = { 0 };
  35. int Section_Count = CalcCount(100, Section_Name, FileName_2);
  36. CString Na, nExpect;
  37. for (int i = 0; i < Section_Count; i++) {
  38. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_2);
  39. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(100), 100, FileName_2);
  40. char* nReal = ExcelSheetColumnTitle(_ttoi(Na));
  41. Assert::AreEqual(*nReal, *nExpect);
  42. }
  43. }
  44. };
  45. TEST_CLASS(UnitTest_3)
  46. {
  47. TEST_METHOD(TestMethode3)
  48. {
  49. char Section_Name[100][10] = { 0 };
  50. int Section_Count = CalcCount(100, Section_Name, FileName_3);
  51. CString Na, nExpect;
  52. for (int i = 0; i < Section_Count; i++) {
  53. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_3);
  54. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_3);
  55. bool nReal = IsUgly(_ttoi(Na));
  56. Assert::AreEqual(nReal, CstrToBool(nExpect));
  57. }
  58. }
  59. };
  60. TEST_CLASS(UnitTest_4)
  61. {
  62. TEST_METHOD(TestMethode1)
  63. {
  64. char Section_Name[100][10] = { 0 };
  65. int Section_Count = CalcCount(100, Section_Name, FileName_4);
  66. CString Na, nExpect;
  67. for (int i = 0; i < Section_Count; i++) {
  68. GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_4);
  69. GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_4);
  70. bool nReal = IsPalindrome(_ttoi(Na));
  71. Assert::AreEqual(nReal, CstrToBool(nExpect));
  72. }
  73. }
  74. };
  75. TEST_CLASS(UnitTest_6)
  76. {
  77. TEST_METHOD(TestMethode1)
  78. {
  79. char Section_Name[100][10] = { 0 };
  80. int Section_Count = CalcCount(100, Section_Name, FileName_6);
  81. int array_count = 0;
  82. int* Section_Value;
  83. CString Na, Nb, nExpect;
  84. for (int i = 0; i < Section_Count; i++) {
  85. GetPrivateProfileString(Section_Name[i], "input", " ", Na.GetBuffer(200), 200, FileName_6);
  86. GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_6);
  87. Section_Value = str_device(Na, &array_count);
  88. bool nReal = containsDuplicate(Section_Value, array_count);
  89. Assert::AreEqual(nReal, CstrToBool(nExpect));
  90. }
  91. }
  92. };
  93. }