/*! * \file queue.cpp * \brief * Unit tests for queue * * \copyright Copyright (C) 2020 Christos Choutouridis * *
License
* The MIT License (MIT) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. *
* */ #include #include namespace Tqueue { using namespace tbx; // Test construction TEST(Tqueue, contruct) { queue q1; queue q2{1, 2, 3, 4, 5, 6, 7, 8}; EXPECT_EQ (8UL, q1.capacity()); EXPECT_EQ (8UL, q2.capacity()); } // simple push-pop functionality TEST(Tqueue, base_class) { queue q1; // Access of base class functionality EXPECT_EQ (8UL, q1.capacity()); EXPECT_EQ (0UL, q1.size()); EXPECT_EQ (true, q1.empty()); EXPECT_EQ (false, q1.full()); q1.push_back(7); EXPECT_EQ (7, q1.front()); EXPECT_EQ (7, q1.back()); EXPECT_EQ (7, q1.pop_front()); q1.push_front(42); EXPECT_EQ (42, q1.front()); EXPECT_EQ (42, q1.back()); EXPECT_EQ (42, q1.pop_back()); q1.push_back(1); q1.push_back(2); q1.push_back(3); int check_it=1; for (auto it = q1.begin() ; it != q1.end() ; ++it) EXPECT_EQ(*it, check_it++); EXPECT_EQ(4, check_it); // run through all } // push-pop TEST(Tqueue, front_back) { queue q1; q1.push(7); EXPECT_EQ (7, q1.front()); EXPECT_EQ (7, q1.back()); EXPECT_EQ (7, q1.pop()); q1.push(1); q1.push(2); q1.push(3); int check_it=1; for (auto it = q1.begin() ; it != q1.end() ; ++it) EXPECT_EQ(*it, check_it++); EXPECT_EQ(4, check_it); // run through all } // stream operations TEST(Tqueue, capacity) { queue q1; // stream 5 items q1 << 1 << 2 << 3 << 4 << 5; int check_it=1; for (auto it = q1.begin() ; it != q1.end() ; ++it) EXPECT_EQ(*it, check_it++); EXPECT_EQ (6, check_it); // run through all // get all back int it; for (int check_it=1 ; check_it<=5 ; ++check_it) { q1 >> it; EXPECT_EQ (check_it, it); } } }