Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////// SHARED PTR
- class OtchemOx {
- public:
- OtchemOx(int F) {
- ponchik = F;
- }
- bool operator==(OtchemOx f) const {
- return f.ponchik == ponchik;
- }
- bool operator!=(OtchemOx f) const {
- return f.ponchik != ponchik;
- }
- bool operator==(int f) const {
- return f == ponchik;
- }
- bool operator!=(int f) const {
- return f != ponchik;
- }
- int ponchik{};
- };
- TEST(globalTests, All) {
- OtchemOx d(4);
- OtchemOx x(4);
- std::cout << (d == x);
- while (true) {
- SharedPtr<OtchemOx> x(new OtchemOx(24));
- OtchemOx* x2(new OtchemOx(23));
- SharedPtr<OtchemOx> sss(new OtchemOx(3));
- ASSERT_TRUE(*sss == 3);
- // Construct + release
- {
- SharedPtr<OtchemOx> c;
- SharedPtr<OtchemOx> g(new OtchemOx(5));
- SharedPtr<OtchemOx> f(x);
- {
- SharedPtr<OtchemOx> f2(x2);
- f2.Release();
- //ASSERT_TRUE(f2.Get() == nullptr);
- }
- SharedPtr<OtchemOx> sss2(sss);
- SharedPtr<OtchemOx> sss3(sss);
- SharedPtr<OtchemOx> sss4(sss);
- ASSERT_TRUE(sss2 == sss3);
- ASSERT_FALSE(sss2 != sss3);
- }
- // !!!!!!!!!!!!! x need to be deleted
- ASSERT_TRUE(*x2 == 23);
- delete (x2);
- ASSERT_TRUE(*(sss.Get()) ==3);
- ASSERT_TRUE((*sss) == 3);
- // // = = = = Shared
- SharedPtr<OtchemOx> hoba;
- const SharedPtr<OtchemOx> zoba(hoba); // !?
- SharedPtr<OtchemOx> boba(hoba); // !?
- boba = zoba;
- const SharedPtr<OtchemOx> cobra(new OtchemOx(41));
- boba = cobra;
- ASSERT_TRUE(*cobra.Get() == 41);
- {
- boba.Release();
- SharedPtr<OtchemOx> novaya(new OtchemOx(43));
- ASSERT_TRUE ((*novaya) == 43 && *(novaya.Get()) == 43);
- const SharedPtr<OtchemOx> novaya2(new OtchemOx(44));
- ASSERT_TRUE ((*novaya2) == 44 && *(novaya2.Get()) == 44);
- const SharedPtr<OtchemOx>* novaya4 = &novaya2;
- }
- OtchemOx* ccc = new OtchemOx(44);
- const SharedPtr<OtchemOx> skolko_mojno(ccc);
- ASSERT_TRUE (ccc == skolko_mojno);
- SharedPtr<OtchemOx> tttt;
- tttt = skolko_mojno;
- tttt = boba;
- OtchemOx* ppp = new OtchemOx(4);
- SharedPtr<OtchemOx> xxxxx(ppp);
- SharedPtr<OtchemOx> fuf(std::move(xxxxx));
- SharedPtr<OtchemOx> xxe;
- xxe = std::move(fuf);
- ASSERT_TRUE(xxe.Get() == ppp);
- }
- }
- ////////////////////////////////////////////////// CONTAINER
- class OtchemOx {
- public:
- OtchemOx(int F) {
- ponchik = F;
- }
- bool operator==(OtchemOx f) const {
- return f.ponchik == ponchik;
- }
- bool operator!=(OtchemOx f) const {
- return f.ponchik != ponchik;
- }
- bool operator==(int f) const {
- return f == ponchik;
- }
- bool operator!=(int f) const {
- return f != ponchik;
- }
- int ponchik{};
- };
- TEST(MyTests, cont) {
- std::vector<OtchemOx> few;
- few.reserve(4);
- while (true) {
- BiDirectionalList<OtchemOx> z{1, 2, 3};
- z = z;
- BiDirectionalList<OtchemOx> pushHere{};
- // PushFront PopFront
- pushHere.PushFront(1);
- ASSERT_TRUE(pushHere.Front()->value == 1);
- pushHere.PushFront(2);
- ASSERT_TRUE(pushHere.Front()->value == 2);
- ASSERT_TRUE(pushHere.Back()->value == 1);
- ASSERT_TRUE(pushHere.Size() == 2);
- pushHere.PopFront();
- ASSERT_TRUE(pushHere.Size() == 1);
- pushHere.PopFront();
- ASSERT_TRUE(pushHere.Size() == 0);
- // constructor
- const BiDirectionalList<OtchemOx> okey{};
- const BiDirectionalList<OtchemOx> okey2;
- BiDirectionalList<OtchemOx> ktoProchelTotNeSdoxnet{1, 2};
- const std::initializer_list<OtchemOx> of{1, 2};
- BiDirectionalList<OtchemOx> ktoProchelTotNeSdoxnet2{of};
- ASSERT_TRUE(*of.begin() == ktoProchelTotNeSdoxnet2.Front()->value);
- ASSERT_TRUE(*of.begin() == ktoProchelTotNeSdoxnet.Front()->value);
- for (int i = 0; i < 100000; i++) {
- BiDirectionalList<OtchemOx> fe;
- fe.PushBack(OtchemOx(1));
- }
- ASSERT_TRUE(ktoProchelTotNeSdoxnet.Size() == 2);
- ktoProchelTotNeSdoxnet.PushBack(1);
- ASSERT_TRUE(ktoProchelTotNeSdoxnet.Size() == 3);
- ktoProchelTotNeSdoxnet.PopFront();
- ASSERT_TRUE(ktoProchelTotNeSdoxnet.Size() == 2);
- ktoProchelTotNeSdoxnet.PopBack();
- ASSERT_TRUE(ktoProchelTotNeSdoxnet.Size() == 1);
- ktoProchelTotNeSdoxnet.PushBack(123);
- ASSERT_TRUE(ktoProchelTotNeSdoxnet.Size() == 2);
- ktoProchelTotNeSdoxnet.PushFront(0);
- ASSERT_TRUE(ktoProchelTotNeSdoxnet.Size() == 3);
- // PushFront PushBack
- {
- BiDirectionalList<OtchemOx> f;
- for (int i = 0; i < 100; i++) {
- f.PushFront(i);
- f.PushBack(i + 1);
- ASSERT_TRUE(f.Back()->value == i + 1);
- ASSERT_TRUE(f.Front()->value == i);
- ASSERT_TRUE(f.Size() == i * 2 + 2);
- }
- }
- // Front Back []
- {
- BiDirectionalList<OtchemOx> x1{12, 32};
- const BiDirectionalList<OtchemOx> x2(x1);
- BiDirectionalList<OtchemOx> x3(x2);
- ASSERT_TRUE(x3.Back()->value == 32);
- ASSERT_TRUE(x2.Back()->value == 32);
- ASSERT_TRUE(x1.Back()->value == 32);
- ASSERT_TRUE(x3[1]->value == 32);
- ASSERT_TRUE(x2[1]->value == 32);
- ASSERT_TRUE(x1[1]->value == 32);
- ASSERT_TRUE(x3.Front()->value == 12);
- ASSERT_TRUE(x2.Front()->value == 12);
- ASSERT_TRUE(x1.Front()->value == 12);
- ASSERT_TRUE(x3[0]->value == 12);
- ASSERT_TRUE(x2[0]->value == 12);
- ASSERT_TRUE(x1[0]->value == 12);
- ASSERT_TRUE(x1.Size() == 2);
- ASSERT_TRUE(x2.Size() == 2);
- ASSERT_TRUE(x3.Size() == 2);
- x1.PopBack();
- x3.PopBack();
- ASSERT_TRUE(x1.Size() == 1);
- ASSERT_TRUE(x3.Size() == 1);
- ASSERT_TRUE(
- x3[0]->value == x3.Back()->value
- && x3.Front()->value == x3[0]->value);
- ASSERT_TRUE(
- x1[0]->value == x1.Back()->value
- && x1.Front()->value == x1[0]->value);
- x1.PopBack();
- x3.PopBack();
- // ASSERT_ANY_THROW(x1[0]);
- //ASSERT_ANY_THROW(x1[-1]);
- // ASSERT_ANY_THROW(x1[100000]);
- // ASSERT_ANY_THROW(x1.Back());
- // ASSERT_ANY_THROW(x1.Front());
- ASSERT_TRUE(x1.Size() == 0);
- ASSERT_TRUE(x3.Size() == 0);
- }
- // Remove Random|Front|Back element in List
- {
- BiDirectionalList<OtchemOx> xerox{1, 2, 3};
- // ASSERT_ANY_THROW(xerox[4]);
- ASSERT_TRUE(xerox[1]->value == 2);
- ASSERT_TRUE(xerox[0]->value == 1);
- ASSERT_TRUE(xerox[2]->value == 3);
- ASSERT_TRUE(xerox.Size() == 3);
- xerox.PushBack(4);
- xerox.PushFront(0); // 1 3
- xerox.Erase(xerox[2]);
- ASSERT_TRUE(xerox[2]->value == 3);
- ASSERT_TRUE(xerox.Size() == 4);
- xerox.Erase(xerox.Front());
- ASSERT_TRUE(xerox[0]->value == 1);
- ASSERT_TRUE(xerox.Size() == 3);
- xerox.Erase(xerox.Back());
- ASSERT_TRUE(xerox[1]->value == 3);
- ASSERT_TRUE(xerox.Size() == 2);
- xerox.PopBack();
- ASSERT_TRUE(xerox.Size() == 1);
- ASSERT_TRUE(xerox.Back() == xerox.Front());
- xerox.PushBack(2);
- ASSERT_TRUE(xerox.Size() == 2);
- ASSERT_TRUE(xerox[0]->value == 1 && xerox[1]->value == 2);
- xerox.PopBack();
- ASSERT_TRUE(xerox.Back() == xerox.Front());
- ASSERT_TRUE(xerox.Size() == 1);
- xerox.Erase(xerox.Front());
- }
- // FindAll
- {
- BiDirectionalList<OtchemOx> oso{0,1, 2, 3, 4, 5, 6};
- for (int i = 0; i < 7; i++) {
- OtchemOx xs(i);
- std::vector<int> All = oso.FindAll(xs);
- ASSERT_TRUE(All[0] == i);
- ASSERT_TRUE(oso.Size() == 7);
- }
- oso[0]->value = oso[1]->value = oso[2]->value = oso[4]->value =
- oso[5]->value = oso[6]->value;
- std::vector<int> All = oso.FindAll(6);
- ASSERT_THAT(All, testing::ElementsAre(0, 1, 2, 4, 5, 6));
- ASSERT_TRUE(oso.Size() == 7);
- }
- // To vector + == + =
- {
- std::initializer_list<OtchemOx> d = {0, 1, 2, 3, 4};
- std::vector<OtchemOx> f(d);
- BiDirectionalList<OtchemOx> xer(d);
- ASSERT_TRUE(xer.ToVector() == f);
- ASSERT_TRUE(xer.Size() == d.size());
- BiDirectionalList<OtchemOx> dq(std::move(xer));
- ASSERT_TRUE(xer.Size() == 0);
- ASSERT_TRUE(dq.Size() == 5);
- ASSERT_TRUE(dq.Size() == d.size());
- }
- // Find +InsertBefore after
- {
- std::initializer_list<OtchemOx>
- d = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
- std::vector<OtchemOx> f(d);
- BiDirectionalList<OtchemOx> xer(d);
- for (int i = 0; i < 15; i++) {
- ASSERT_TRUE(xer.Find(i) == i && d.size() == xer.Size());
- }
- BiDirectionalList<OtchemOx> opra{0};
- ASSERT_THAT(opra.ToVector(), testing::ElementsAre(0));
- opra.InsertBefore(opra[0], 1);
- ASSERT_THAT(opra.ToVector(), testing::ElementsAre(1, 0));
- opra.InsertBefore(opra[1], 2);
- ASSERT_THAT(opra.ToVector(), testing::ElementsAre(1, 2, 0));
- opra.InsertAfter(opra[1], 3);
- ASSERT_THAT(opra.ToVector(), testing::ElementsAre(1, 2, 3, 0));
- opra.InsertAfter(opra[3], 5);
- ASSERT_THAT(opra.ToVector(), testing::ElementsAre(1, 2, 3, 0, 5));
- opra.InsertBefore(opra[4], 2);
- ASSERT_THAT(opra.ToVector(), testing::ElementsAre(1, 2, 3, 0, 2, 5));
- }
- // Stack
- {
- Container<OtchemOx> ff1;
- Container<OtchemOx> ff2{};
- Container<OtchemOx> ff3{1, 2, 3, 4};
- ASSERT_TRUE(ff1.Size() == ff2.Size());
- ASSERT_TRUE(ff3.Size() == 4);
- ff3.Push(5);
- ff3.Push(6);
- ASSERT_TRUE(ff3.Size() == 6);
- for (int i = 0; i < 6; i++) {
- ASSERT_TRUE(ff3.Get() == 6 - i);
- ASSERT_TRUE(ff3.Size() == 6 - i);
- ff3.Pop();
- }
- Container<OtchemOx> x1{1, 2, 3};
- Container<OtchemOx> x2{1, 2};
- Container<OtchemOx> x3{1, 2, 3, 4};
- ASSERT_FALSE(x1 == x2);
- ASSERT_FALSE(x2 == x3);
- ASSERT_FALSE(x1 == x3);
- ASSERT_FALSE(x1 != x1);
- x2.Push(3);
- x3.Pop();
- ASSERT_TRUE(x1 == x2);
- ASSERT_TRUE(x1 == x3);
- ASSERT_TRUE(x3 == x1);
- }
- // Const
- const BiDirectionalList<OtchemOx> f;
- BiDirectionalList<OtchemOx> f1{};
- BiDirectionalList<OtchemOx> f3{1, 2, 3, 4};
- const std::initializer_list<OtchemOx> x = {1, 2, 3};
- BiDirectionalList<OtchemOx> f4(x);
- std::initializer_list<OtchemOx> x1 = {1, 2, 3};
- BiDirectionalList<OtchemOx> f5(x1);
- const BiDirectionalList<OtchemOx> opa(f5);
- BiDirectionalList<OtchemOx> opa2(opa);
- const BiDirectionalList<OtchemOx>& opa3(std::move(opa2));
- ASSERT_TRUE(f5.Size() != f.Size() && f.IsEmpty());
- const OtchemOx zzzz = 2;
- f1.PushFront(zzzz);
- f1.PushBack(zzzz);
- ASSERT_TRUE(f1.Back()->value == f1.Front()->value);
- ASSERT_TRUE (opa.Front() != opa.Back());
- f1.PopBack();
- f1.PopFront();
- std::cout << (f1.Size() == 0);
- const std::vector<OtchemOx> buka = opa.ToVector();
- const std::vector<int> buka2 = opa.FindAll(zzzz);
- opa2 = opa;
- opa2[1];
- opa[1];
- opa2.InsertBefore(opa2.Back(), zzzz);
- opa2.InsertBefore(opa2.Front(), zzzz);
- opa2.InsertAfter(opa2.Front(), zzzz);
- opa2.InsertAfter(opa2.Back(), zzzz);
- opa2.InsertAfter(opa2[0], zzzz);
- while (!opa2.IsEmpty()) { opa2.Erase(opa2[0]); }
- ASSERT_TRUE (opa2 == f1 && f1 == opa2);
- f1 = opa;
- f1 = opa2;
- const Container<OtchemOx> skoka;
- const std::initializer_list<OtchemOx> f42{12, 433};
- Container<OtchemOx> dota(f42);
- Container<OtchemOx> dota2(f42);
- const Container<OtchemOx> doka(f42);
- const int dudochka = 4;
- int sudochka = 4;
- dota.Push(dudochka);
- dota.Push(sudochka);
- dota.Push(std::move(sudochka));
- dota.Pop();
- ASSERT_TRUE(doka.Get() == 433 || doka.Get() == 12);
- doka.Size();
- doka.IsEmpty();
- ASSERT_TRUE(dota != dota2 && !(dota2 == dota));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement