t136.py

00001 # This file is Copyright 2003, 2006, 2007, 2009 Dean Hall.
00002 #
00003 # This file is part of the Python-on-a-Chip program.
00004 # Python-on-a-Chip is free software: you can redistribute it and/or modify
00005 # it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
00006 #
00007 # Python-on-a-Chip is distributed in the hope that it will be useful,
00008 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010 # A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
00011 # is seen in the file COPYING up one directory from this.
00012 
00013 #
00014 # System Test 136
00015 # Create module interface for compound datatypes
00016 #
00017 
00018 import dict, list
00019 
00020 
00021 # Tests for dict
00022 if 1:
00023     d = {}
00024     d[0] = "zero"
00025     d["one"] = 1
00026     print d
00027     print dict.keys(d)
00028     print dict.values(d)
00029 
00030     dict.clear(d)
00031     print d
00032     d['new'] = "more"
00033     print d
00034 
00035     print "d has key 'new' = ", dict.has_key(d, 'new')
00036     print "d has key 'old' = ", dict.has_key(d, 'old')
00037 
00038 
00039 # Tests for list
00040 if 1:
00041     foo = [0]
00042     list.append(foo, 1)
00043     print foo
00044 
00045     list.extend(foo, [2, 2])
00046     print foo
00047 
00048 
00049     print list.count(foo, 1)
00050     print list.count(foo, 2)
00051     print list.count(foo, 42)
00052 
00053     print list.index(foo, 0)
00054 
00055     list.insert(foo, 0, "zero")
00056     list.insert(foo, -1, "penultimate")
00057     print foo
00058 
00059     print list.pop(foo)
00060     print list.pop(foo, 2)
00061     print foo
00062 
00063     list.remove(foo, 2)
00064     list.remove(foo, "zero")
00065     print foo
00066 
00067     list.append(foo, "bob")
00068     print list.index(foo, "bob")
00069     print list.index(foo, "z") # expects a ValueError
00070 

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9