2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2021-04-25 05:53:23 +00:00
|
|
|
#include <LibTest/TestCase.h>
|
2019-08-02 07:23:03 +00:00
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
#include <AK/ByteString.h>
|
2019-06-15 08:34:03 +00:00
|
|
|
#include <AK/Queue.h>
|
|
|
|
|
2019-07-16 08:08:39 +00:00
|
|
|
TEST_CASE(construct)
|
2019-06-15 08:34:03 +00:00
|
|
|
{
|
|
|
|
EXPECT(Queue<int>().is_empty());
|
|
|
|
EXPECT(Queue<int>().size() == 0);
|
2019-07-16 08:08:39 +00:00
|
|
|
}
|
2019-06-15 08:34:03 +00:00
|
|
|
|
2019-07-16 08:08:39 +00:00
|
|
|
TEST_CASE(populate_int)
|
|
|
|
{
|
2019-06-15 08:34:03 +00:00
|
|
|
Queue<int> ints;
|
|
|
|
ints.enqueue(1);
|
|
|
|
ints.enqueue(2);
|
|
|
|
ints.enqueue(3);
|
2020-03-06 10:21:23 +00:00
|
|
|
EXPECT_EQ(ints.size(), 3u);
|
2019-06-15 08:39:19 +00:00
|
|
|
EXPECT_EQ(ints.dequeue(), 1);
|
2020-03-06 10:21:23 +00:00
|
|
|
EXPECT_EQ(ints.size(), 2u);
|
2019-06-15 08:39:19 +00:00
|
|
|
EXPECT_EQ(ints.dequeue(), 2);
|
2020-03-06 10:21:23 +00:00
|
|
|
EXPECT_EQ(ints.size(), 1u);
|
2019-06-15 08:39:19 +00:00
|
|
|
EXPECT_EQ(ints.dequeue(), 3);
|
2020-03-06 10:21:23 +00:00
|
|
|
EXPECT_EQ(ints.size(), 0u);
|
2019-07-16 08:08:39 +00:00
|
|
|
}
|
2019-06-15 08:34:03 +00:00
|
|
|
|
2019-07-16 08:08:39 +00:00
|
|
|
TEST_CASE(populate_string)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
Queue<ByteString> strings;
|
2019-06-15 08:34:03 +00:00
|
|
|
strings.enqueue("ABC");
|
|
|
|
strings.enqueue("DEF");
|
2020-03-06 10:21:23 +00:00
|
|
|
EXPECT_EQ(strings.size(), 2u);
|
2019-06-15 08:39:19 +00:00
|
|
|
EXPECT_EQ(strings.dequeue(), "ABC");
|
|
|
|
EXPECT_EQ(strings.dequeue(), "DEF");
|
|
|
|
EXPECT(strings.is_empty());
|
2019-07-16 08:08:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(order)
|
|
|
|
{
|
2023-12-16 14:19:34 +00:00
|
|
|
Queue<ByteString> strings;
|
2019-07-16 08:08:39 +00:00
|
|
|
EXPECT(strings.is_empty());
|
2019-06-15 08:39:19 +00:00
|
|
|
|
2020-03-06 10:21:23 +00:00
|
|
|
for (size_t i = 0; i < 10000; ++i) {
|
2023-12-16 14:19:34 +00:00
|
|
|
strings.enqueue(ByteString::number(i));
|
2019-06-15 08:39:19 +00:00
|
|
|
EXPECT_EQ(strings.size(), i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 10000; ++i) {
|
2023-12-23 02:59:14 +00:00
|
|
|
EXPECT_EQ(strings.dequeue().to_number<int>().value(), i);
|
2019-06-15 08:39:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-15 08:34:03 +00:00
|
|
|
EXPECT(strings.is_empty());
|
|
|
|
}
|