林永吉的四则运算库
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.

141 lines
3.1 KiB

  1. #pragma once
  2. #include "pch.h"
  3. #include "CppUnitTest.h"
  4. #include"../FourOperator/dev.h"
  5. #include<Windows.h>
  6. #include <atlstr.h>
  7. #include <stdio.h>
  8. #define FilePath "..//ex1.ini"
  9. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  10. namespace UnitTest1
  11. {
  12. TEST_CLASS(UnitTest1)
  13. {
  14. public:
  15. #if 1
  16. int j = 0;
  17. char str[50][10] = { 0 };//保存ini文件里 节的名字
  18. int count = CalcCount(50, str);//保存ini文件里 节的个数
  19. unsigned short i;
  20. TEST_METHOD(TestMethode1)
  21. {
  22. int nReal;//保存运算结果
  23. CString na, nb, nExpect; //b保存不同的键值
  24. for (j = 0; j < count; j++)
  25. {
  26. GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath);
  27. GetPrivateProfileString(str[j], "nb", " ", nb.GetBuffer(20), 20, FilePath);
  28. GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath);
  29. nReal = dev(_ttoi(na), _ttoi(nb)); //_ttoi是CString转为整型
  30. Assert::AreEqual(nReal, _ttoi(nExpect));
  31. }
  32. }
  33. };
  34. }
  35. #endif
  36. #if 0
  37. TEST_METHOD(a)
  38. {
  39. int nReal;
  40. CString na, nb, nExpect;
  41. //这一段程序是往 ex1.ini 文件中写入测试样例
  42. //WritePrivateProfileString(_T("a"), _T("na"), _T("6"), _T("../ex1.ini"));
  43. //WritePrivateProfileString(_T("a"), _T("nb"), _T("2"), _T("../ex1.ini"));
  44. //WritePrivateProfileString(_T("a"), _T("QExpect"), _T("3"), _T("../ex1.ini"));
  45. //这一段程序是从 ex1.ini 文件读取测试样例
  46. GetPrivateProfileString(_T("a"), _T("na"), _T(" "), na.GetBuffer(20), 20, _T(FilePath));
  47. GetPrivateProfileString(_T("a"), _T("nb"), _T(" "), nb.GetBuffer(20), 20, _T(FilePath));
  48. GetPrivateProfileString(_T("a"), _T("nExpect"), _T(" "), nExpect.GetBuffer(20), 20, _T(FilePath));
  49. nReal = dev(_ttoi(na), _ttoi(nb));
  50. Assert::AreEqual(nReal, _ttoi(nExpect));
  51. }
  52. TEST_METHOD(b)
  53. {
  54. int nReal;
  55. CString na, nb, nExpect;
  56. GetPrivateProfileString(_T("b"), _T("na"), _T(" "), na.GetBuffer(20), 20, _T(FilePath));
  57. GetPrivateProfileString(_T("b"), _T("nb"), _T(" "), nb.GetBuffer(20), 20, _T(FilePath));
  58. GetPrivateProfileString(_T("b"), _T("nExpect"), _T(" "), nExpect.GetBuffer(20), 20, _T(FilePath));
  59. nReal = dev(_ttoi(na), _ttoi(nb));
  60. Assert::AreEqual(nReal, _ttoi(nExpect));
  61. }
  62. TEST_METHOD(c)
  63. {
  64. int nReal;
  65. CString na, nb, nExpect;
  66. GetPrivateProfileString(_T("c"), _T("na"), _T(" "), na.GetBuffer(20), 20, _T(FilePath));
  67. GetPrivateProfileString(_T("c"), _T("nb"), _T(" "), nb.GetBuffer(20), 20, _T(FilePath));
  68. GetPrivateProfileString(_T("c"), _T("nExpect"), _T(" "), nExpect.GetBuffer(20), 20, _T(FilePath));
  69. nReal = dev(_ttoi(na), _ttoi(nb));
  70. Assert::AreEqual(nReal, _ttoi(nExpect));
  71. }
  72. TEST_METHOD(TestMethod3)
  73. {
  74. int nReal;
  75. CString na, nb, nExpect;
  76. GetPrivateProfileString("d", "na", " ", na.GetBuffer(20), 20, FilePath);
  77. GetPrivateProfileString("d", "nb", " ", nb.GetBuffer(20), 20, FilePath);
  78. GetPrivateProfileString("d", "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath);
  79. nReal = dev(_ttoi(na), _ttoi(nb));
  80. Assert::AreEqual(nReal, _ttoi(nExpect));
  81. }
  82. #endif