2015-02-26 17:56:25 +01:00
|
|
|
/* Copyright 2015 OpenMarket Ltd
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2015-06-27 01:15:23 +02:00
|
|
|
#include "olm/list.hh"
|
2021-12-22 19:45:33 +01:00
|
|
|
#include "testing.hh"
|
2015-02-24 12:30:28 +01:00
|
|
|
|
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
/** List insert test **/
|
2015-02-24 12:30:28 +01:00
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
TEST_CASE("List insert") {
|
2015-02-24 12:30:28 +01:00
|
|
|
|
2015-06-27 01:15:23 +02:00
|
|
|
olm::List<int, 4> test_list;
|
2015-02-24 12:30:28 +01:00
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(std::size_t(0), test_list.size());
|
2015-02-24 12:30:28 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
test_list.insert(test_list.end(), i);
|
|
|
|
}
|
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(std::size_t(4), test_list.size());
|
2015-02-24 12:30:28 +01:00
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for (auto item : test_list) {
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(i++, item);
|
2015-02-24 12:30:28 +01:00
|
|
|
}
|
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(4, i);
|
2015-02-24 12:30:28 +01:00
|
|
|
|
|
|
|
test_list.insert(test_list.end(), 4);
|
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(4, test_list[3]);
|
2015-02-24 12:30:28 +01:00
|
|
|
|
|
|
|
} /** List insert test **/
|
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
/** List insert beginning test **/
|
2015-07-15 17:31:45 +02:00
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
TEST_CASE("List insert beginning") {
|
2015-07-15 17:31:45 +02:00
|
|
|
|
|
|
|
olm::List<int, 4> test_list;
|
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(std::size_t(0), test_list.size());
|
2015-07-15 17:31:45 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
test_list.insert(test_list.begin(), i);
|
|
|
|
}
|
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(std::size_t(4), test_list.size());
|
2015-07-15 17:31:45 +02:00
|
|
|
|
|
|
|
int i = 4;
|
|
|
|
for (auto item : test_list) {
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(--i, item);
|
2015-07-15 17:31:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} /** List insert test **/
|
|
|
|
|
|
|
|
|
2021-12-22 19:45:33 +01:00
|
|
|
/** List erase test **/
|
|
|
|
TEST_CASE("List erase") {
|
2015-02-24 12:30:28 +01:00
|
|
|
|
2015-06-27 01:15:23 +02:00
|
|
|
olm::List<int, 4> test_list;
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(std::size_t(0), test_list.size());
|
2015-02-24 12:30:28 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
test_list.insert(test_list.end(), i);
|
|
|
|
}
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(std::size_t(4), test_list.size());
|
2015-02-24 12:30:28 +01:00
|
|
|
|
|
|
|
test_list.erase(test_list.begin());
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(std::size_t(3), test_list.size());
|
2015-02-24 12:30:28 +01:00
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for (auto item : test_list) {
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(i + 1, item);
|
2015-02-24 12:30:28 +01:00
|
|
|
++i;
|
|
|
|
}
|
2021-12-22 19:45:33 +01:00
|
|
|
CHECK_EQ(3, i);
|
2015-02-24 12:30:28 +01:00
|
|
|
|
|
|
|
}
|