diff options
Diffstat (limited to 'ReckonPrimer.tests/collection/test_collection_MM091214.py')
-rw-r--r-- | ReckonPrimer.tests/collection/test_collection_MM091214.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/ReckonPrimer.tests/collection/test_collection_MM091214.py b/ReckonPrimer.tests/collection/test_collection_MM091214.py new file mode 100644 index 0000000..8e1134b --- /dev/null +++ b/ReckonPrimer.tests/collection/test_collection_MM091214.py @@ -0,0 +1,63 @@ +# -*- coding: UTF8 -*- +"""tests on collection class""" + +class collection: + + def __init__(self, name): + self._data = [] + self._name = name + self._pic = "" + + def add(self, x): + self._data.append(x) + + def delete(self, n): + del self._data[n] + + def show(self, top): + """ prints recursively all elements of this collection """ + #only for test reasons + print("**********") + print "collection: ", self._name + print "elements:" + for el in self._data: + el.show(False) + print "---- end of ", self._name + if top: + print # print an empty line after the last element + +class task: + def __init__(self, name): + self._name = name + def show(self, top): + print "task: ", self._name + + +root = collection("root") +c1 = collection("c1") +t1 = task("t1") +t2 = task("t2") +c1.add(t1) +c1.add(t2) +c3 = collection("c3") +c3.add(t2) +c3.add(t1) +c1.add(c3) +root.add(c1) +# created: [[t1, t2, [t2, t1]]] +root.show(True) + +# Versuch in einer Schleife dynamisch auf ein mit Koordinaten spezifiertes Object zuzugreifen +co=[0,2] # Koordinaten +print "pick element ", co +el = root +for n in co: + el = el._data[n] + +el.show(True) # gewähltes Element anzeigen + +# funktioniert! + + + + |