blob: 764a527679bf478eb460da97d971a3448f960241 [file] [log] [blame]
Wenzel Jakob57082212015-09-04 23:42:12 +02001#!/usr/bin/env python
2from __future__ import print_function
Wenzel Jakob38bd7112015-07-05 20:05:44 +02003import sys
4sys.path.append('.')
5
Jason Rhinelander5aa85be2016-08-11 21:22:05 -04006from example import Sequence, StringMap
Wenzel Jakob38bd7112015-07-05 20:05:44 +02007
8s = Sequence(5)
9print("s = " + str(s))
10print("len(s) = " + str(len(s)))
11print("s[0], s[3] = %f %f" % (s[0], s[3]))
12print('12.34 in s: ' + str(12.34 in s))
13s[0], s[3] = 12.34, 56.78
14print('12.34 in s: ' + str(12.34 in s))
15print("s[0], s[3] = %f %f" % (s[0], s[3]))
16rev = reversed(s)
17rev2 = s[::-1]
18print("rev[0], rev[1], rev[2], rev[3], rev[4] = %f %f %f %f %f" % (rev[0], rev[1], rev[2], rev[3], rev[4]))
19
20for i in rev:
21 print(i, end=' ')
22print('')
23for i in rev2:
24 print(i, end=' ')
25print('')
26print(rev == rev2)
27rev[0::2] = Sequence([2.0, 2.0, 2.0])
28for i in rev:
29 print(i, end=' ')
30print('')
Jason Rhinelander3f589372016-08-07 13:05:26 -040031
Jason Rhinelander5aa85be2016-08-11 21:22:05 -040032m = StringMap({ 'hi': 'bye', 'black': 'white' })
33print(m['hi'])
34print(len(m))
35print(m['black'])
36try:
37 print(m['orange'])
38 print('Error: should have thrown exception')
39except KeyError:
40 pass
41m['orange'] = 'banana'
42print(m['orange'])
43
44for k in m:
45 print("key = %s, value = %s" % (k, m[k]))
46
47for k,v in m.items():
48 print("item: (%s, %s)" % (k,v))
49
Jason Rhinelander3f589372016-08-07 13:05:26 -040050from example import ConstructorStats
51cstats = ConstructorStats.get(Sequence)
52print("Instances not destroyed:", cstats.alive())
53s = None
54print("Instances not destroyed:", cstats.alive())
55rev = None
56print("Instances not destroyed:", cstats.alive())
57rev2 = None
58print("Instances not destroyed:", cstats.alive())
59print("Constructor values:", cstats.values())
60print("Default constructions:", cstats.default_constructions)
61print("Copy constructions:", cstats.copy_constructions)
62print("Move constructions:", cstats.move_constructions >= 1)
63print("Copy assignments:", cstats.copy_assignments)
64print("Move assignments:", cstats.move_assignments)