提交 88c92bde 编写于 作者: 邹晓航

update

上级 80293672
#include "BitmapTest.h" //#include "BitmapTest.h"
//
namespace TinySTL{ //namespace TinySTL{
namespace BitmapTest{ // namespace BitmapTest{
void testCase1(){ // void testCase1(){
bitmap<1> bt1; // bitmap<1> bt1;
assert(bt1.size() == 8); // assert(bt1.size() == 8);
//
bitmap<7> bt2; // bitmap<7> bt2;
assert(bt2.size() == 8); // assert(bt2.size() == 8);
//
bitmap<127> bt3; // bitmap<127> bt3;
assert(bt3.size() == 128); // assert(bt3.size() == 128);
} // }
void testCase2(){ // void testCase2(){
bitmap<8> bt1, bt2; // bitmap<8> bt1, bt2;
bt1.set(); // bt1.set();
cout << bt1 << endl; // cout << bt1 << endl;
bt1.reset(); // bt1.reset();
cout << bt1 << endl; // cout << bt1 << endl;
//
bt2.set(0); bt2.set(2); bt2.set(4); // bt2.set(0); bt2.set(2); bt2.set(4);
cout << bt2 << endl; // cout << bt2 << endl;
bt2.reset(0); bt2.reset(2); bt2.reset(4); // bt2.reset(0); bt2.reset(2); bt2.reset(4);
cout << bt2 << endl; // cout << bt2 << endl;
} // }
void testCase3(){ // void testCase3(){
bitmap<8> bt; // bitmap<8> bt;
bt.flip(); // bt.flip();
cout << bt << endl; // cout << bt << endl;
//
bt.flip(0); // bt.flip(0);
cout << bt << endl; // cout << bt << endl;
} // }
void testCase4(){ // void testCase4(){
bitmap<8> bt; // bitmap<8> bt;
bt.set(); // bt.set();
assert(bt.count() == 8); // assert(bt.count() == 8);
//
bt.flip(); // bt.flip();
assert(bt.count() == 0); // assert(bt.count() == 0);
//
bt.set(0); // bt.set(0);
assert(bt.count() == 1); // assert(bt.count() == 1);
} // }
void testCase5(){ // void testCase5(){
bitmap<8> bt; // bitmap<8> bt;
assert(!bt.test(0)); // assert(!bt.test(0));
//
bt.set(0); // bt.set(0);
assert(bt.test(0)); // assert(bt.test(0));
} // }
void testCase6(){ // void testCase6(){
bitmap<8> bt; // bitmap<8> bt;
assert(!bt.any()); // assert(!bt.any());
assert(bt.none()); // assert(bt.none());
assert(!bt.all()); // assert(!bt.all());
//
bt.set(0); // bt.set(0);
assert(bt.any()); // assert(bt.any());
assert(!bt.none()); // assert(!bt.none());
assert(!bt.all()); // assert(!bt.all());
//
bt.set(); // bt.set();
assert(bt.any()); // assert(bt.any());
assert(!bt.none()); // assert(!bt.none());
assert(bt.all()); // assert(bt.all());
//
bt.reset(); // bt.reset();
assert(!bt.any()); // assert(!bt.any());
assert(bt.none()); // assert(bt.none());
assert(!bt.all()); // assert(!bt.all());
} // }
void testCase7(){ // void testCase7(){
bitmap<8> bt; // bitmap<8> bt;
bt.set(0); bt.set(2); bt.set(4); bt.set(6); // bt.set(0); bt.set(2); bt.set(4); bt.set(6);
assert(bt.to_string() == TinySTL::string("10101010")); // assert(bt.to_string() == TinySTL::string("10101010"));
} // }
} // }
} //}
//
using namespace TinySTL::BitmapTest; //using namespace TinySTL::BitmapTest;
int main(){ //int main(){
//testCase1(); // //testCase1();
//testCase2(); // //testCase2();
//testCase3(); // //testCase3();
//testCase4(); // //testCase4();
//testCase5(); // //testCase5();
//testCase6(); // //testCase6();
//testCase7(); // //testCase7();
//
system("pause"); // system("pause");
return 0; // return 0;
} //}
\ No newline at end of file \ No newline at end of file
#include "CircularBufferTest.h" //#include "CircularBufferTest.h"
namespace TinySTL{
namespace CircularBufferTest{
void testCase1(){
tsCB<int, 10> cb1(10, 1);
for (auto i = 0; i != 10; ++i)
assert(cb1[i] == 1);
int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
tsCB<int, 10> cb2(std::begin(arr), std::end(arr));
for (auto i = 0; i != 10; ++i)
assert(cb2[i] == i);
auto cb3(cb2);
assert(circular_buffer_equal(cb2, cb3));
auto cb4(std::move(cb2));//cb2 clear
assert(circular_buffer_equal(cb3, cb4));
auto cb5 = cb3;
assert(circular_buffer_equal(cb3, cb5));
auto cb6 = std::move(cb3);//cb3 clear
assert(circular_buffer_equal(cb5, cb6));
}
void testCase2(){
tsCB<int, 2> cb(1);
assert(cb.size() == 1);
cb.pop_front();
assert(!cb.full());
assert(cb.size() == 0);
assert(cb.empty());
cb.push_back(1), cb.push_back(2);
assert(cb.full());
assert(!cb.empty());
assert(cb.size() == 2);
}
void testCase3(){
tsCB<std::string, 3> cb(3);
cb[0] = "one", cb[1] = "two", cb[2] = "three";
assert(*(cb.first()) == "one" && *(cb.last()) == "three");
assert(cb.front() == "one" && cb.back() == "three");
}
void testCase4(){
tsCB<std::string, 3> cb(1);
assert(cb.front() == std::string());
cb.push_back("zxh"); cb.push_back("jwl");
assert(cb.back() == "jwl");
cb.pop_front();
assert(cb.front() == "zxh");
}
void testCase5(){
tsCB<int, 3> cb1(3), cb2(3);
assert(cb1 == cb2);
assert(!(cb1 != cb2));
cb1[0] = -1;
assert(!(cb1 == cb2));
assert(cb1 != cb2);
}
void testCase6(){
std::string arr[] = { "1", "2", "3" };
tsCB<std::string, 3> cb(std::begin(arr), std::end(arr));
std::cout << cb << std::endl;
}
}
}
//using namespace TinySTL::CircularBufferTest;
//int main(){
// testCase1();
// testCase2();
// testCase3();
// testCase4();
// testCase5();
// testCase6();
// //
// system("pause"); //namespace TinySTL{
// return 0; // namespace CircularBufferTest{
//} // void testCase1(){
\ No newline at end of file // tsCB<int, 10> cb1(10, 1);
// for (auto i = 0; i != 10; ++i)
// assert(cb1[i] == 1);
//
// int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// tsCB<int, 10> cb2(std::begin(arr), std::end(arr));
// for (auto i = 0; i != 10; ++i)
// assert(cb2[i] == i);
//
// auto cb3(cb2);
// assert(circular_buffer_equal(cb2, cb3));
//
// auto cb4(std::move(cb2));//cb2 clear
// assert(circular_buffer_equal(cb3, cb4));
//
// auto cb5 = cb3;
// assert(circular_buffer_equal(cb3, cb5));
//
// auto cb6 = std::move(cb3);//cb3 clear
// assert(circular_buffer_equal(cb5, cb6));
// }
// void testCase2(){
// tsCB<int, 2> cb(1);
// assert(cb.size() == 1);
// cb.pop_front();
// assert(!cb.full());
// assert(cb.size() == 0);
// assert(cb.empty());
//
// cb.push_back(1), cb.push_back(2);
// assert(cb.full());
// assert(!cb.empty());
// assert(cb.size() == 2);
// }
// void testCase3(){
// tsCB<std::string, 3> cb(3);
// cb[0] = "one", cb[1] = "two", cb[2] = "three";
//
// assert(*(cb.first()) == "one" && *(cb.last()) == "three");
//
// assert(cb.front() == "one" && cb.back() == "three");
// }
// void testCase4(){
// tsCB<std::string, 3> cb(1);
// assert(cb.front() == std::string());
//
// cb.push_back("zxh"); cb.push_back("jwl");
// assert(cb.back() == "jwl");
// cb.pop_front();
// assert(cb.front() == "zxh");
// }
// void testCase5(){
// tsCB<int, 3> cb1(3), cb2(3);
// assert(cb1 == cb2);
// assert(!(cb1 != cb2));
//
// cb1[0] = -1;
// assert(!(cb1 == cb2));
// assert(cb1 != cb2);
// }
// void testCase6(){
// std::string arr[] = { "1", "2", "3" };
// tsCB<std::string, 3> cb(std::begin(arr), std::end(arr));
// std::cout << cb << std::endl;
// }
// }
//}
//
////using namespace TinySTL::CircularBufferTest;
////int main(){
//// testCase1();
//// testCase2();
//// testCase3();
//// testCase4();
//// testCase5();
//// testCase6();
////
//// system("pause");
//// return 0;
////}
\ No newline at end of file
#include "PairTest.h" //#include "PairTest.h"
//
namespace TinySTL{ //namespace TinySTL{
namespace PairTest{ // namespace PairTest{
template<class Container1, class Container2> // template<class Container1, class Container2>
static inline bool container_equal(const Container1& pair1, const Container2& pair2){ // static inline bool container_equal(const Container1& pair1, const Container2& pair2){
return (pair1.first == pair2.first && pair1.second == pair2.second); // return (pair1.first == pair2.first && pair1.second == pair2.second);
} // }
void testCase1(){ // void testCase1(){
stdPair<int> p1(5, 5); // stdPair<int> p1(5, 5);
tsPair<int> p2(5, 5); // tsPair<int> p2(5, 5);
assert(container_equal(p1, p2)); // assert(container_equal(p1, p2));
} // }
void testCase2(){ // void testCase2(){
stdPair<int> p1(stdPair<int>(0, 0)); // stdPair<int> p1(stdPair<int>(0, 0));
tsPair<int> p2(tsPair<int>(0, 0)); // tsPair<int> p2(tsPair<int>(0, 0));
assert(container_equal(p1, p2)); // assert(container_equal(p1, p2));
} // }
void testCase3(){ // void testCase3(){
stdPair<std::string> temp1 = std::make_pair(std::string("zxh"), std::string("zxh")); // stdPair<std::string> temp1 = std::make_pair(std::string("zxh"), std::string("zxh"));
stdPair<std::string> p1 = temp1; // stdPair<std::string> p1 = temp1;
//
tsPair<std::string> temp2 = TinySTL::make_pair(std::string("zxh"), std::string("zxh")); // tsPair<std::string> temp2 = TinySTL::make_pair(std::string("zxh"), std::string("zxh"));
tsPair<std::string> p2 = temp2; // tsPair<std::string> p2 = temp2;
//
assert(container_equal(p1, p2)); // assert(container_equal(p1, p2));
} // }
void testCase4(){ // void testCase4(){
TinySTL::pair<int, char> foo(10, 'z'); // TinySTL::pair<int, char> foo(10, 'z');
TinySTL::pair<int, char> bar(90, 'a'); // TinySTL::pair<int, char> bar(90, 'a');
//
//foo and bar are not equal // //foo and bar are not equal
//foo is less than bar // //foo is less than bar
//foo is less than or equal to bar // //foo is less than or equal to bar
if (foo == bar) std::cout << "foo and bar are equal\n"; // if (foo == bar) std::cout << "foo and bar are equal\n";
if (foo != bar) std::cout << "foo and bar are not equal\n"; // if (foo != bar) std::cout << "foo and bar are not equal\n";
if (foo< bar) std::cout << "foo is less than bar\n"; // if (foo< bar) std::cout << "foo is less than bar\n";
if (foo> bar) std::cout << "foo is greater than bar\n"; // if (foo> bar) std::cout << "foo is greater than bar\n";
if (foo <= bar) std::cout << "foo is less than or equal to bar\n"; // if (foo <= bar) std::cout << "foo is less than or equal to bar\n";
if (foo >= bar) std::cout << "foo is greater than or equal to bar\n"; // if (foo >= bar) std::cout << "foo is greater than or equal to bar\n";
} // }
void testCase5(){ // void testCase5(){
TinySTL::pair<int, char> foo(10, 'z'); // TinySTL::pair<int, char> foo(10, 'z');
TinySTL::pair<int, char> bar(90, 'a'); // TinySTL::pair<int, char> bar(90, 'a');
//
foo.swap(bar); // foo.swap(bar);
//
std::cout << "foo : (" << foo.first << ", " << foo.second << ")" << std::endl; // std::cout << "foo : (" << foo.first << ", " << foo.second << ")" << std::endl;
std::cout << "bar : (" << bar.first << ", " << bar.second << ")" << std::endl; // std::cout << "bar : (" << bar.first << ", " << bar.second << ")" << std::endl;
//TinySTL::Test::print_container(foo); // //TinySTL::Test::print_container(foo);
//TinySTL::Test::print_container(bar); // //TinySTL::Test::print_container(bar);
} // }
} // }
} //}
//using namespace TinySTL::PairTest; ////using namespace TinySTL::PairTest;
//int main(){ ////int main(){
// testCase1(); //// testCase1();
// testCase2(); //// testCase2();
// testCase3(); //// testCase3();
// testCase4(); //// testCase4();
// testCase5(); //// testCase5();
// system("pause"); //// system("pause");
// return 0; //// return 0;
//} ////}
\ No newline at end of file \ No newline at end of file
#include "PriorityQueueTest.h" //#include "PriorityQueueTest.h"
//
namespace TinySTL{ //namespace TinySTL{
namespace PriorityQueueTest{ // namespace PriorityQueueTest{
void testCase1(){ // void testCase1(){
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -1, -2, -3 }; // int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -1, -2, -3 };
stdPQ<int> pq1(std::begin(arr), std::end(arr)); // stdPQ<int> pq1(std::begin(arr), std::end(arr));
tsPQ<int> pq2(std::begin(arr), std::end(arr)); // tsPQ<int> pq2(std::begin(arr), std::end(arr));
//
while (!pq1.empty() && !pq2.empty()){ // while (!pq1.empty() && !pq2.empty()){
assert(pq1.top() == pq2.top()); // assert(pq1.top() == pq2.top());
pq1.pop(); pq2.pop(); // pq1.pop(); pq2.pop();
} // }
assert(pq1.empty() && pq2.empty()); // assert(pq1.empty() && pq2.empty());
} // }
void testCase2(){ // void testCase2(){
tsPQ<std::string> pq; // tsPQ<std::string> pq;
assert(pq.empty()); // assert(pq.empty());
//
pq.push("zxh"); // pq.push("zxh");
assert(!pq.empty()); // assert(!pq.empty());
} // }
void testCase3(){ // void testCase3(){
tsPQ<int> pq; // tsPQ<int> pq;
auto i = 1; // auto i = 1;
for (; i != 10; ++i){ // for (; i != 10; ++i){
pq.push(i); // pq.push(i);
assert(pq.size() == i); // assert(pq.size() == i);
} // }
for (i = pq.size(); i != 0; --i){ // for (i = pq.size(); i != 0; --i){
pq.pop(); // pq.pop();
assert(pq.size() == (i - 1)); // assert(pq.size() == (i - 1));
} // }
} // }
void testCase4(){ // void testCase4(){
stdPQ<int> pq1; // stdPQ<int> pq1;
tsPQ<int> pq2; // tsPQ<int> pq2;
//
pq1.push(30); // pq1.push(30);
pq1.push(100); // pq1.push(100);
pq1.push(25); // pq1.push(25);
pq1.push(40); // pq1.push(40);
//
pq2.push(30); // pq2.push(30);
pq2.push(100); // pq2.push(100);
pq2.push(25); // pq2.push(25);
pq2.push(40); // pq2.push(40);
//
while (!pq1.empty() && !pq2.empty()){ // while (!pq1.empty() && !pq2.empty()){
assert(pq1.top() == pq2.top()); // assert(pq1.top() == pq2.top());
pq1.pop(); // pq1.pop();
pq2.pop(); // pq2.pop();
} // }
} // }
void testCase5(){ // void testCase5(){
tsPQ<int> foo, bar; // tsPQ<int> foo, bar;
foo.push(15); foo.push(30); foo.push(10); // foo.push(15); foo.push(30); foo.push(10);
bar.push(101); bar.push(202); // bar.push(101); bar.push(202);
//
assert(foo.size() == 3 && bar.size() == 2); // assert(foo.size() == 3 && bar.size() == 2);
foo.swap(bar); // foo.swap(bar);
assert(foo.size() == 2 && bar.size() == 3); // assert(foo.size() == 2 && bar.size() == 3);
//
TinySTL::swap(foo, bar); // TinySTL::swap(foo, bar);
assert(foo.size() == 3 && bar.size() == 2); // assert(foo.size() == 3 && bar.size() == 2);
} // }
} // }
} //}
//
//using namespace TinySTL::PriorityQueueTest; ////using namespace TinySTL::PriorityQueueTest;
//int main(){ ////int main(){
// testCase1(); //// testCase1();
// testCase2(); //// testCase2();
// testCase3(); //// testCase3();
// testCase4(); //// testCase4();
// testCase5(); //// testCase5();
// system("pause"); //// system("pause");
// return 0; //// return 0;
//} ////}
\ No newline at end of file \ No newline at end of file
#include "QueueTest.h" //#include "QueueTest.h"
//
namespace TinySTL{ //namespace TinySTL{
namespace QueueTest{ // namespace QueueTest{
void testCase1(){ // void testCase1(){
stdQ<int> q1; // stdQ<int> q1;
tsQ<int> q2; // tsQ<int> q2;
//
for (auto i = 0; i != 10; ++i){ // for (auto i = 0; i != 10; ++i){
q1.push(i); // q1.push(i);
q2.push(i); // q2.push(i);
} // }
for (auto i = 0; i != 10; ++i){ // for (auto i = 0; i != 10; ++i){
assert(q1.front() == q2.front()); // assert(q1.front() == q2.front());
q1.pop(); // q1.pop();
q2.pop(); // q2.pop();
} // }
} // }
void testCase2(){ // void testCase2(){
tsQ<int> q1; // tsQ<int> q1;
for (auto i = 0; i != 10; ++i) // for (auto i = 0; i != 10; ++i)
q1.push(i); // q1.push(i);
auto q2(q1); // auto q2(q1);
assert(q1 == q2); // assert(q1 == q2);
assert(!(q1 != q2)); // assert(!(q1 != q2));
} // }
void testCase3(){ // void testCase3(){
tsQ<int> q; // tsQ<int> q;
assert(q.empty()); // assert(q.empty());
assert(q.size() == 0); // assert(q.size() == 0);
//
q.push(10); // q.push(10);
q.push(11); // q.push(11);
assert(!q.empty()); // assert(!q.empty());
assert(q.size() == 2); // assert(q.size() == 2);
} // }
void testCase4(){ // void testCase4(){
tsQ<std::string> q; // tsQ<std::string> q;
q.push("front"); // q.push("front");
q.push("back"); // q.push("back");
//
assert(q.front() == "front"); // assert(q.front() == "front");
assert(q.back() == "back"); // assert(q.back() == "back");
} // }
void testCase5(){ // void testCase5(){
tsQ<int> q1, q2; // tsQ<int> q1, q2;
//
q1.push(1); q1.push(2); q1.push(3); // q1.push(1); q1.push(2); q1.push(3);
q2.push(1); q2.push(2); // q2.push(1); q2.push(2);
//
assert(q1.size() == 3 && q2.size() == 2); // assert(q1.size() == 3 && q2.size() == 2);
q1.swap(q2); // q1.swap(q2);
assert(q1.size() == 2 && q2.size() == 3); // assert(q1.size() == 2 && q2.size() == 3);
TinySTL::swap(q1, q2); // TinySTL::swap(q1, q2);
assert(q1.size() == 3 && q2.size() == 2); // assert(q1.size() == 3 && q2.size() == 2);
} // }
} // }
} //}
//
//using namespace TinySTL::QueueTest; ////using namespace TinySTL::QueueTest;
//int main(){ ////int main(){
// testCase1(); //// testCase1();
// testCase2(); //// testCase2();
// testCase3(); //// testCase3();
// testCase4(); //// testCase4();
// testCase5(); //// testCase5();
// system("pause"); //// system("pause");
// return 0; //// return 0;
//} ////}
\ No newline at end of file \ No newline at end of file
#include "StackTest.h" //#include "StackTest.h"
namespace TinySTL{
namespace StackTest{
void testCase1(){
stdSt<int> st1;
tsSt<int> st2;
for (auto i = 0; i != 10; ++i){
st1.push(i);
st2.push(i);
}
for (auto i = 0; i != 10; ++i){
assert(st1.top() == st2.top());
st1.pop();
st2.pop();
}
}
void testCase2(){
tsSt<std::string> st;
assert(st.empty());
assert(st.size() == 0);
st.push("one");
st.push("two");
assert(!st.empty());
assert(st.size() == 2);
}
void testCase3(){
tsSt<int> st1;
for (auto i = 0; i != 5; ++i)
st1.push(i);
auto st2(st1);
assert(st1 == st2);
assert(!(st1 != st2));
}
void testCase4(){
tsSt<int> st1, st2;
st1.push(1); st1.push(2); st1.push(3);
st2.push(1); st2.push(2);
assert(st1.size() == 3 && st2.size() == 2);
st1.swap(st2);
assert(st1.size() == 2 && st2.size() == 3);
TinySTL::swap(st1, st2);
assert(st1.size() == 3 && st2.size() == 2);
}
}
}
//using namespace TinySTL::StackTest;
//int main(){
// testCase1();
// testCase2();
// testCase3();
// testCase4();
// //
// system("pause"); //namespace TinySTL{
// return 0; // namespace StackTest{
//} // void testCase1(){
\ No newline at end of file // stdSt<int> st1;
// tsSt<int> st2;
//
// for (auto i = 0; i != 10; ++i){
// st1.push(i);
// st2.push(i);
// }
// for (auto i = 0; i != 10; ++i){
// assert(st1.top() == st2.top());
// st1.pop();
// st2.pop();
// }
// }
// void testCase2(){
// tsSt<std::string> st;
// assert(st.empty());
// assert(st.size() == 0);
//
// st.push("one");
// st.push("two");
// assert(!st.empty());
// assert(st.size() == 2);
// }
// void testCase3(){
// tsSt<int> st1;
// for (auto i = 0; i != 5; ++i)
// st1.push(i);
// auto st2(st1);
// assert(st1 == st2);
// assert(!(st1 != st2));
// }
// void testCase4(){
// tsSt<int> st1, st2;
// st1.push(1); st1.push(2); st1.push(3);
// st2.push(1); st2.push(2);
// assert(st1.size() == 3 && st2.size() == 2);
// st1.swap(st2);
// assert(st1.size() == 2 && st2.size() == 3);
// TinySTL::swap(st1, st2);
// assert(st1.size() == 3 && st2.size() == 2);
// }
// }
//}
//
////using namespace TinySTL::StackTest;
////int main(){
//// testCase1();
//// testCase2();
//// testCase3();
//// testCase4();
////
//// system("pause");
//// return 0;
////}
\ No newline at end of file
此差异已折叠。
#include "SuffixArrayTest.h" //#include "SuffixArrayTest.h"
namespace TinySTL{
namespace SuffixArrayTest{
void testCase(){
//char arr[] = { 'a', 'a', 'b', 'a', 'a', 'a', 'a', 'b' };
std::string str("aabaaaab");
//TinySTL::suffix_array sa(arr, 8);
TinySTL::suffix_array sa(str.data(), str.size());
auto sa1 = sa.suffixArray();
auto sa2 = TinySTL::suffix_array::array_type{3, 4, 5, 0, 6, 1, 7, 2};
assert(TinySTL::Test::container_equal(sa1, sa2));
auto ra1 = sa.rankArray();
auto ra2 = TinySTL::suffix_array::array_type{ 3, 5, 7, 0, 1, 2, 4, 6 };
assert(TinySTL::Test::container_equal(ra1, ra2));
auto ha1 = sa.heightArray();
auto ha2 = TinySTL::suffix_array::array_type{ 3, 2, 3, 1, 2, 0, 1 };
assert(TinySTL::Test::container_equal(ha1, ha2));
}
}
}
//using namespace TinySTL::SuffixArrayTest;
//int main(){
// testCase();
// //
// system("pause"); //namespace TinySTL{
// return 0; // namespace SuffixArrayTest{
//} // void testCase(){
\ No newline at end of file // //char arr[] = { 'a', 'a', 'b', 'a', 'a', 'a', 'a', 'b' };
// std::string str("aabaaaab");
//
// //TinySTL::suffix_array sa(arr, 8);
// TinySTL::suffix_array sa(str.data(), str.size());
// auto sa1 = sa.suffixArray();
// auto sa2 = TinySTL::suffix_array::array_type{3, 4, 5, 0, 6, 1, 7, 2};
// assert(TinySTL::Test::container_equal(sa1, sa2));
//
// auto ra1 = sa.rankArray();
// auto ra2 = TinySTL::suffix_array::array_type{ 3, 5, 7, 0, 1, 2, 4, 6 };
// assert(TinySTL::Test::container_equal(ra1, ra2));
//
// auto ha1 = sa.heightArray();
// auto ha2 = TinySTL::suffix_array::array_type{ 3, 2, 3, 1, 2, 0, 1 };
// assert(TinySTL::Test::container_equal(ha1, ha2));
// }
// }
//}
//
////using namespace TinySTL::SuffixArrayTest;
////int main(){
//// testCase();
////
//// system("pause");
//// return 0;
////}
\ No newline at end of file
#include "VectorTest.h" //#include "VectorTest.h"
//
namespace TinySTL{ //namespace TinySTL{
namespace VectorTest{ // namespace VectorTest{
//
void testCase1(){ // void testCase1(){
stdVec<std::string> v1(10, "zxh"); // stdVec<std::string> v1(10, "zxh");
tsVec<std::string> v2(10, "zxh"); // tsVec<std::string> v2(10, "zxh");
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
//
stdVec<std::string> v3(10); // stdVec<std::string> v3(10);
tsVec<std::string> v4(10); // tsVec<std::string> v4(10);
assert(TinySTL::Test::container_equal(v3, v4)); // assert(TinySTL::Test::container_equal(v3, v4));
//
std::array<std::string, 3> arr = { "abc", "def", "ghi" }; // std::array<std::string, 3> arr = { "abc", "def", "ghi" };
stdVec<std::string> v5(std::begin(arr), std::end(arr)); // stdVec<std::string> v5(std::begin(arr), std::end(arr));
tsVec<std::string> v6(std::begin(arr), std::end(arr)); // tsVec<std::string> v6(std::begin(arr), std::end(arr));
assert(TinySTL::Test::container_equal(v5, v6)); // assert(TinySTL::Test::container_equal(v5, v6));
} // }
void testCase2(){ // void testCase2(){
stdVec<int> temp1(10, 0); // stdVec<int> temp1(10, 0);
tsVec<int> temp2(10, 0); // tsVec<int> temp2(10, 0);
//
auto v1(temp1); // auto v1(temp1);
auto v2(temp2); // auto v2(temp2);
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
//
auto v3(std::move(temp1)); // auto v3(std::move(temp1));
auto v4(std::move(temp2)); // auto v4(std::move(temp2));
assert(TinySTL::Test::container_equal(v3, v4)); // assert(TinySTL::Test::container_equal(v3, v4));
//
auto v5 = v1; // auto v5 = v1;
auto v6 = v2; // auto v6 = v2;
assert(TinySTL::Test::container_equal(v5, v6)); // assert(TinySTL::Test::container_equal(v5, v6));
//
auto v7 = std::move(v3); // auto v7 = std::move(v3);
auto v8 = std::move(v4); // auto v8 = std::move(v4);
assert(TinySTL::Test::container_equal(v7, v8)); // assert(TinySTL::Test::container_equal(v7, v8));
} // }
void testCase3(){ // void testCase3(){
tsVec<int> v1, v2; // tsVec<int> v1, v2;
for (int i = 0; i != 100; ++i){ // for (int i = 0; i != 100; ++i){
v1.push_back(i); // v1.push_back(i);
v2.push_back(i); // v2.push_back(i);
} // }
//
assert(v1 == v2); // assert(v1 == v2);
assert(!(v1 != v2)); // assert(!(v1 != v2));
} // }
void testCase4(){ // void testCase4(){
tsVec<int> myvector; // tsVec<int> myvector;
for (int i = 1; i <= 5; i++) myvector.push_back(i); // for (int i = 1; i <= 5; i++) myvector.push_back(i);
//
std::cout << "myvector contains:"; // std::cout << "myvector contains:";
for (tsVec<int>::iterator it = myvector.begin(); it != myvector.end(); ++it) // for (tsVec<int>::iterator it = myvector.begin(); it != myvector.end(); ++it)
std::cout << ' ' << *it; // std::cout << ' ' << *it;
std::cout << '\n'; // std::cout << '\n';
//
std::cout << "myvector contains:"; // std::cout << "myvector contains:";
for (tsVec<int>::const_iterator it = myvector.cbegin(); it != myvector.cend(); ++it) // for (tsVec<int>::const_iterator it = myvector.cbegin(); it != myvector.cend(); ++it)
std::cout << ' ' << *it; // std::cout << ' ' << *it;
std::cout << '\n'; // std::cout << '\n';
} // }
void testCase5(){ // void testCase5(){
tsVec<int> myvector(5); // 5 default-constructed ints // tsVec<int> myvector(5); // 5 default-constructed ints
int i = 0; // int i = 0;
tsVec<int>::reverse_iterator rit = myvector.rbegin(); // tsVec<int>::reverse_iterator rit = myvector.rbegin();
for (; rit != myvector.rend(); ++rit) // for (; rit != myvector.rend(); ++rit)
*rit = ++i; // *rit = ++i;
//
std::cout << "myvector contains:"; // std::cout << "myvector contains:";
for (tsVec<int>::iterator it = myvector.begin(); it != myvector.end(); ++it) // for (tsVec<int>::iterator it = myvector.begin(); it != myvector.end(); ++it)
std::cout << ' ' << *it; // std::cout << ' ' << *it;
std::cout << '\n'; // std::cout << '\n';
std::cout << "myvector contains(reverse order):"; // std::cout << "myvector contains(reverse order):";
for (tsVec<int>::reverse_iterator it = myvector.rbegin(); it != myvector.rend(); ++it) // for (tsVec<int>::reverse_iterator it = myvector.rbegin(); it != myvector.rend(); ++it)
std::cout << ' ' << *it; // std::cout << ' ' << *it;
std::cout << '\n'; // std::cout << '\n';
} // }
void testCase6(){ // void testCase6(){
tsVec<int> v(11, 0); // tsVec<int> v(11, 0);
assert(v.size() == 11); // assert(v.size() == 11);
//
v.resize(5); // v.resize(5);
assert(v.size() == 5); // assert(v.size() == 5);
//
v.resize(20); // v.resize(20);
assert(v.size() == 20); // assert(v.size() == 20);
} // }
void testCase7(){ // void testCase7(){
tsVec<int> v; // tsVec<int> v;
v.reserve(20); // v.reserve(20);
assert(v.capacity() == 20); // assert(v.capacity() == 20);
} // }
void testCase8(){ // void testCase8(){
stdVec<int> v1(10); // stdVec<int> v1(10);
tsVec<int> v2(10); // tsVec<int> v2(10);
for (unsigned i = 0; i < 10; i++){ // for (unsigned i = 0; i < 10; i++){
v1[i] = i; // v1[i] = i;
v2[i] = i; // v2[i] = i;
} // }
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
//
v1.front() = 99; // v1.front() = 99;
v2.front() = 99; // v2.front() = 99;
v1.back() = 100; // v1.back() = 100;
v2.back() = 100; // v2.back() = 100;
//
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
} // }
void testCase9(){ // void testCase9(){
stdVec<int> v1(5); // stdVec<int> v1(5);
tsVec<int> v2(5); // tsVec<int> v2(5);
//
auto p1 = v1.data(); // auto p1 = v1.data();
auto p2 = v2.data(); // auto p2 = v2.data();
*p1 = 10; ++p1; *p1 = 20; p1[2] = 100; // *p1 = 10; ++p1; *p1 = 20; p1[2] = 100;
*p2 = 10; ++p2; *p2 = 20; p2[2] = 100; // *p2 = 10; ++p2; *p2 = 20; p2[2] = 100;
//
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
} // }
void testCase10(){ // void testCase10(){
tsVec<int> foo(3, 100); // three ints with a value of 100 // tsVec<int> foo(3, 100); // three ints with a value of 100
tsVec<int> bar(5, 200); // five ints with a value of 200 // tsVec<int> bar(5, 200); // five ints with a value of 200
//
TinySTL::Test::print_container(foo, "foo"); // TinySTL::Test::print_container(foo, "foo");
TinySTL::Test::print_container(bar, "bar"); // TinySTL::Test::print_container(bar, "bar");
foo.swap(bar); // foo.swap(bar);
TinySTL::Test::print_container(foo, "foo"); // TinySTL::Test::print_container(foo, "foo");
TinySTL::Test::print_container(bar, "bar"); // TinySTL::Test::print_container(bar, "bar");
} // }
void testCase11(){ // void testCase11(){
stdVec<std::string> v1; // stdVec<std::string> v1;
tsVec<std::string> v2; // tsVec<std::string> v2;
//
v1.push_back("hello "); v1.push_back("world"); // v1.push_back("hello "); v1.push_back("world");
v2.push_back("hello "); v2.push_back("world"); // v2.push_back("hello "); v2.push_back("world");
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
//
v1.pop_back(); // v1.pop_back();
v2.pop_back(); // v2.pop_back();
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
} // }
void testCase12(){ // void testCase12(){
stdVec<int> v1; // stdVec<int> v1;
tsVec<int> v2; // tsVec<int> v2;
//
v1.insert(v1.begin(), 0); // v1.insert(v1.begin(), 0);
v2.insert(v2.begin(), 0); // v2.insert(v2.begin(), 0);
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
//
v1.insert(v1.end(), 1); // v1.insert(v1.end(), 1);
v2.insert(v2.end(), 1); // v2.insert(v2.end(), 1);
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
//
v1.insert(v1.begin() + v1.size() / 2, 10, 0); // v1.insert(v1.begin() + v1.size() / 2, 10, 0);
v2.insert(v2.begin() + v2.size() / 2, 10, 0); // v2.insert(v2.begin() + v2.size() / 2, 10, 0);
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
//
int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
v1.insert(v1.end(), std::begin(arr), std::end(arr)); // v1.insert(v1.end(), std::begin(arr), std::end(arr));
v2.insert(v2.end(), std::begin(arr), std::end(arr)); // v2.insert(v2.end(), std::begin(arr), std::end(arr));
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
} // }
void testCase13(){ // void testCase13(){
stdVec<int> v1; // stdVec<int> v1;
tsVec<int> v2; // tsVec<int> v2;
for (int i = 1; i <= 10; i++) { // for (int i = 1; i <= 10; i++) {
v1.push_back(i); // v1.push_back(i);
v2.push_back(i); // v2.push_back(i);
} // }
v1.erase(v1.begin() + 5); // v1.erase(v1.begin() + 5);
v2.erase(v2.begin() + 5); // v2.erase(v2.begin() + 5);
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
//
v1.erase(v1.begin(), v1.begin() + 3); // v1.erase(v1.begin(), v1.begin() + 3);
v2.erase(v2.begin(), v2.begin() + 3); // v2.erase(v2.begin(), v2.begin() + 3);
assert(TinySTL::Test::container_equal(v1, v2)); // assert(TinySTL::Test::container_equal(v1, v2));
} // }
void testCase14(){ // void testCase14(){
tsVec<int> foo(3, 100); // tsVec<int> foo(3, 100);
tsVec<int> bar(2, 200); // tsVec<int> bar(2, 200);
//
assert(!(foo == bar)); // assert(!(foo == bar));
assert(foo != bar); // assert(foo != bar);
} // }
} // }
} //}
//
//using namespace TinySTL::VectorTest; ////using namespace TinySTL::VectorTest;
//int main(){ ////int main(){
// //testCase1(); //// //testCase1();
// //testCase2(); //// //testCase2();
// //testCase3(); //// //testCase3();
// //testCase4(); //// //testCase4();
// //testCase5(); //// //testCase5();
// //testCase6(); //// //testCase6();
// //testCase7(); //// //testCase7();
// //testCase8(); //// //testCase8();
// //testCase9(); //// //testCase9();
// //testCase10(); //// //testCase10();
// //testCase11(); //// //testCase11();
// //testCase12(); //// //testCase12();
// //testCase13(); //// //testCase13();
// //testCase14(); //// //testCase14();
// system("pause"); //// system("pause");
// return 0; //// return 0;
//} ////}
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册