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
|
|
|
|
2020-03-02 11:50:43 +03:00
|
|
|
#include <AK/CircularDeque.h>
|
2022-12-04 21:02:33 +03:00
|
|
|
#include <AK/DeprecatedString.h>
|
2020-03-02 11:50:43 +03:00
|
|
|
#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)
|
|
|
|
{
|
2022-12-04 21:02:33 +03:00
|
|
|
CircularDeque<DeprecatedString, 2> strings;
|
2020-03-02 11:50:43 +03:00
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
DeprecatedString str { "test" };
|
2020-03-02 11:50:43 +03:00
|
|
|
strings.enqueue_begin(move(str));
|
|
|
|
EXPECT(str.is_null());
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|