new Queue<>,new QueueTest.cpp,test OK!
This commit is contained in:
parent
008de4cd31
commit
dbf6113742
@ -63,7 +63,7 @@ add_executable(StackTest datatype/StackTest.cpp)
|
||||
cm_example_project("DataType" StackTest)
|
||||
|
||||
add_executable(QueueTest datatype/QueueTest.cpp)
|
||||
cm_example_project("DataType" QueueTest)
|
||||
set_property(TARGET QueueTest PROPERTY FOLDER "CM/Examples/DataType")
|
||||
|
||||
####################################################################################################
|
||||
|
||||
|
@ -38,7 +38,7 @@ add_executable(AndroidDeviceAnalysis AndroidDeviceAnalysis/main.cpp
|
||||
AndroidDeviceAnalysis/GameRecord.h
|
||||
AndroidDeviceAnalysis/GameRecord.cpp
|
||||
AndroidDeviceAnalysis/AndroidDeviceRecord.cpp
|
||||
AndroidDeviceAnalysis/GetDeviceLevel.cpp
|
||||
AndroidDeviceAnalysis/GPUDeviceRecord.cpp
|
||||
# AndroidDeviceAnalysis/ExportReport.cpp
|
||||
${ADA_LOAD_GAME_RECORD_SOURCE})
|
||||
|
||||
|
@ -80,13 +80,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> class TestRawArray:public TestArray<T,RawLifetimeCallback<T>>
|
||||
template<typename T> class TestRawArray:public TestArray<T,DataLifetimeCallback<T>>
|
||||
{
|
||||
RawLifetimeCallback<T> life_cb;
|
||||
DataLifetimeCallback<T> life_cb;
|
||||
|
||||
public:
|
||||
|
||||
TestRawArray():TestArray<T,RawLifetimeCallback<T>>(&life_cb){}
|
||||
TestRawArray():TestArray<T,DataLifetimeCallback<T>>(&life_cb){}
|
||||
~TestRawArray()=default;
|
||||
};
|
||||
|
||||
|
@ -4,8 +4,12 @@
|
||||
using namespace hgl;
|
||||
using namespace std;
|
||||
|
||||
void TestQueue()
|
||||
void TestQueueOrdered()
|
||||
{
|
||||
cout<<endl;
|
||||
cout<<"-----------------------------------------"<<endl;
|
||||
cout<<"Queue Ordered Test"<<endl<<endl;
|
||||
|
||||
Queue<int> tab;
|
||||
int i;
|
||||
|
||||
@ -30,17 +34,110 @@ void TestQueue()
|
||||
cout<<"Queue Count: "<<tab.GetCount()<<endl;
|
||||
}
|
||||
|
||||
void TestQueueUnordered()
|
||||
{
|
||||
cout<<endl;
|
||||
cout<<"-----------------------------------------"<<endl;
|
||||
cout<<"Queue Unordered Test"<<endl<<endl;
|
||||
|
||||
Queue<int> tab;
|
||||
int i;
|
||||
int val;
|
||||
|
||||
for(i=0;i<20;i++)
|
||||
{
|
||||
if(rand()&1)
|
||||
{
|
||||
if(tab.Pop(val))
|
||||
cout<<"pop "<<val<<endl;
|
||||
else
|
||||
cout<<"pop error"<<endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"push "<<i<<endl;
|
||||
|
||||
tab.Push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct UserInfo
|
||||
{
|
||||
char name[32];
|
||||
bool sex;
|
||||
int age;
|
||||
};
|
||||
|
||||
static UserInfo ui_array[]=
|
||||
{
|
||||
//注: 以下人物信息由Github Copilot自动创建
|
||||
//ps: The following list of character information is automatically created by Github Copilot
|
||||
|
||||
{"Adloph",true,18},
|
||||
{"Bella",false,19},
|
||||
{"Cindy",false,20},
|
||||
{"David",true,21},
|
||||
{"Elsa",false,22},
|
||||
{"Frank",true,23},
|
||||
{"Gina",false,24},
|
||||
{"Helen",false,25},
|
||||
{"Ivan",true,26},
|
||||
{"Jack",true,27},
|
||||
{"Kitty",false,28},
|
||||
{"Lily",false,29},
|
||||
{"Mike",true,30},
|
||||
{"Nancy",false,31},
|
||||
{"Owen",true,32},
|
||||
{"Peter",true,33},
|
||||
{"Queen",false,34},
|
||||
{"Robert",true,35},
|
||||
{"Sunny",false,36},
|
||||
{"Tom",true,37},
|
||||
{"Uma",false,38},
|
||||
{"Vivian",false,39},
|
||||
{"Wendy",false,40},
|
||||
{"Xavier",true,41},
|
||||
{"Yoyo",false,42},
|
||||
{"Zack",true,43}
|
||||
};
|
||||
|
||||
void TestQueueStruct()
|
||||
{
|
||||
cout<<endl;
|
||||
cout<<"-----------------------------------------"<<endl;
|
||||
cout<<"Queue Struct Test"<<endl<<endl;
|
||||
|
||||
Queue<UserInfo> ui_queue;
|
||||
|
||||
for(uint i=0;i<sizeof(ui_array)/sizeof(UserInfo);i++)
|
||||
ui_queue.Push(ui_array[i]);
|
||||
|
||||
cout<<"Queue Count: "<<ui_queue.GetCount()<<endl;
|
||||
|
||||
for(uint i=0;i<sizeof(ui_array)/sizeof(UserInfo);i++)
|
||||
{
|
||||
UserInfo ui;
|
||||
|
||||
ui_queue.Pop(ui);
|
||||
|
||||
cout<<i<<": "<<ui.name<<(ui.sex?" male ":" female ")<<ui.age<<" age."<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
class QueueTestObject
|
||||
{
|
||||
int val;
|
||||
|
||||
public:
|
||||
|
||||
QueueTestObject(int v)
|
||||
QueueTestObject(){val=-1;}
|
||||
|
||||
void Set(int v)
|
||||
{
|
||||
val=v;
|
||||
|
||||
cout<<"QueueTestObject "<<val<<endl;
|
||||
cout<<"QueueTestObject::Set "<<val<<endl;
|
||||
}
|
||||
|
||||
~QueueTestObject()
|
||||
@ -51,18 +148,26 @@ public:
|
||||
|
||||
void TestObjectQueue()
|
||||
{
|
||||
cout<<endl;
|
||||
cout<<"-----------------------------------------"<<endl;
|
||||
cout<<"Queue Object Test"<<endl<<endl;
|
||||
|
||||
ObjectQueue<QueueTestObject> tab;
|
||||
|
||||
int i;
|
||||
|
||||
for(i=0;i<10;i++)
|
||||
{
|
||||
tab.Push(new QueueTestObject(i));
|
||||
QueueTestObject *obj=new QueueTestObject;
|
||||
|
||||
obj->Set(i);
|
||||
|
||||
tab.Push(obj);
|
||||
}
|
||||
|
||||
cout<<"Queue Count: "<<tab.GetCount()<<endl;
|
||||
|
||||
for(i=0;i<10;i++)
|
||||
for(i=0;i<5;i++) //只取出5个,剩几个给自动清理处理
|
||||
{
|
||||
QueueTestObject *obj=tab.Pop();
|
||||
|
||||
@ -75,10 +180,16 @@ void TestObjectQueue()
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
TestQueue();
|
||||
srand(time(nullptr));
|
||||
|
||||
cout<<"------------------------"<<endl;
|
||||
//原生单个数据测试
|
||||
TestQueueOrdered();
|
||||
TestQueueUnordered();
|
||||
|
||||
//原生结构体测试
|
||||
TestQueueStruct();
|
||||
|
||||
//对象测试
|
||||
TestObjectQueue();
|
||||
|
||||
return(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user