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 233 00015 # 00016 # Replication was introduced in issue #160 (original trac). 00017 # The system test t160 does not exercise the BINARY_MULTIPLY bytecode! 00018 # It turns out the Python compiler will automatically expand sequence*integerconstant 00019 # When integerconstant is <= 20. So these tests use 30 so that BINARY_MULTIPLY 00020 # is exercised and the replication functions are called. 00021 # 00022 00023 00024 # Test string replication 00025 s = "farley" * 30 00026 print s 00027 assert s == "farleyfarleyfarley" * 10 00028 assert len(s) == 6*30 00029 00030 mul = 0 00031 assert "farley" * mul == "" 00032 mul = -42 00033 assert "farley" * mul == "" 00034 00035 # Test tuple replication 00036 t = (2,5,6) * 30 00037 print t 00038 assert t == (2,5,6, 2,5,6, 2,5,6) * 10 00039 assert len(t) == 3*30 00040 00041 mul = 0 00042 assert (2,5,6) * mul == () 00043 mul = -42 00044 assert (2,5,6) * mul == () 00045 00046 # Also ensure list replication works 00047 r = range(3) * 30 00048 assert r == [0,1,2,0,1,2,0,1,2] * 10 00049 assert len(r) == 3*30 00050 00051 mul = 0 00052 assert [0,1,2] * mul == [] 00053 mul = -42 00054 assert [0,1,2] * mul == [] 00055 00056 # Just for fun 00057 print [[3,]*30, "three"*30, ('e',)*30]*30