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