summaryrefslogtreecommitdiff
path: root/Tests/AK/TestCircularDeque.cpp
blob: 8346eca2daa1836b36d55c09fcea51b2f94deef0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright (c) 2020, Fei Wu <f.eiwu@yahoo.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibTest/TestCase.h>

#include <AK/CircularDeque.h>
#include <AK/DeprecatedString.h>
#include <AK/StdLibExtras.h>

TEST_CASE(enqueue_begin)
{
    CircularDeque<int, 3> ints;

    ints.enqueue_begin(0);
    EXPECT_EQ(ints.size(), 1u);
    EXPECT_EQ(ints.first(), 0);

    ints.enqueue_begin(1);
    EXPECT_EQ(ints.size(), 2u);
    EXPECT_EQ(ints.first(), 1);
    EXPECT_EQ(ints.last(), 0);

    ints.enqueue_begin(2);
    EXPECT_EQ(ints.size(), 3u);
    EXPECT_EQ(ints.first(), 2);
    EXPECT_EQ(ints.last(), 0);

    ints.enqueue_begin(3);
    EXPECT_EQ(ints.size(), 3u);
    EXPECT_EQ(ints.first(), 3);
    EXPECT_EQ(ints.at(1), 2);
    EXPECT_EQ(ints.last(), 1);
}

TEST_CASE(enqueue_begin_being_moved_from)
{
    CircularDeque<DeprecatedString, 2> strings;

    DeprecatedString str { "test" };
    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);
    EXPECT_EQ(ints.size(), 3u);

    EXPECT_EQ(ints.dequeue_end(), 2);
    EXPECT_EQ(ints.size(), 2u);

    EXPECT_EQ(ints.dequeue_end(), 1);
    EXPECT_EQ(ints.size(), 1u);

    EXPECT_EQ(ints.dequeue_end(), 0);
    EXPECT(ints.is_empty());
}