diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2007-11-30 06:23:24 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2007-11-30 06:23:24 +0000 |
| commit | c81b01e060ad80a5c4df579a96ff737df2d336b3 (patch) | |
| tree | d34a873e7b5e19f0e91424d4ab28e2f968233d63 /tests/regressiontests/utils/datastructures.py | |
| parent | f88babafc58eafece72d3f2f7444336c69196808 (diff) | |
newforms-admin: Merged from trunk up to [6775].
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6777 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/utils/datastructures.py')
| -rw-r--r-- | tests/regressiontests/utils/datastructures.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/regressiontests/utils/datastructures.py b/tests/regressiontests/utils/datastructures.py new file mode 100644 index 0000000000..52bf81a9e0 --- /dev/null +++ b/tests/regressiontests/utils/datastructures.py @@ -0,0 +1,51 @@ +""" +>>> from django.utils.datastructures import SortedDict + +>>> d = SortedDict() +>>> d[7] = 'seven' +>>> d[1] = 'one' +>>> d[9] = 'nine' +>>> d.keys() +[7, 1, 9] +>>> d.values() +['seven', 'one', 'nine'] +>>> d.items() +[(7, 'seven'), (1, 'one'), (9, 'nine')] + +# Overwriting an item keeps it's place. +>>> d[1] = 'ONE' +>>> d.values() +['seven', 'ONE', 'nine'] + +# New items go to the end. +>>> d[0] = 'nil' +>>> d.keys() +[7, 1, 9, 0] + +# Deleting an item, then inserting the same key again will place it at the end. +>>> del d[7] +>>> d.keys() +[1, 9, 0] +>>> d[7] = 'lucky number 7' +>>> d.keys() +[1, 9, 0, 7] + +# Changing the keys won't do anything, it's only a copy of the keys dict. +>>> k = d.keys() +>>> k.remove(9) +>>> d.keys() +[1, 9, 0, 7] + +# Initialising a SortedDict with two keys will just take the first one. A real +# dict will actually take the second value so we will too, but we'll keep the +# ordering from the first key found. +>>> tuples = ((2, 'two'), (1, 'one'), (2, 'second-two')) +>>> d = SortedDict(tuples) +>>> d.keys() +[2, 1] +>>> real_dict = dict(tuples) +>>> real_dict.values() +['one', 'second-two'] +>>> d.values() +['second-two', 'one'] +"""
\ No newline at end of file |
