2020-03-02 11:50:43 +03:00
|
|
|
/*
|
2020-03-02 16:23:54 +03:00
|
|
|
* Copyright (c) 2020, Fei Wu <f.eiwu@yahoo.com>
|
2020-03-02 11:50:43 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-02 11:50:43 +03:00
|
|
|
*/
|
|
|
|
|
2021-04-25 08:53:23 +03:00
|
|
|
#include <LibTest/TestCase.h>
|
2020-03-06 13:21:23 +03:00
|
|
|
|
2023-12-16 17:19:34 +03:00
|
|
|
#include <AK/ByteString.h>
|
2020-03-02 11:50:43 +03:00
|
|
|
#include <AK/CircularDeque.h>
|
|
|
|
#include <AK/StdLibExtras.h>
|
|
|
|
|
|
|
|
TEST_CASE(enqueue_begin)
|
|
|
|
{
|
|
|
|
CircularDeque<int, 3> ints;
|
|
|
|
|
|
|
|
ints.enqueue_begin(0);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 1u);
|
2020-03-02 11:50:43 +03:00
|
|
|
EXPECT_EQ(ints.first(), 0);
|
|
|
|
|
|
|
|
ints.enqueue_begin(1);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 2u);
|
2020-03-02 11:50:43 +03:00
|
|
|
EXPECT_EQ(ints.first(), 1);
|
|
|
|
EXPECT_EQ(ints.last(), 0);
|
|
|
|
|
|
|
|
ints.enqueue_begin(2);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 3u);
|
2020-03-02 11:50:43 +03:00
|
|
|
EXPECT_EQ(ints.first(), 2);
|
|
|
|
EXPECT_EQ(ints.last(), 0);
|
|
|
|
|
|
|
|
ints.enqueue_begin(3);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 3u);
|
2020-03-02 11:50:43 +03:00
|
|
|
EXPECT_EQ(ints.first(), 3);
|
|
|
|
EXPECT_EQ(ints.at(1), 2);
|
|
|
|
EXPECT_EQ(ints.last(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(enqueue_begin_being_moved_from)
|
|
|
|
{
|
2023-12-16 17:19:34 +03:00
|
|
|
CircularDeque<ByteString, 2> strings;
|
2020-03-02 11:50:43 +03:00
|
|
|
|
2023-12-16 17:19:34 +03:00
|
|
|
ByteString str { "test" };
|
2020-03-02 11:50:43 +03:00
|
|
|
strings.enqueue_begin(move(str));
|
2023-10-10 14:30:58 +03:00
|
|
|
EXPECT(str.is_empty());
|
2020-03-02 11:50:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(deque_end)
|
|
|
|
{
|
|
|
|
CircularDeque<int, 3> ints;
|
|
|
|
ints.enqueue(0);
|
|
|
|
ints.enqueue(1);
|
|
|
|
ints.enqueue(2);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 3u);
|
2020-03-02 11:50:43 +03:00
|
|
|
|
|
|
|
EXPECT_EQ(ints.dequeue_end(), 2);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 2u);
|
2020-03-02 11:50:43 +03:00
|
|
|
|
|
|
|
EXPECT_EQ(ints.dequeue_end(), 1);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 1u);
|
2020-03-02 11:50:43 +03:00
|
|
|
|
|
|
|
EXPECT_EQ(ints.dequeue_end(), 0);
|
|
|
|
EXPECT(ints.is_empty());
|
|
|
|
}
|