TEST(NAME, OPERATOR_GREATER_THAN) { Stack<int> stk1(10); Stack<int> stk2(10); for (size_t i = 0; i < 10; ++i) { stk1.push(i * i); stk2.push(i); } EXPECT_EQ(false, stk1 > stk2); }
TEST(NAME, OPERATOR_GREATER_OR_EQUAL_TO) { Stack<int> stk1(10); Stack<int> stk2(10); for (size_t i = 0; i < 10; ++i) { stk1.push(i * i); stk2.push(i); } EXPECT_EQ(true, stk1 >= stk2); }
TEST(NAME, OPERATOR_PLUS) { Stack<int> stk1(10); Stack<int> stk2(10); stk1.push(1); stk2.push(3); Stack<int> stk3 = stk1 + stk2; EXPECT_EQ(1, stk1.peek()); EXPECT_EQ(3, stk3.peek()); EXPECT_EQ(2, stk3.getSize()); }
TEST(NAME, OPERATOR_LESS_OR_EQUAL_TO) { Stack<int> stk1(10); Stack<int> stk2(10); for (size_t i = 0; i < 10; ++i) { stk1.push(i * i); stk2.push(i); } EXPECT_EQ(false, stk1 <= stk2); }
TEST(NAME, COPY) { Stack<int> stk1(10); Stack<int> stk2(2); Stack<int> stk3(1); for (size_t i = 0; i < 10; ++i) { stk1.push(i); } stk2 = stk1; stk3.copy(stk2); EXPECT_EQ(true, stk2.peek() == stk1.peek()); EXPECT_EQ(true, stk3.peek() == stk1.peek()); }
void fun2(mystack<std::function<bool()>>& stk) { bool done = false; int itr = 0; while (!done) { mystack<std::function<bool()>> stk2(stk); std::mutex mtx; std::unique_lock<std::mutex> lck(mtx); stk.not_empty.wait(lck, [&](){ return !stk.empty(); }); // On prend le premier élement auto msg = stk.top(); stk.pop(); // Tu fais ton traitement avec 'msg' et tu mets à jour 'done' std::cout << "fun2: " + std::to_string(itr)+"\n"; ++itr; done = msg(); // par exemple } }
TEST(NAME, OPERATOR_EQUAL_TO) { Stack<int> stk1(10); Stack<int> stk2(10); EXPECT_EQ(true, stk1 == stk2); for (size_t i = 0; i < 5; ++i) { stk1.push(i); stk2.push(i); } EXPECT_EQ(true, stk1 == stk2); stk2.pop(); EXPECT_EQ(false, stk1 == stk2); EXPECT_EQ(false, stk1.equals(stk2)); stk2.pop(); stk1.pop(2); EXPECT_EQ(true, stk1 == stk2); EXPECT_EQ(true, stk1.equals(stk2)); }
void main() { Stack stk; Stack stk2(10); int counter = 0; stk.Push(10.0); stk.Push(20.0); std::cout << "Element of stk" << stk.Pop() << std::endl; for(counter = 0; counter < 10; counter++) { stk2.Push(counter); } for(counter = 0; counter < 10; counter++) { std::cout << "Element : " << stk2.Pop() << std::endl; } }
TEST(NAME, SHRINK) { Stack<int> stk1(5); for (size_t i = 1; i < 6; ++i) { stk1.push(i); } stk1.shrink(3); EXPECT_EQ(3, stk1.peek()); Stack<int> stk2(10); for (size_t i = 1; i < 11; ++i) { stk2.push(i); } for (int32 i = 4; i >= 1; --i) { stk2.resize(i); EXPECT_EQ(i, stk2.peek()); EXPECT_EQ(i, stk2.getMaxSize()); EXPECT_EQ(i, stk2.getSize()); } }
TEST(NAME, SWAP) { Stack<int> stk1(10); Stack<int> stk2(10); for (size_t i = 1; i < 11; ++i) { if (i % 2 == 0) { stk1.push(i); } if (i % 3 == 0) { stk2.push(i); } } std::cout << stk1 << std::endl; std::cout << stk2 << std::endl; stk1.swap(stk2); std::cout << stk1 << std::endl; std::cout << stk2 << std::endl; EXPECT_EQ(10, stk2.peek()); EXPECT_EQ(9, stk1.peek()); }