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