t047.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 # Regression Test for Issue #47
00015 # Design and implement method for basic types
00016 # to access their respective class methods
00017 #
00018 
00019 import string, sys
00020 
00021 assert len(string.digits) == 10
00022 
00023 assert string.atoi("42") == 42
00024 assert string.atoi("0") == 0
00025 assert string.atoi("-42") == -42
00026 assert string.atoi("8675309") == 8675309
00027 assert string.atoi("2147483647") == sys.maxint
00028 
00029 assert string.atoi("42", 0) == 42
00030 assert string.atoi("0", 0) == 0
00031 assert string.atoi("-42", 0) == -42
00032 assert string.atoi("8675309", 0) == 8675309
00033 assert string.atoi("2147483647", 0) == sys.maxint
00034 
00035 assert string.atoi("42", 16) == 66
00036 assert string.atoi("0", 16) == 0
00037 assert string.atoi("-42", 16) == -66
00038 assert string.atoi("0x8675309", 16) == 140989193
00039 assert string.atoi("0x7fffffff", 16) == sys.maxint
00040 
00041 #string.atoi() # Expect TypeError (0xED)
00042 #string.atoi(42) # Expect TypeError (0xED)
00043 #string.atoi("42","10") # Expect TypeError (0xED)
00044 #string.atoi("42", 10, 0) # Expect TypeError (0xED)
00045 #string.atoi('c') # Expect ValueError (0xEE)
00046 #string.atoi("10", 1) # Expect ValueError (0xEE)
00047 #string.atoi("10", -1) # Expect ValueError (0xEE)
00048 #string.atoi("10", 99) # Expect ValueError (0xEE)
00049 
00050 assert string.count("timmy", "t") == 1
00051 assert string.count("timmy", "m") == 2
00052 assert string.count("timmy", "y") == 1
00053 assert string.count("timmy", "z") == 0
00054 
00055 assert string.count("cccccancun","c") == 6
00056 assert string.count("cccccancun","n") == 2
00057 assert string.count("cccccancun","C") == 0
00058 assert string.count("cccccancun","\0") == 0
00059 
00060 assert string.count("","") == 1
00061 assert string.count("","a") == 0
00062 assert string.count("a","") == 2
00063 assert string.count("","\0") == 0
00064 assert string.count("\0","\0") == 1
00065 assert string.count("\0","") == 2
00066 
00067 #string.count("") # Expect TypeError (0xED)
00068 #string.count("","","") # Expect TypeError (0xED)
00069 #string.count("",2) # Expect TypeError (0xED)
00070 #string.count([],"") # Expect TypeError (0xED)
00071 
00072 assert string.find("timmy", "t") == 0
00073 assert string.find("timmy", "m") == 2
00074 assert string.find("timmy", "y") == 4
00075 assert string.find("timmy", "z") == -1
00076 assert string.find("timmy", "M") == -1
00077 
00078 assert string.find("","") == 0
00079 assert string.find("","a") == -1
00080 assert string.find("a","") == 0
00081 assert string.find("","\0") == -1
00082 assert string.find("\0","\0") == 0
00083 assert string.find("\0","") == 0
00084 assert string.find(" \0","") == 0
00085 assert string.find(" \0","\0") == 1
00086 
00087 #string.find("") # Expect TypeError (0xED)
00088 #string.find("","","") # Expect TypeError (0xED)
00089 #string.find("",2) # Expect TypeError (0xED)
00090 #string.find([],"") # Expect TypeError (0xED)
00091 

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