@@ -56,3 +56,38 @@ Alogrithm/.vs/Alogrithm/v16/Browse.VC.db-wal | |||
Alogrithm/.vs/Alogrithm/v16/Browse.VC.opendb | |||
Alogrithm/.vs/Alogrithm/v16/Solution.VC.db-shm | |||
Alogrithm/.vs/Alogrithm/v16/Solution.VC.db-wal | |||
Alogrithm/TestResults/fb202b31-a40d-4970-8414-add42e85ae22/林_MI-1 2021-01-14 16_23_23.coverage | |||
Alogrithm/UnitTest/Debug/UnitTest.Build.CppClean.log | |||
Alogrithm/UnitTest/Debug/UnitTest.dll.recipe | |||
Alogrithm/UnitTest/Debug/UnitTest.obj | |||
Alogrithm/UnitTest/Debug/UnitTest.vcxproj.FileListAbsolute.txt | |||
Alogrithm/UnitTest/Debug/UnitTest.tlog/link.12728.delete.1.tlog | |||
Alogrithm/UnitTest/Debug/UnitTest.tlog/link.command.1.tlog | |||
Alogrithm/UnitTest/Debug/UnitTest.tlog/link.read.1.tlog | |||
Alogrithm/UnitTest/Debug/UnitTest.tlog/link.write.1.tlog | |||
Alogrithm/UnitTest/Debug/UnitTest.tlog/UnitTest.write.1u.tlog | |||
Alogrithm/TestResults/84c6ace1-133c-41c3-9b02-94db81e6aa3a/林_MI-1 2021-01-14 18_54_25.coverage | |||
Alogrithm/TestResults/8b615f86-7689-4378-a8a0-e09120490e1d/林_MI-1 2021-01-14 15_48_38.coverage | |||
Alogrithm/TestResults/8e613af4-68a7-4f48-8525-48d0cd2c3928/林_MI-1 2021-01-14 18_36_56.coverage | |||
Alogrithm/TestResults/8fda7b28-3ed2-4ea0-bf3c-5a9a28ea695c/林_MI-1 2021-01-14 18_41_23.coverage | |||
Alogrithm/TestResults/a0595beb-6f55-4119-8993-a7004136a5b6/林_MI-1 2021-01-14 15_10_41.coverage | |||
Alogrithm/TestResults/a556f927-382c-4f2c-b2c7-5fe00c31dcb5/林_MI-1 2021-01-14 16_21_32.coverage | |||
Alogrithm/TestResults/c6594eae-705b-4566-9bda-127da6acb938/林_MI-1 2021-01-14 15_15_47.coverage | |||
Alogrithm/TestResults/cce6119d-a3de-446e-95bc-b2f5f83123cb/林_MI-1 2021-01-14 16_22_04.coverage | |||
Alogrithm/TestResults/cee69d67-755c-4b31-8eec-9107e82975bc/林_MI-1 2021-01-14 15_48_01.coverage | |||
Alogrithm/TestResults/e0dd8071-2170-417d-9549-6021400ffa4b/林_MI-1 2021-01-14 18_38_32.coverage | |||
Alogrithm/TestResults/03c6f374-8594-4b77-ba6c-eb0b342ba092/林_MI-1 2021-01-14 16_21_54.coverage | |||
Alogrithm/TestResults/0ff3c1ff-496e-4801-9b05-b4b37d173d29/林_MI-1 2021-01-14 18_35_54.coverage | |||
Alogrithm/TestResults/180d1d1c-2be8-451c-9447-3035ebbc58c3/林_MI-1 2021-01-14 18_54_12.coverage | |||
Alogrithm/TestResults/1ace4913-8399-4b21-ba73-ecb59f5c0e16/林_MI-1 2021-01-14 15_12_41.coverage | |||
Alogrithm/TestResults/327189f3-d0cc-4bd4-baef-11656043e1fb/林_MI-1 2021-01-14 16_22_20.coverage | |||
Alogrithm/TestResults/5e078520-30dd-446b-ae53-875962257cfe/林_MI-1 2021-01-14 16_22_28.coverage | |||
Alogrithm/TestResults/664ef07b-ae35-4d96-9a2b-2ef0e924c550/林_MI-1 2021-01-14 16_21_42.coverage | |||
Alogrithm/TestResults/6b39ec81-5639-4a8b-8905-11278c842fa8/林_MI-1 2021-01-14 18_38_46.coverage | |||
Alogrithm/TestResults/72ff8dca-92fc-4877-b1c8-1aedc3802082/林_MI-1 2021-01-14 15_11_48.coverage | |||
Alogrithm/TestResults/73ea4536-5f55-4a46-991b-139ffea8ade3/林_MI-1 2021-01-14 18_41_17.coverage | |||
Alogrithm/Debug/UnitTest.dll | |||
Alogrithm/Debug/UnitTest.exp | |||
Alogrithm/Debug/UnitTest.ilk | |||
Alogrithm/Debug/UnitTest.lib | |||
Alogrithm/Debug/UnitTest.pdb |
@@ -92,6 +92,7 @@ | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
<GenerateDebugInformation>true</GenerateDebugInformation> | |||
<AdditionalDependencies>../Alogrithm/Debug/2_ExcelSheetColumnTitle.obj;%(AdditionalDependencies)</AdditionalDependencies> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||
@@ -150,6 +151,8 @@ | |||
<ClInclude Include="include\3_bool IsUgly.h" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Include="config\1_ContainsNearbyDuplicate.ini" /> | |||
<None Include="config\2_ExcelSheetColumnTiTle.ini" /> | |||
<None Include="config\3_bool IsUgly.ini" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
@@ -52,5 +52,11 @@ | |||
<None Include="config\3_bool IsUgly.ini"> | |||
<Filter>资源文件\config</Filter> | |||
</None> | |||
<None Include="config\1_ContainsNearbyDuplicate.ini"> | |||
<Filter>资源文件\config</Filter> | |||
</None> | |||
<None Include="config\2_ExcelSheetColumnTiTle.ini"> | |||
<Filter>资源文件\config</Filter> | |||
</None> | |||
</ItemGroup> | |||
</Project> |
@@ -1,11 +1,23 @@ | |||
[Test1] | |||
nums=1,2,3,1 | |||
nExpect=1 | |||
[Test1] | |||
nums=1,0,1,1 | |||
nExpect=1 | |||
array=1,2,3,1 | |||
key=3 | |||
output=1 | |||
[Test2] | |||
array=1,0,1,1 | |||
key=1 | |||
output=1 | |||
[Test3] | |||
nums=1,2,3,1,2,3 | |||
nExpect=0 | |||
array=1,2,3,1,2,3 | |||
key=2 | |||
output=0 | |||
[Test4] | |||
array=1,2,3,1,2,3 | |||
key=3 | |||
output=1 | |||
[Test5] | |||
array=1,0,3,4,2,1,0,3,4 | |||
key=3 | |||
output=0 | |||
@@ -0,0 +1,21 @@ | |||
[Test1] | |||
Na=1 | |||
nExpect=A | |||
[Test2] | |||
Na=2 | |||
nExpect=B | |||
[Test3] | |||
Na=26 | |||
nExpect=Z | |||
[Test4] | |||
Na=1 | |||
nExpect=A | |||
[Test5] | |||
Na=27 | |||
nExpect=AA | |||
[Test6] | |||
Na=52 | |||
nExpect=AZ | |||
[Test7] | |||
Na=53 | |||
nExpect=AAA |
@@ -0,0 +1,15 @@ | |||
[Test1] | |||
Na=6 | |||
nExpect=1 | |||
[Test2] | |||
Na=3 | |||
nExpect=1 | |||
[Test3] | |||
Na=14 | |||
nExpect=0 | |||
[Test4] | |||
Na=15 | |||
nExpect=1 | |||
[Test5] | |||
Na=20 | |||
nExpect=1 |
@@ -3,7 +3,7 @@ | |||
//给定一个整数,返回它在 Excel 表中相对应的列名称,如果在Excel表中找不到该列,则返回""。 | |||
char* ExcelSheetColumnTitle(int n) | |||
{ | |||
char str[STR_LEN] = { 0 }; | |||
static char str[STR_LEN] = { 0 }; | |||
int i = 0; | |||
while (n > 0) { | |||
if ((n > 0) && (n <= 26)) { | |||
@@ -15,6 +15,6 @@ char* ExcelSheetColumnTitle(int n) | |||
n = n - 26; | |||
i++; | |||
} | |||
printf("%s", str); | |||
return str; | |||
char* pstr = str; | |||
return pstr; | |||
} |
@@ -1,18 +1,60 @@ | |||
#include "pch.h" | |||
#include "CppUnitTest.h" | |||
#define FilePath "../Alogrithm/1_ContainsNearbyDuplicate.ini" | |||
using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||
#define FileName_1 "../Alogrithm/config/1_ContainsNearbyDuplicate.ini" | |||
#define FileName_2 "../Alogrithm/config/2_ExcelSheetColumnTiTle.ini" | |||
#define FileName_3 "../Alogrithm/config/3_bool IsUgly.ini" | |||
namespace UnitTest | |||
{ | |||
TEST_CLASS(UnitTest) | |||
TEST_CLASS(UnitTest_1) | |||
{ | |||
public: | |||
TEST_METHOD(TestMethode2) | |||
TEST_METHOD(TestMethode1) | |||
{ | |||
char Section_Name[100][10] = { 0 }; | |||
int Section_Count = CalcCount(100, Section_Name, FileName_1); | |||
int array_count = 0; | |||
int* Section_Value; | |||
CString Na, Nb, nExpect; | |||
for (int i = 0; i < Section_Count; i++) { | |||
GetPrivateProfileString(Section_Name[i], "array", " ", Na.GetBuffer(200), 200, FileName_1); | |||
GetPrivateProfileString(Section_Name[i], "key", " ", Nb.GetBuffer(20), 20, FileName_1); | |||
GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(20), 20, FileName_1); | |||
Section_Value = str_device(Na, &array_count); | |||
bool nReal = ContainsNearbyDuplicate(Section_Value, array_count, _ttoi(Nb)); | |||
Assert::AreEqual(nReal, CstrToBool(nExpect)); | |||
} | |||
} | |||
}; | |||
TEST_CLASS(UnitTest_2) | |||
{ | |||
TEST_METHOD(TestMethode1) | |||
{ | |||
char Section_Name[100][10] = { 0 }; | |||
int Section_Count = CalcCount(100, Section_Name, FileName_2); | |||
CString Na, nExpect; | |||
for (int i = 0; i < Section_Count; i++) { | |||
GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_2); | |||
GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(100), 100, FileName_2); | |||
char* nReal = ExcelSheetColumnTitle(_ttoi(Na)); | |||
Assert::AreEqual(*nReal, *nExpect); | |||
} | |||
} | |||
}; | |||
TEST_CLASS(UnitTest_3) | |||
{ | |||
TEST_METHOD(TestMethode3) | |||
{ | |||
char Section_Name[100][10] = { 0 }; | |||
int Section_Count = CalcCount(100, Section_Name, FileName_3); | |||
CString Na, nExpect; | |||
for (int i = 0; i < Section_Count; i++) { | |||
GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_3); | |||
GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(20), 20, FileName_3); | |||
bool nReal = IsUgly(_ttoi(Na)); | |||
Assert::AreEqual(nReal, CstrToBool(nExpect)); | |||
} | |||
} | |||
}; | |||
} |
@@ -93,13 +93,17 @@ | |||
<WarningLevel>Level3</WarningLevel> | |||
<SDLCheck>true</SDLCheck> | |||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<PreprocessorDefinitions>WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||
<UseFullPaths>true</UseFullPaths> | |||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||
<LanguageStandard>stdcpp14</LanguageStandard> | |||
<LanguageStandard_C>stdc11</LanguageStandard_C> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Windows</SubSystem> | |||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||
<GenerateDebugInformation>DebugFull</GenerateDebugInformation> | |||
<AdditionalDependencies>../Alogrithm/Debug/1_ContainsNearbyDuplicate.obj;../Alogrithm/Debug/2_ExcelSheetColumnTitle.obj;../Alogrithm/Debug/3_bool IsUgly.obj;%(AdditionalDependencies)</AdditionalDependencies> | |||
</Link> | |||
</ItemDefinitionGroup> | |||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||
@@ -1,7 +1,13 @@ | |||
// pch.cpp: 与预编译标头对应的源文件 | |||
#include "pch.h" | |||
int CalcCount(int n, char(*str)[10]) | |||
//***************************************************************************************************// | |||
//********读取ini文件函数,返回值为文件节的个数,入参为字符串数组的首地址,带回读取到的节名***************// | |||
//***************************************************************************************************// | |||
int CalcCount(int n, char(*str)[10],const char *FileName) | |||
{ | |||
TCHAR chSectionNames[2048] = { 0 };//定义一个数组,保存读取节的名字 | |||
char* pSectionName; //保存找到的某个节名字符串的首地址 | |||
@@ -10,7 +16,7 @@ int CalcCount(int n, char(*str)[10]) | |||
int k = 0; //临时变量,用于给str数组赋值 | |||
int m = 0; //临时变量,用于给str数组赋值 | |||
int count = 0; //统计节的个数 | |||
GetPrivateProfileSectionNames(chSectionNames, 2048, "..//ex1.ini");//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||
GetPrivateProfileSectionNames(chSectionNames, 2048, FileName);//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||
//要加头文件 | |||
for (i = 0; i < 2048; i++, j++)//对chSectionName中保存的内容进行拆分 | |||
{ | |||
@@ -29,7 +35,6 @@ int CalcCount(int n, char(*str)[10]) | |||
{ | |||
str[k][m] = *(pSectionName + m); | |||
} | |||
//str[k][++m] = '\0';//手动给节名加上\0,表示这个节名结束 | |||
k++;//变量自加,用来保存下一个节名 | |||
//在获取节名的时候可以获取该节中键的值,前提是我们知道该节中有哪些键。 | |||
if (chSectionNames[i + 1] == 0) | |||
@@ -41,12 +46,19 @@ int CalcCount(int n, char(*str)[10]) | |||
return count;//返回节名的个数 | |||
} | |||
int* str_device(CString* str, int* value_count) | |||
#if 1 | |||
//***************************************************************************************************// | |||
//************切割字符串函数,返回值为int数组的首地址,通过传入int指针带回数组元素个数***************// | |||
//***************************************************************************************************// | |||
int* str_device(CString str, int* value_count) | |||
{ | |||
char* token; //存放被切割后的第一个子串 | |||
static int Section_devide[500];//存放字符切割完成以后的数组元素值 | |||
char Section_value[500] = { 0 };//存放nums转换成string类型的结果 | |||
strcpy(Section_value, *str);//将CString类型的字符串转换成char类型,方便后面切割字符串 | |||
memset(Section_value, 0, sizeof(char) * 500); | |||
*value_count = 0; | |||
strcpy(Section_value, str);//将CString类型的字符串转换成char类型,方便后面切割字符串 | |||
//获得切割到的第一个字符串 | |||
token = strtok(Section_value, ","); | |||
/* 继续获取其他的子字符串 */ | |||
@@ -56,4 +68,13 @@ int* str_device(CString* str, int* value_count) | |||
(*value_count)++; //记录存了多少个元素 | |||
} | |||
return Section_devide; //返回数组首地址 | |||
} | |||
} | |||
#endif | |||
bool CstrToBool(CString str) | |||
{ | |||
if (str == "1") { | |||
return 1; | |||
} | |||
return 0; | |||
} |
@@ -13,9 +13,13 @@ | |||
#include<Windows.h> | |||
#include <atlstr.h> | |||
#include"../Alogrithm/include/1_ContainsNearbyDuplicate.h" | |||
#include"../Alogrithm/include/2_ExcelSheetColumnTitle.h" | |||
#include"../Alogrithm/include/3_bool IsUgly.h" | |||
int CalcCount(int n, char(*str)[10]); | |||
int* str_device(CString* str, int* value_count); | |||
int CalcCount(int n, char(*str)[10],const char *FileName); | |||
int* str_device(CString str, int* value_count); | |||
bool CstrToBool(CString str); | |||
#endif //PCH_H |