added StringMapTest
This commit is contained in:
parent
fe28916336
commit
707710f664
@ -30,12 +30,6 @@ cm_example_project("DataType" StrChrTest)
|
|||||||
add_executable(Uint2StrTest datatype/utos_test.cpp)
|
add_executable(Uint2StrTest datatype/utos_test.cpp)
|
||||||
cm_example_project("DataType" Uint2StrTest)
|
cm_example_project("DataType" Uint2StrTest)
|
||||||
|
|
||||||
add_executable(MapTest datatype/MapTest.cpp)
|
|
||||||
cm_example_project("DataType" MapTest)
|
|
||||||
|
|
||||||
add_executable(MultiMapTest datatype/MultiMapTest.cpp)
|
|
||||||
cm_example_project("DataType" MultiMapTest)
|
|
||||||
|
|
||||||
add_executable(RuntimeAssetManagerTest datatype/ram/RuntimeAssetManagerTest.cpp
|
add_executable(RuntimeAssetManagerTest datatype/ram/RuntimeAssetManagerTest.cpp
|
||||||
datatype/ram/RuntimeAssetManager.h
|
datatype/ram/RuntimeAssetManager.h
|
||||||
datatype/ram/RAM_TestClass.h
|
datatype/ram/RAM_TestClass.h
|
||||||
@ -70,6 +64,9 @@ set_property(TARGET QueueTest PROPERTY FOLDER "CM/Examples/DataType/DataArray")
|
|||||||
add_executable(PoolTest datatype/PoolTest.cpp)
|
add_executable(PoolTest datatype/PoolTest.cpp)
|
||||||
set_property(TARGET PoolTest PROPERTY FOLDER "CM/Examples/DataType/DataArray")
|
set_property(TARGET PoolTest PROPERTY FOLDER "CM/Examples/DataType/DataArray")
|
||||||
|
|
||||||
|
add_executable(MapTest datatype/MapTest.cpp)
|
||||||
|
set_property(TARGET MapTest PROPERTY FOLDER "CM/Examples/DataType/DataArray")
|
||||||
|
|
||||||
####################################################################################################
|
####################################################################################################
|
||||||
|
|
||||||
add_executable(FixFilenameTest filesystem/FixFilenameTest.cpp)
|
add_executable(FixFilenameTest filesystem/FixFilenameTest.cpp)
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include<time.h>
|
#include<time.h>
|
||||||
#include<hgl/type/SortedSets.h>
|
#include<hgl/type/SortedSets.h>
|
||||||
#include<hgl/type/Map.h>
|
#include<hgl/type/Map.h>
|
||||||
|
#include<hgl/type/String.h>
|
||||||
|
#include"UserInfo.h"
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -23,7 +25,7 @@ void out_id(Map<int,int> &int_map)
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
//lambda用法
|
//lambda用法
|
||||||
int_map.Enum([](const int &key,int value)
|
int_map.Enum([](const int &key,int &value)
|
||||||
{
|
{
|
||||||
cout<<"["<<key<<","<<value<<"]";
|
cout<<"["<<key<<","<<value<<"]";
|
||||||
});
|
});
|
||||||
@ -31,8 +33,10 @@ void out_id(Map<int,int> &int_map)
|
|||||||
cout<<endl;
|
cout<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int,char **)
|
void IntMapTest()
|
||||||
{
|
{
|
||||||
|
constexpr const int MAX_COUNT=10;
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
int value;
|
int value;
|
||||||
SortedSets<int> int_sets;
|
SortedSets<int> int_sets;
|
||||||
@ -40,11 +44,11 @@ int main(int,char **)
|
|||||||
|
|
||||||
srand(time(nullptr));
|
srand(time(nullptr));
|
||||||
|
|
||||||
for(int i=0;i<20;i++)
|
for(int i=0;i<MAX_COUNT;i++)
|
||||||
{
|
{
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
index=rand()%20;
|
index=rand()%MAX_COUNT;
|
||||||
if(!int_sets.IsMember(index))break;
|
if(!int_sets.IsMember(index))break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +64,7 @@ int main(int,char **)
|
|||||||
|
|
||||||
cout<<endl;
|
cout<<endl;
|
||||||
|
|
||||||
for(int i=0;i<20;i++)
|
for(int i=0;i<MAX_COUNT;i++)
|
||||||
{
|
{
|
||||||
value=rand()%255;
|
value=rand()%255;
|
||||||
|
|
||||||
@ -69,6 +73,29 @@ int main(int,char **)
|
|||||||
|
|
||||||
out_id(int_map);
|
out_id(int_map);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringMapTest()
|
||||||
|
{
|
||||||
|
Map<UTF8String,UserInfo> ui_map;
|
||||||
|
|
||||||
|
for(auto &ui:user_info_array)
|
||||||
|
ui_map.Add(ui.name,ui);
|
||||||
|
|
||||||
|
ui_map.Enum([](const UTF8String &key,UserInfo &ui)
|
||||||
|
{
|
||||||
|
cout<<"["<<key<<","<<(ui.sex?"male":"female")<<","<<ui.age<<"]"<<endl;
|
||||||
|
});
|
||||||
|
|
||||||
|
cout<<endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int,char **)
|
||||||
|
{
|
||||||
|
IntMapTest();
|
||||||
|
|
||||||
|
StringMapTest();
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ void StructPoolTest()
|
|||||||
|
|
||||||
//添加所有的人物数据到池中
|
//添加所有的人物数据到池中
|
||||||
{
|
{
|
||||||
for(auto ui:ui_array)
|
for(auto ui:user_info_array)
|
||||||
pool.Append(ui);
|
pool.Append(ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ void StructPoolTest()
|
|||||||
int count=10+rand()%10;
|
int count=10+rand()%10;
|
||||||
|
|
||||||
for(int i=0;i<count;i++)
|
for(int i=0;i<count;i++)
|
||||||
pool.Release(ui_array[rand()%26]);
|
pool.Release(user_info_array[rand()%26]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowUserInfoArray(pool.GetActiveArray());
|
ShowUserInfoArray(pool.GetActiveArray());
|
||||||
@ -100,7 +100,7 @@ void ObjectPoolTest()
|
|||||||
|
|
||||||
//添加所有的人物数据到池中
|
//添加所有的人物数据到池中
|
||||||
{
|
{
|
||||||
for(auto ui:ui_array)
|
for(auto ui:user_info_array)
|
||||||
{
|
{
|
||||||
UserInfoClass *uic=new UserInfoClass;
|
UserInfoClass *uic=new UserInfoClass;
|
||||||
|
|
||||||
|
@ -71,12 +71,12 @@ void TestQueueStruct()
|
|||||||
|
|
||||||
Queue<UserInfo> ui_queue;
|
Queue<UserInfo> ui_queue;
|
||||||
|
|
||||||
for(uint i=0;i<sizeof(ui_array)/sizeof(UserInfo);i++)
|
for(uint i=0;i<sizeof(user_info_array)/sizeof(UserInfo);i++)
|
||||||
ui_queue.Push(ui_array[i]);
|
ui_queue.Push(user_info_array[i]);
|
||||||
|
|
||||||
cout<<"Queue Count: "<<ui_queue.GetCount()<<endl;
|
cout<<"Queue Count: "<<ui_queue.GetCount()<<endl;
|
||||||
|
|
||||||
for(uint i=0;i<sizeof(ui_array)/sizeof(UserInfo);i++)
|
for(uint i=0;i<sizeof(user_info_array)/sizeof(UserInfo);i++)
|
||||||
{
|
{
|
||||||
UserInfo ui;
|
UserInfo ui;
|
||||||
|
|
||||||
|
@ -71,12 +71,12 @@ void TestStackStruct()
|
|||||||
|
|
||||||
Stack<UserInfo> ui_queue;
|
Stack<UserInfo> ui_queue;
|
||||||
|
|
||||||
for(uint i=0;i<sizeof(ui_array)/sizeof(UserInfo);i++)
|
for(uint i=0;i<sizeof(user_info_array)/sizeof(UserInfo);i++)
|
||||||
ui_queue.Push(ui_array[i]);
|
ui_queue.Push(user_info_array[i]);
|
||||||
|
|
||||||
cout<<"Stack Count: "<<ui_queue.GetCount()<<endl;
|
cout<<"Stack Count: "<<ui_queue.GetCount()<<endl;
|
||||||
|
|
||||||
for(uint i=0;i<sizeof(ui_array)/sizeof(UserInfo);i++)
|
for(uint i=0;i<sizeof(user_info_array)/sizeof(UserInfo);i++)
|
||||||
{
|
{
|
||||||
UserInfo ui;
|
UserInfo ui;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ struct UserInfo
|
|||||||
int age;
|
int age;
|
||||||
};
|
};
|
||||||
|
|
||||||
static UserInfo ui_array[]=
|
static UserInfo user_info_array[]=
|
||||||
{
|
{
|
||||||
//注: 以下人物信息由Github Copilot自动创建
|
//注: 以下人物信息由Github Copilot自动创建
|
||||||
//ps: The following list of character information is automatically created by Github Copilot
|
//ps: The following list of character information is automatically created by Github Copilot
|
||||||
|
Loading…
x
Reference in New Issue
Block a user