t289.py

00001 # This file is Copyright 2003, 2006, 2007, 2009, 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 289
00015 # Create bytearray datatype
00016 #
00017 
00018 b0 = bytearray("test")
00019 b1 = bytearray(4)
00020 b2 = bytearray([2,5,6,2])
00021 b3 = bytearray((1,2,8,1))
00022 b4 = bytearray(b0)
00023 b5 = bytearray(['2',5,'6',2])
00024 b6 = bytearray(('1','2',8,1))
00025 
00026 # Test that the bytearrays all have the proper length
00027 assert 4 == len(b0)
00028 assert 4 == len(b1)
00029 assert 4 == len(b2)
00030 assert 4 == len(b3)
00031 assert 4 == len(b4)
00032 assert 4 == len(b5)
00033 assert 4 == len(b6)
00034 
00035 # Test that indexing into each bytearray returns an Integer
00036 assert type(0) == type(b0[0])
00037 assert type(0) == type(b1[0])
00038 assert type(0) == type(b2[0])
00039 assert type(0) == type(b3[0])
00040 assert type(0) == type(b4[0])
00041 assert type(0) == type(b5[0])
00042 assert type(0) == type(b6[0])
00043 
00044 # Test that the contents of each bytearray are proper
00045 assert b0[0] == ord('t')
00046 assert b0[1] == ord('e')
00047 assert b0[2] == ord('s')
00048 assert b0[3] == ord('t')
00049 
00050 assert b1[0] == 0
00051 assert b1[1] == 0
00052 assert b1[2] == 0
00053 assert b1[3] == 0
00054 
00055 assert b2[0] == 2
00056 assert b2[1] == 5
00057 assert b2[2] == 6
00058 assert b2[3] == 2
00059 
00060 assert b3[0] == 1
00061 assert b3[1] == 2
00062 assert b3[2] == 8
00063 assert b3[3] == 1
00064 
00065 assert b4[0] == ord('t')
00066 assert b4[1] == ord('e')
00067 assert b4[2] == ord('s')
00068 assert b4[3] == ord('t')
00069 
00070 assert b5[0] == ord('2')
00071 assert b5[1] == 5
00072 assert b5[2] == ord('6')
00073 assert b5[3] == 2
00074 
00075 assert b6[0] == ord('1')
00076 assert b6[1] == ord('2')
00077 assert b6[2] == 8
00078 assert b6[3] == 1
00079 
00080 # Test setting contents (STORE_SUBSCR)
00081 b1[0] = 't'
00082 b1[1] = 'e'
00083 b1[2] = 's'
00084 b1[3] = 't'
00085 
00086 # Test comparing contents
00087 assert b1 == b0
00088 
00089 # Test setting contents (STORE_SUBSCR)
00090 b0[False] = 0x34
00091 b0[True] = 0x32
00092 assert b0[0] == ord('4')
00093 assert b0[1] == ord('2')
00094 
00095 print b0

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