From c55e356b67cfc4da7f2b134de698cbbc97525189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=98=A5=E5=B1=B1?= <1760264627@qq.com> Date: Thu, 10 Dec 2020 08:59:48 +0800 Subject: [PATCH] 11 --- jia/UnitTest1/UnitTest1.vcxproj | 2 +- jia/UnitTest1/unittest1.cpp | 88 ++++++++++++++++++++++++--------- jia/chen/Source.def | 3 +- jia/chen/chen.cpp | 15 +++--- jia/chen/chen.h | 7 ++- jia/chu/chu.vcxproj | 4 +- jia/chu/chu.vcxproj.filters | 6 +++ jia/chu/main.cpp | 56 ++++++++++++++++----- jia/chu/tof.cpp | 18 +++++++ jia/chu/tof.h | 8 +++ jia/ex1.ini | 14 +++--- jia/ex2.ini | 12 ++--- jia/ex3.ini | 36 +++++++------- jia/ex4.ini | 10 ++-- jia/jia/jia.cpp | 14 ++---- jia/jia/jia.h | 4 +- jia/jian/jian.cpp | 26 ++++++++-- jia/jian/jian.h | 4 +- 18 files changed, 224 insertions(+), 103 deletions(-) create mode 100644 jia/chu/tof.cpp create mode 100644 jia/chu/tof.h diff --git a/jia/UnitTest1/UnitTest1.vcxproj b/jia/UnitTest1/UnitTest1.vcxproj index 9fecb53..2acaad5 100644 --- a/jia/UnitTest1/UnitTest1.vcxproj +++ b/jia/UnitTest1/UnitTest1.vcxproj @@ -60,7 +60,7 @@ <SubSystem>Windows</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> - <AdditionalDependencies>..\jia\Debug\jia.obj;..\jian\Debug\jian.obj;..\chen\Debug\chen.obj;..\chu\Debug\chu.obj;%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalDependencies>..\jia\Debug\jia.obj;..\jian\Debug\jian.obj;..\chen\Debug\chen.obj;..\chu\Debug\chu.obj;..\chu\Debug\tof.obj;%(AdditionalDependencies)</AdditionalDependencies> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> diff --git a/jia/UnitTest1/unittest1.cpp b/jia/UnitTest1/unittest1.cpp index 7dff01e..7dddd41 100644 --- a/jia/UnitTest1/unittest1.cpp +++ b/jia/UnitTest1/unittest1.cpp @@ -5,6 +5,10 @@ #include"../jian/jian.h" #include"../chen/chen.h" #include"../chu/chu.h" +#include"../chu/tof.h" +#include <limits> +//#include "iostream" +//using namespace std; using namespace Microsoft::VisualStudio::CppUnitTestFramework; @@ -18,25 +22,37 @@ namespace UnitTest1 TEST_METHOD(TestMethod1) { // TODO: �ڴ�������Դ��� - int SUM = GetPrivateProfileInt("Len", "sum", 0, "../ex1.ini"); + int SUM = GetPrivateProfileInt("Len", "sum", 0, "..//ex1.ini"); { for (int i = 1; i <= SUM; i++) { - char SUMStr[8]; - char TestStr[8] = { "Test" }; - _itoa_s(i, SUMStr, 8); + char SUMStr[10]; + char TestStr[10] = { "Test" }; + _itoa_s(i, SUMStr, 10); strcat_s(TestStr, SUMStr); - int num1 = GetPrivateProfileInt("TestStr", "number1", 0, "ex1.ini"); - int num2 = GetPrivateProfileInt("TestStr", "number2", 0, "ex1.ini"); - int output = GetPrivateProfileInt("TestStr", "output", 0, "ex1.ini"); - - Assert::AreEqual(output, add(num1, num2)); + //string str(TestStr); + int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex1.ini"); + int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex1.ini"); + int c = 0; + bool ret1 = Add(num1, num2, &c); + if (ret1 == 1) + { + int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex1.ini"); + Assert::AreEqual(output, c); + } + else + { + LPTSTR Output = (LPTSTR)malloc(255); + GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex1.ini"); + string s(Output); + Assert::AreEqual(tof(s), Add(num1, num2, &c)); + } } } } TEST_METHOD(TestMethod2) { - int SUB = GetPrivateProfileInt("Len", "sum", 0, "../ex2.ini"); + int SUB = GetPrivateProfileInt("Len", "sum", 0, "..//ex2.ini"); { for (int j = 1; j <= SUB; j++) { @@ -44,17 +60,29 @@ namespace UnitTest1 char TestStr[8] = { "Test" }; _itoa_s(j, SUBStr, 8); strcat_s(TestStr, SUBStr); - int num1 = GetPrivateProfileInt("TestStr", "number1", 0, "ex2.ini"); - int num2 = GetPrivateProfileInt("TestStr", "number2", 0, "ex2.ini"); - int output = GetPrivateProfileInt("TestStr", "output", 0, "ex2.ini"); - - Assert::AreEqual(output, sub(num1, num2)); + int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex2.ini"); + int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex2.ini"); + + int d = 0; + bool ret2 = Sub(num1, num2, &d); + if (ret2 == 1) + { + int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex2.ini"); + Assert::AreEqual(output, d); + } + else + { + LPTSTR Output = (LPTSTR)malloc(255); + GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex2.ini"); + string s(Output); + Assert::AreEqual(tof(s), Sub(num1, num2, &d)); + } } } } TEST_METHOD(TestMethod3) { - int MUL = GetPrivateProfileInt("Len", "sum", 0, "../ex3.ini"); + int MUL = GetPrivateProfileInt("Len", "sum", 0, "..//ex3.ini"); { for (int i = 1; i <= MUL; i++) { @@ -62,17 +90,29 @@ namespace UnitTest1 char TestStr[8] = { "Test" }; _itoa_s(i, MULStr, 8); strcat_s(TestStr, MULStr); - int num1 = GetPrivateProfileInt("TestStr", "number1", 0, "ex3.ini"); - int num2 = GetPrivateProfileInt("TestStr", "number2", 0, "ex3.ini"); - int output = GetPrivateProfileInt("TestStr", "output", 0, "ex3.ini"); + int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex3.ini"); + int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex3.ini"); + int e = 0; + bool ret3 = chen(num1, num2, &e); + if (ret3 == 1) + { + int output = GetPrivateProfileInt(TestStr, "output", 0, "..//ex3.ini"); + Assert::AreEqual(output, e); + } + else + { + LPTSTR Output = (LPTSTR)malloc(255); + GetPrivateProfileString(TestStr, "output", "", Output, 255, "..//ex3.ini"); + string s(Output); + Assert::AreEqual(tof(s), chen(num1, num2, &e)); + } - Assert::AreEqual(output, mul(num1, num2)); } } } TEST_METHOD(TestMethod4) { - int DIV = GetPrivateProfileInt("Len", "sum", 0, "../ex4.ini"); + int DIV = GetPrivateProfileInt("Len", "sum", 0, "..//ex4.ini"); { for (int i = 1; i <= DIV; i++) { @@ -80,9 +120,9 @@ namespace UnitTest1 char TestStr[8] = { "Test" }; _itoa_s(i, DIVStr, 8); strcat_s(TestStr, DIVStr); - int num1 = GetPrivateProfileInt("TestStr", "number1", 0, "ex4.ini"); - int num2 = GetPrivateProfileInt("TestStr", "number2", 0, "ex4.ini"); - int output = GetPrivateProfileInt("TestStr", "output", 0, "ex4.ini"); + int num1 = GetPrivateProfileInt(TestStr, "number1", 0, "..//ex4.ini"); + int num2 = GetPrivateProfileInt(TestStr, "number2", 0, "..//ex4.ini"); + int output = GetPrivateProfileInt(TestStr, "output", 0, "../ex4.ini"); Assert::AreEqual(output, chu(num1, num2)); } diff --git a/jia/chen/Source.def b/jia/chen/Source.def index 2808b55..c7aef20 100644 --- a/jia/chen/Source.def +++ b/jia/chen/Source.def @@ -1,4 +1,3 @@ -LIBRARY CHEN +LIBRARY chen EXPORTS -mul chen diff --git a/jia/chen/chen.cpp b/jia/chen/chen.cpp index e1327fb..f2789cb 100644 --- a/jia/chen/chen.cpp +++ b/jia/chen/chen.cpp @@ -1,8 +1,15 @@ #include "chen.h" #include <limits> -bool chen(int a, int b, int *e) + +bool chen(int a, int b, int *e) { - if( (a>0 && b>0 && a >( INT_MAX / b ))||( a<0 && b<0 && a < (INT_MAX / b)) ||( a>0 && b<0 && a < (INT_MIN / b)) ||( a<0 && b>0 && a >( INT_MIN /b) )) + if ((a>0 && b>0 && a >(INT_MAX / b)) || (a<0 && b<0 && a < (INT_MAX / b))) + { + + return false; + } + + else if ((a > 0 && b < 0 && b != -1 && (INT_MIN / a) > b || (a < 0 && b > 0 && a != -1 && (INT_MIN / a) < b))) { return false; @@ -15,8 +22,4 @@ bool chen(int a, int b, int *e) } } -int mul(int a, int b) -{ - return a * b; -} diff --git a/jia/chen/chen.h b/jia/chen/chen.h index b3c7b71..81d6d6c 100644 --- a/jia/chen/chen.h +++ b/jia/chen/chen.h @@ -1,8 +1,7 @@ -#ifndef MUL_H -#define MUL_H +#ifndef CHEN_H +#define CHEN_H -int mul(int a, int b); - bool chen(int a, int b, int *e); +bool chen(int a, int b, int *e); #endif \ No newline at end of file diff --git a/jia/chu/chu.vcxproj b/jia/chu/chu.vcxproj index 0055aec..e1f7237 100644 --- a/jia/chu/chu.vcxproj +++ b/jia/chu/chu.vcxproj @@ -20,7 +20,7 @@ <ConfigurationType>Application</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> <PlatformToolset>v120</PlatformToolset> - <CharacterSet>Unicode</CharacterSet> + <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <ConfigurationType>Application</ConfigurationType> @@ -81,9 +81,11 @@ <ItemGroup> <ClCompile Include="chu.cpp" /> <ClCompile Include="main.cpp" /> + <ClCompile Include="tof.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="chu.h" /> + <ClInclude Include="tof.h" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/jia/chu/chu.vcxproj.filters b/jia/chu/chu.vcxproj.filters index c0c538b..43ec0a2 100644 --- a/jia/chu/chu.vcxproj.filters +++ b/jia/chu/chu.vcxproj.filters @@ -21,10 +21,16 @@ <ClCompile Include="chu.cpp"> <Filter>源文件</Filter> </ClCompile> + <ClCompile Include="tof.cpp"> + <Filter>源文件</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="chu.h"> <Filter>头文件</Filter> </ClInclude> + <ClInclude Include="tof.h"> + <Filter>头文件</Filter> + </ClInclude> </ItemGroup> </Project> \ No newline at end of file diff --git a/jia/chu/main.cpp b/jia/chu/main.cpp index 4116f96..25f490c 100644 --- a/jia/chu/main.cpp +++ b/jia/chu/main.cpp @@ -4,47 +4,79 @@ #include "../jian/jian.h" //#pragma comment(lib,"jian.lib") #include "chu.h" -#include "Windows.h" +#include "windows.h" #include "../chen/chen.h" +#include <iostream> +#include "tof.h" +using namespace std; -typedef int(*PMUL)(int a, int b); typedef bool(*QCHEN)(int a, int b,int *e); + int main() { - + int a, b; int c = 0; int d = 0; int e = 0; - + /*char f = 0; + char *d = &f;*/ printf("��������������\n"); scanf("%d%d", &a, &b); + bool ret1 = Add(a, b,&c); + if ( ret1 == 0) + { + printf("����������ӽ�������\n"); + + } + else + { - printf("ret1=%d a+b=%d\n",ret1,c); + printf("������������ӽ����;%d\n", c); + } + //printf("������������������;%d\n,%d", Sub(a, b, d)); bool ret2 = Sub(a, b, &d); - printf("ret2=%d a-b=%d\n", ret2,d); + if (ret2 == 0) + { + printf("�������������������\n "); + + + } + else + { + printf("������������������;%d\n", d); + } - HMODULE hDLL = LoadLibrary(L"../Debug/chen.dll"); + HMODULE hDLL =LoadLibrary ("../Debug/chen.dll"); if (hDLL == NULL) { printf("����DLL�ļ�ʧ��\n"); return 0; } - PMUL pMul = (PMUL)GetProcAddress(hDLL, "mul"); +// PMUL pMul = (PMUL)GetProcAddress(hDLL, "mul"); QCHEN qChen = (QCHEN)GetProcAddress(hDLL, "chen"); bool ret3 = chen(a, b, &e); - printf("ret3=%d a*b=%d\n", ret3, e); - - printf("a/b=%d\n", chu(a, b)); + if (ret3 == 0) + { + printf("����������˽�������\n "); - FreeLibrary(hDLL); + } + else + { + printf("������������˽����;%d\n", e); + } + + printf("������������������;%d\n", chu(a,b)); + + system("pause"); + FreeLibrary(hDLL); } \ No newline at end of file diff --git a/jia/chu/tof.cpp b/jia/chu/tof.cpp new file mode 100644 index 0000000..1a9efab --- /dev/null +++ b/jia/chu/tof.cpp @@ -0,0 +1,18 @@ +#include "tof.h" + +bool tof(string a) +{ + string b = "false"; + if (a == b) + { + return false; + + } + else + { + return true; + + } + + +} \ No newline at end of file diff --git a/jia/chu/tof.h b/jia/chu/tof.h new file mode 100644 index 0000000..fdd97d8 --- /dev/null +++ b/jia/chu/tof.h @@ -0,0 +1,8 @@ +#ifndef TOF_H +#define TOF_H +#include <iostream> +using namespace std; + +bool tof(string a); + +#endif \ No newline at end of file diff --git a/jia/ex1.ini b/jia/ex1.ini index f90c649..4787eb2 100644 --- a/jia/ex1.ini +++ b/jia/ex1.ini @@ -2,7 +2,7 @@ sum=8 [Test1] -number1=1 +number1 =1 number2=2 output=3 @@ -22,9 +22,9 @@ number2=-2 output=-3 [Test5] -number1=1000 -number2=20000 -output=21000 +number1=2000000000 +number2=2000000000 +output=false [Test6] number1=-1000 @@ -37,6 +37,6 @@ number2=-10 output=2990 [Test8] -number1=100000 -number2=5000000 -output=5100000 \ No newline at end of file +number1=-1000000000 +number2=-2000000000 +output=false \ No newline at end of file diff --git a/jia/ex2.ini b/jia/ex2.ini index aae3649..8a28fc4 100644 --- a/jia/ex2.ini +++ b/jia/ex2.ini @@ -22,9 +22,9 @@ number2=-11 output=2 [Test5] -number1=10000 -number2=2000 -output=8000 +number1=-1000000000 +number2=2000000000 +output=false [Test6] number1=-1 @@ -37,6 +37,6 @@ number2=-10000 output=10300 [Test8] -number1=10000 -number2=500000 -output=-490000 \ No newline at end of file +number1=2000000000 +number2=-2000000000 +output=false \ No newline at end of file diff --git a/jia/ex3.ini b/jia/ex3.ini index 831ee55..d943175 100644 --- a/jia/ex3.ini +++ b/jia/ex3.ini @@ -12,31 +12,31 @@ number2=2 output=-2 [Test3] -number1=1 -number2=-5 -output=-5 +number1=1000000 +number2=50000 +output=false [Test4] -number1=-9 -number2=-11 -output=99 +number1=-9000000 +number2=-11000 +output=false [Test5] -number1=100 -number2=200 -output=20000 +number1=9 +number2=9 +output=81 [Test6] -number1=-10000 -number2=200 -output=-2000000 +number1=-100000 +number2=200000 +output=false [Test7] -number1=300 -number2=-1 -output=-300 +number1=1000000 +number2=-20000 +output=false [Test8] -number1=-11 -number2=-11 -output=121 \ No newline at end of file +number1=2 +number2=2 +output=4 \ No newline at end of file diff --git a/jia/ex4.ini b/jia/ex4.ini index 4ae1105..b854388 100644 --- a/jia/ex4.ini +++ b/jia/ex4.ini @@ -3,8 +3,8 @@ sum=8 [Test1] number1=100 -number2=0 -output=0 +number2=1 +output=100 [Test2] number1=-2 @@ -29,12 +29,12 @@ output=-1 [Test6] number1=-10000 number2=200 -output=-500 +output=-50 [Test7] number1=300 -number2=-1 -output=-300 +number2=0 +output=false [Test8] number1=0 diff --git a/jia/jia/jia.cpp b/jia/jia/jia.cpp index b87e6e4..4f1f4fa 100644 --- a/jia/jia/jia.cpp +++ b/jia/jia/jia.cpp @@ -1,23 +1,19 @@ #include "jia.h" #include <limits> -bool Add(int a, int b, int *c) + +bool Add(int a, int b, int *c) { - if (a>0&&b>0&&a > INT_MAX - b ||a<0&&b<0&& a < INT_MIN - b) - { + if ((a > 0 && b > 0 && a > (INT_MAX - b)) || (a < 0 && b < 0 && a < (INT_MIN - b))) + { return false; } else { *c = a + b; return true; - } - -} -int add(int a, int b) -{ - return a + b; + } diff --git a/jia/jia/jia.h b/jia/jia/jia.h index a4056c5..47f7c1b 100644 --- a/jia/jia/jia.h +++ b/jia/jia/jia.h @@ -1,6 +1,6 @@ #ifndef ADD_H #define ADD_H -bool Add(int a, int b, int *c); -int add(int a, int b); +bool Add(int a, int b,int *c); +//int add(int a,int b); #endif \ No newline at end of file diff --git a/jia/jian/jian.cpp b/jia/jian/jian.cpp index a704a74..809b40a 100644 --- a/jia/jian/jian.cpp +++ b/jia/jian/jian.cpp @@ -1,5 +1,23 @@ #include "jian.h" #include <limits> + +//char Sub(int a, int b, char *d) +//{ +// if ((a>0 && b<0 && a >(INT_MAX + b)) || (a<0 && b>0 && a < (INT_MIN + b))) +// { +// char *c = { "overflow" }; +// *d = c[0]; +// return d[0]; +// } +// else +// { +// d[0] = (a - b) + '0'; +// return d[0]; +// +// } +// +//} + bool Sub(int a, int b, int *d) { if ((a>0 &&b<0 && a >( INT_MAX + b)) ||( a<0 && b>0 && a < (INT_MIN + b))) @@ -15,7 +33,7 @@ bool Sub(int a, int b, int *d) } } -int sub(int a, int b) -{ - return a - b; -} \ No newline at end of file +//int sub(int a, int b) +//{ +// return a - b; +//} \ No newline at end of file diff --git a/jia/jian/jian.h b/jia/jian/jian.h index 1bb7f66..fe90f51 100644 --- a/jia/jian/jian.h +++ b/jia/jian/jian.h @@ -5,7 +5,7 @@ #else #define DLLAPI _declspec(dllimport) #endif -int DLLAPI sub(int a, int b); +//int DLLAPI sub(int a, int b); bool DLLAPI Sub(int a, int b, int *d); - +//char DLLAPI Sub(int a, int b, char *d); #endif \ No newline at end of file