Test the ``SortMixin`` class, which can be mixed in with
any sequence class to keep items in sorted order. The
sequence can still be initialized as usual, and will put
its items in sorted order.

    >>> from plib.stdlib.coll import SortMixin
    >>> class SortList(SortMixin, list):
    ...     def __init__(self, iterable=(), key=None):
    ...         super(SortMixin, self).__init__()
    ...         self._init_seq(iterable, key)
    ... 
    >>> list1 = ['c', 'b', 'e', 'a', 'd']
    >>> list2 = SortList(list1)
    >>> list2
    SortList(['a', 'b', 'c', 'd', 'e'], key=None)
    >>> list2 == sorted(list1)
    True

A sorted sequence maintains sort order when items are
inserted individually.

    >>> def build_sortlist(l1, l2):
    ...     for item in l1:
    ...         l2.insert(item)
    ...         print(l2)
    ... 
    >>> list2 = SortList()
    >>> build_sortlist(list1, list2)
    SortList(['c'], key=None)
    SortList(['b', 'c'], key=None)
    SortList(['b', 'c', 'e'], key=None)
    SortList(['a', 'b', 'c', 'e'], key=None)
    SortList(['a', 'b', 'c', 'd', 'e'], key=None)
    >>> list2 == sorted(list1)
    True

Strings sort alphabetically, as above, but integers sort by
value by default.

    >>> list1 = [3, 2, 5, 1, 4]
    >>> list2 = SortList()
    >>> build_sortlist(list1, list2)
    SortList([3], key=None)
    SortList([2, 3], key=None)
    SortList([2, 3, 5], key=None)
    SortList([1, 2, 3, 5], key=None)
    SortList([1, 2, 3, 4, 5], key=None)
    >>> list2 == sorted(list1)
    True
    >>> list1 = [222, 1300, 51, 7, 411]
    >>> list2 = SortList()
    >>> build_sortlist(list1, list2)
    SortList([222], key=None)
    SortList([222, 1300], key=None)
    SortList([51, 222, 1300], key=None)
    SortList([7, 51, 222, 1300], key=None)
    SortList([7, 51, 222, 411, 1300], key=None)
    >>> list2 == sorted(list1)
    True

We can supply a custom sort key to our sorted list; let's test
that we can get integers to sort by their string representations,
instead of by value. Contrast the sort order with the previous
case.

    >>> list1 = [222, 1300, 51, 7, 411]
    >>> list2 = SortList(key=str)
    >>> build_sortlist(list1, list2)
    SortList([222], key=str)
    SortList([1300, 222], key=str)
    SortList([1300, 222, 51], key=str)
    SortList([1300, 222, 51, 7], key=str)
    SortList([1300, 222, 411, 51, 7], key=str)
    >>> list2 == sorted(list1, key=str)
    True

We can also change the key on the fly.

    >>> list2.key = lambda x: len(str(x))
    >>> list2
    SortList([7, 51, 222, 411, 1300], key=<lambda>)
    >>> del list2.key
    >>> list2
    SortList([7, 51, 222, 411, 1300], key=None)
    >>> list2 == sorted(list1)
    True

Methods that can preserve the sort order are allowed,
including the standard sequence methods and operations
that are read-only.

    >>> len(list2)
    5
    >>> list2[0]
    7
    >>> for item in list2:
    ...     print(item)
    7
    51
    222
    411
    1300
    >>> list2.index(7)
    0
    >>> list2.count(7)
    1
    >>> del list2[0]
    >>> 7 in list2
    False
    >>> 51 in list2
    True
    >>> list2.remove(51)
    >>> 51 in list2
    False
    >>> list2
    SortList([222, 411, 1300], key=None)
    >>> list2.pop()
    1300
    >>> list2.pop(0)
    222
    >>> list2
    SortList([411], key=None)
    >>> list2.clear()
    >>> len(list2)
    0

Some methods are re-defined to preserve the sort order, so
their semantics are different from the standard sequence
methods.

    >>> list2.append(7)
    >>> list2
    SortList([7], key=None)
    >>> list2.append(222)
    >>> list2
    SortList([7, 222], key=None)
    >>> list2.append(51)
    >>> list2
    SortList([7, 51, 222], key=None)
    >>> list2.clear()
    >>> list2.extend(list1)
    >>> list2
    SortList([7, 51, 222, 411, 1300], key=None)
    >>> list2.clear()

Methods that cannot preserve the sort order are forbidden by
SortMixin.

    >>> list2.sort()
    Traceback (most recent call last):
    ...
    TypeError: can't manually sort a sorted sequence.
    >>> list2.reverse()
    Traceback (most recent call last):
    ...
    TypeError: can't reverse a sorted sequence.
    >>> list2[0] = 0
    Traceback (most recent call last):
    ...
    TypeError: can't set item by index on sorted sequence; use insert instead.
