t259.py

00001 # This file is Copyright 2010 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 259
00015 # Add filter() function to builtins
00016 #
00017 
00018 e = filter(lambda x: x%2 == 0, range(5))
00019 assert e == [0, 2, 4]
00020 print "filter() test 1 passes."
00021 
00022 
00023 e = filter(lambda x: x%2 == 2, range(5))
00024 assert e == []
00025 print "filter() test 2 passes."
00026 
00027 
00028 e = filter(lambda x: True, range(0))
00029 assert e == []
00030 print "filter() test 3 passes."
00031 
00032 
00033 e = filter(lambda x: True, [])
00034 assert e == []
00035 print "filter() test 4 passes."
00036 
00037 
00038 e = filter(lambda x: x%2 == 0, (1,3,5))
00039 assert e == []
00040 print "filter() test 5 passes."
00041 
00042 
00043 # The following code should throw a TypeError
00044 #filter(2, range(5))
00045 
00046 # The following code should throw a TypeError
00047 #filter(lambda x: x%2 == 0, 5)

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