Changeset 7452b155 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:24Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
91ac0bb
Parents:
c300bb5
git-author:
Dzejrou <dzejrou@…> (2018-05-17 16:51:33)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:24)
Message:

cpp: added the rest of list tests and fixed bugs found by them

Location:
uspace/lib/cpp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/list.hpp

    rc300bb5 r7452b155  
    7171
    7272                list_const_iterator(const list_iterator<T>& other)
    73                     : current_{other.node()}, head_{other.head()}
     73                    : current_{other.node()}, head_{other.head()}, end_{other.end()}
    7474                { /* DUMMY BODY */ }
    7575
     
    307307        template<class T>
    308308        bool operator!=(const list_iterator<T>& lhs, const list_iterator<T>& rhs)
     309        {
     310            return !(lhs == rhs);
     311        }
     312
     313        template<class T>
     314        bool operator==(const list_const_iterator<T>& lhs, const list_iterator<T>& rhs)
     315        {
     316            return (lhs.node() == rhs.node()) && (lhs.end() == rhs.end());
     317        }
     318
     319        template<class T>
     320        bool operator!=(const list_const_iterator<T>& lhs, const list_iterator<T>& rhs)
     321        {
     322            return !(lhs == rhs);
     323        }
     324
     325        template<class T>
     326        bool operator==(const list_iterator<T>& lhs, const list_const_iterator<T>& rhs)
     327        {
     328            return (lhs.node() == rhs.node()) && (lhs.end() == rhs.end());
     329        }
     330
     331        template<class T>
     332        bool operator!=(const list_iterator<T>& lhs, const list_const_iterator<T>& rhs)
    309333        {
    310334            return !(lhs == rhs);
     
    874898                    return;
    875899
    876                 if (first.node() == other.head_ && !last.node())
     900                if (first == other.begin() && last == other.end())
    877901                { // [first, last) is everything in other.
    878902                    splice(position, other);
     
    884908                aux::list_node<value_type>* last_node{};
    885909
    886                 if (first.node() == other.head_)
     910                if (first == other.begin())
    887911                { // The range is a prefix of other.
    888912                    other.head_ = last.node();
     
    893917                    last_node = last.node()->prev;
    894918                }
    895                 else if (!last.node())
     919                else if (last == other.end())
    896920                { // The range is a suffix of other.
    897921                    auto new_last = first.node()->prev;
     
    928952                }
    929953
    930                 auto count = distance(iterator{first_node}, iterator{last_node});
     954                auto count = distance(
     955                    iterator{first_node, nullptr, false},
     956                    iterator{last_node, nullptr, false}
     957                );
     958                ++count;
     959
    931960                size_ += count;
    932961                other.size_ -= count;
  • uspace/lib/cpp/src/__bits/test/list.cpp

    rc300bb5 r7452b155  
    237237        test_eq("clear empty", l1.empty(), true);
    238238        test_eq("clear size", l1.size(), 0U);
     239
     240        std::list<int> l2{1, 2, 3, 4, 5};
     241        std::list<int> l3{10, 20, 30, 40, 50};
     242
     243        auto check6 = {1, 2, 10, 20, 30, 40, 50, 3, 4, 5};
     244        auto check7 = {1, 2, 10, 20, 30, 40, 50};
     245        auto check8 = {3, 4, 5};
     246
     247        auto it6 = l2.begin();
     248        std::advance(it6, 2);
     249
     250        l2.splice(it6, l3);
     251        test_eq(
     252            "splice pt1",
     253            check6.begin(), check6.end(),
     254            l2.begin(), l2.end()
     255        );
     256        test_eq("splice pt2", l3.empty(), true);
     257
     258        l3.splice(l3.begin(), l2, it6, l2.end());
     259        test_eq(
     260            "splice pt3",
     261            check7.begin(), check7.end(),
     262            l2.begin(), l2.end()
     263        );
     264        test_eq(
     265            "splice pt4",
     266            check8.begin(), check8.end(),
     267            l3.begin(), l3.end()
     268        );
     269        test_eq("splice size pt1", l2.size(), 7U);
     270        test_eq("splice size pt2", l3.size(), 3U);
     271
     272        auto check9 = {1, -1, 2, -2, 3, -3, 4, -4};
     273        auto check10 = {1, 2, 3, 4};
     274        std::list<int> l4{1, -1, 2, 5, -2, 5, 3, -3, 5, 4, -4};
     275
     276        l4.remove(5);
     277        test_eq(
     278            "remove",
     279            check9.begin(), check9.end(),
     280            l4.begin(), l4.end()
     281        );
     282        test_eq("remove size", l4.size(), 8U);
     283
     284        l4.remove_if([](auto x){ return x < 0; });
     285        test_eq(
     286            "remove_if",
     287            check10.begin(), check10.end(),
     288            l4.begin(), l4.end()
     289        );
     290        test_eq("remove_if size", l4.size(), 4U);
     291
     292        auto check11 = {1, 2, 3, 2, 4, 5};
     293        std::list<int> l5{1, 1, 2, 3, 3, 2, 2, 4, 5, 5};
     294
     295        l5.unique();
     296        test_eq(
     297            "unique",
     298            check11.begin(), check11.end(),
     299            l5.begin(), l5.end()
     300        );
     301        test_eq("unique size", l5.size(), 6U);
     302
     303        auto check12 = {1, 3, 3, 5, 7, 9, 9};
     304        std::list<int> l6{1, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 9};
     305
     306        l6.unique([](auto lhs, auto rhs){ return lhs == rhs + 1; });
     307        test_eq(
     308            "unique predicate",
     309            check12.begin(), check12.end(),
     310            l6.begin(), l6.end()
     311        );
     312        test_eq("unique predicate size", l6.size(), 7U);
    239313    }
    240314}
Note: See TracChangeset for help on using the changeset viewer.