indexden is now optional
[oweals/karmaworld.git] / dicthelperstest.py
1 # I need to turn this into a proper unit test.
2 # uhm, this is horrible. sorry everybody.
3 # -Bryan
4
5 import time
6 from dicthelpers import fallbackdict
7
8 start = time.time()
9
10 fallback = {1: '1'}
11 poop = fallbackdict(fallback)
12 print 'expect 1 (fallback): ' + poop[1]
13 fallback[2] = '2'
14 print 'expect 2 (dynamic fallback): ' + poop[2]
15 poop[2] = '3'
16 print 'expect 3 (overridden): ' + poop[2]
17 del poop[2]
18 print 'expect 2 (fallback after delete): ' + poop[2]
19 fallback['three'] = 3
20 fallback[3] = '3{three}'
21 print 'expect 33 (formatting): ' + poop[3]
22 print 'expect 4 (len): ' + str(len(poop))
23 fallback['infinite'] = '{infinite}'
24 print 'simple infinite recursion test: ' + poop['infinite']
25 fallback['infone'] = '{inftwo}'
26 fallback['inftwo'] = '{infone}'
27 print 'double infinite recursion test: ' + poop['infone']
28 fallback['2infone'] = '{2inftwo}'
29 fallback['2inftwo'] = '{2infone}'
30 print 'double infinite recursion test: ' + poop['2inftwo']
31 poop['four'] = 4
32 poop[4] = '4{four}'
33 print 'expect 34 (self as string mapping): {three}{four}'.format(**poop)
34 print 'expect 44 (self formatting): ' + poop[4]
35 # silent iter length processing.
36 # this used to take 1 or 2 seconds prior to optimizations
37 for x in poop: poop[x]
38
39 stop = time.time()
40 print "execution " + str(stop - start)