t026.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 026
00015 # Tests new builtin functions
00016 #
00017 
00018 #
00019 # Test len()
00020 #
00021 assert len("") == 0
00022 assert len("\x00") == 1
00023 assert len("\x00\x00\x00\x00") == 4
00024 
00025 #
00026 # Test ord()
00027 #
00028 c = ord("t")
00029 assert c == 116
00030 
00031 c = ord("\xff")
00032 assert c == 0xff
00033 
00034 c = ord("\x00")
00035 assert c == 0
00036 
00037 
00038 #
00039 # Test chr()
00040 #
00041 n = chr(0)
00042 assert n == "\x00"
00043 
00044 n = chr(255)
00045 assert n == "\xff"
00046 
00047 n = chr(116)
00048 assert n == "t"
00049 
00050 i = 32
00051 while i >= 0:
00052     assert ord(chr(i)) == i
00053     i -= 1
00054 
00055 #
00056 # Test abs()
00057 #
00058 n = 255
00059 m = abs(n)
00060 assert m == n
00061 assert m is n
00062 
00063 n = -42
00064 m = abs(n)
00065 assert m is not n
00066 assert m == -n
00067 
00068 
00069 #
00070 # Test sum()
00071 #
00072 s = [2, 5, 6]
00073 assert sum(s) == 13
00074 
00075 s = (2, 5, 6)
00076 assert sum(s) == 13

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