添加测试用例
This commit is contained in:
@@ -2,6 +2,78 @@
|
|||||||
|
|
||||||
namespace TinySTL{
|
namespace TinySTL{
|
||||||
namespace PriorityQueueTest{
|
namespace PriorityQueueTest{
|
||||||
|
void testCase1(){
|
||||||
|
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -1, -2, -3 };
|
||||||
|
stdPQ<int> pq1(std::begin(arr), std::end(arr));
|
||||||
|
tsPQ<int> pq2(std::begin(arr), std::end(arr));
|
||||||
|
|
||||||
|
while (!pq1.empty() && !pq2.empty()){
|
||||||
|
assert(pq1.top() == pq2.top());
|
||||||
|
pq1.pop(); pq2.pop();
|
||||||
|
}
|
||||||
|
assert(pq1.empty() && pq2.empty());
|
||||||
|
}
|
||||||
|
void testCase2(){
|
||||||
|
tsPQ<std::string> pq;
|
||||||
|
assert(pq.empty());
|
||||||
|
|
||||||
|
pq.push("zxh");
|
||||||
|
assert(!pq.empty());
|
||||||
|
}
|
||||||
|
void testCase3(){
|
||||||
|
tsPQ<int> pq;
|
||||||
|
auto i = 1;
|
||||||
|
for (; i != 10; ++i){
|
||||||
|
pq.push(i);
|
||||||
|
assert(pq.size() == i);
|
||||||
|
}
|
||||||
|
for (i = pq.size(); i != 0; --i){
|
||||||
|
pq.pop();
|
||||||
|
assert(pq.size() == (i - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void testCase4(){
|
||||||
|
stdPQ<int> pq1;
|
||||||
|
tsPQ<int> pq2;
|
||||||
|
|
||||||
|
pq1.push(30);
|
||||||
|
pq1.push(100);
|
||||||
|
pq1.push(25);
|
||||||
|
pq1.push(40);
|
||||||
|
|
||||||
|
pq2.push(30);
|
||||||
|
pq2.push(100);
|
||||||
|
pq2.push(25);
|
||||||
|
pq2.push(40);
|
||||||
|
|
||||||
|
while (!pq1.empty() && !pq2.empty()){
|
||||||
|
assert(pq1.top() == pq2.top());
|
||||||
|
pq1.pop();
|
||||||
|
pq2.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void testCase5(){
|
||||||
|
tsPQ<int> foo, bar;
|
||||||
|
foo.push(15); foo.push(30); foo.push(10);
|
||||||
|
bar.push(101); bar.push(202);
|
||||||
|
|
||||||
|
assert(foo.size() == 3 && bar.size() == 2);
|
||||||
|
foo.swap(bar);
|
||||||
|
assert(foo.size() == 2 && bar.size() == 3);
|
||||||
|
|
||||||
|
TinySTL::swap(foo, bar);
|
||||||
|
assert(foo.size() == 3 && bar.size() == 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//using namespace TinySTL::PriorityQueueTest;
|
||||||
|
//int main(){
|
||||||
|
// testCase1();
|
||||||
|
// testCase2();
|
||||||
|
// testCase3();
|
||||||
|
// testCase4();
|
||||||
|
// testCase5();
|
||||||
|
// system("pause");
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
@@ -6,7 +6,9 @@
|
|||||||
#include "../Queue.h"
|
#include "../Queue.h"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace TinySTL{
|
namespace TinySTL{
|
||||||
namespace PriorityQueueTest{
|
namespace PriorityQueueTest{
|
||||||
@@ -14,6 +16,12 @@ namespace TinySTL{
|
|||||||
using stdPQ = std::priority_queue < T > ;
|
using stdPQ = std::priority_queue < T > ;
|
||||||
template<class T>
|
template<class T>
|
||||||
using tsPQ = TinySTL::priority_queue < T > ;
|
using tsPQ = TinySTL::priority_queue < T > ;
|
||||||
|
|
||||||
|
void testCase1();
|
||||||
|
void testCase2();
|
||||||
|
void testCase3();
|
||||||
|
void testCase4();
|
||||||
|
void testCase5();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user