Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalther Neuper <neuper@neuper.(none)>2009-12-16 11:46:27 (GMT)
committer Walther Neuper <neuper@neuper.(none)>2009-12-16 11:46:27 (GMT)
commit62adac3d6e39b19994b8f0c08f3109aee0155929 (patch)
treed33c14e55762059c7066be49762efbeb56619d78
parent597276ae03251fc1e71fdf20467d1c794c3c232e (diff)
added collection/test_, ..really
-rw-r--r--ReckonPrimer.tests/collection/test_collection_WW091215.py197
-rw-r--r--ReckonPrimer.tests/collection/test_perfect_minimum_MM091214.py63
2 files changed, 260 insertions, 0 deletions
diff --git a/ReckonPrimer.tests/collection/test_collection_WW091215.py b/ReckonPrimer.tests/collection/test_collection_WW091215.py
new file mode 100644
index 0000000..b8008c8
--- /dev/null
+++ b/ReckonPrimer.tests/collection/test_collection_WW091215.py
@@ -0,0 +1,197 @@
+# -*- coding: utf-8 -*-
+"""tests on collection class"""
+
+
+
+class Task(object):
+
+ # constructor
+ def __init__(self, name):
+ self.name = name
+ self.obj = object
+ # destructor
+ #def __del__(self):
+ # print "in destructor"
+
+ # methods
+
+ # returns string representation of object
+ def __str__(self):
+ return "task: { name: ", self._name , " }"
+
+
+
+class Collection(object):
+
+ # constructor
+ def __init__(self, name):
+ self.name = name
+ self.pic = object
+ self._coll = []
+ self._tasks = []
+ # destructor
+ #def __del__(self):
+ # print "in destructor"
+
+ # methods
+
+ # adds collection or task to collection
+ def add(self, obj):
+ # if obj.instanceOf(Collection)
+ self._coll.append(obj)
+ #else
+ #self._tasks.append(obj)
+
+ # deletes collection or task from collection
+ def delete(self,sel):
+ # if obj.instanceOf(Collection) ?????
+ # find object
+ # if obj empty: delete
+ print "collection deleted"
+ # else error: collection not empty
+ # error: collection not found
+ # else # =task
+ # find object
+ print "task deletet"
+ # error: task not found
+
+ # returns string representation of object
+ def __str__(self): #mit for schleife definieren!!!
+ return 'collection: { name: ' , self.name , ', tasks: [' , self._tasks.__str__ , '], collections: [' , self._coll.__str__ , '] }'
+
+################################
+ def delete(self, n):
+ del self._data[n]
+
+ def pick(self, coords):
+ """ coords is a list of numbers (n-tupel), wich tells, which element
+ of the collection to select. The selected element will be returned """
+ if len(coords) == 0:
+ return self # emty coordinates: return this element
+ elif len(coords) == 1:
+ return self._data[coords[0]] # end of recursion
+ # go to next level
+ #self._data[coords[0]].show()
+ self._data[coords[0]].pick(coords[1:])
+
+ def show(self, top):
+ """ prints recursively all elements of this collection """
+ 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 Data(object): # inherit from gtk tree???
+
+ # constructor
+ def __init__(self):
+ self._collRoot = Collection("")
+ self._co=[0,2] # selction coordiantes: testing only ???
+ # destructor
+ #def __del__(self):
+ # print "in destructor"
+
+ # methods
+
+ # adds collection to selected collection or root
+ def addCollection(self, obj):
+ # if selection = null
+ self._collRoot.add(obj)
+ # else
+ # selCollection.add(obj)
+
+ # adds task to selected collection
+ def addTask(self, obj):
+ print "add task" #avoid syntax error
+ # if selection = null
+ # Error: please selct a collection to add a new task
+ # else
+ # selCollection.add(obj)
+
+ # edit selected object: task or collection
+ def edit(self):
+ # if selection = null
+ # Error: please select a task or collection
+ # find object
+ # if sel obj instance of task
+ # loadTask.. ???
+ # else
+ # loadCollection.. ???
+ print "edit object"
+
+ # deletes selected collection or task
+ def delete(self):
+ print "delete" #avoid syntax error
+ #if self._co = [0,2] and self._collRoot = []
+ # del self._collRoot
+ #else
+ self._collRoot.delete(sel)
+
+
+ # saves _collRoot to file
+ def _saveToFile(self):
+ print "save"
+
+ # loads _collRoot from file
+ def _loadFromFile(self):
+ print "load"
+
+ # update treeView
+ def _updateTree(self):
+ print "update treeView"
+
+ # returns string representation of object
+ def __str__(self):
+ return self._collRoot.__str__()
+
+
+
+
+
+
+# test
+
+fs = Data()
+
+c1 = Collection("c1")
+c2 = Collection("c2")
+t1 = Task("t1")
+t2 = Task("t2")
+c1.add(t1)
+c1.add(t2)
+c3 = Collection("c3")
+c3.add(t2)
+c3.add(t1)
+c1.add(c2.add(c3))
+fs.addCollection(c1)
+
+# created: [[t1, t2, [t2, t1]]]
+print fs.__str__()
+#print fs.__dict__
+#print fs.collRoot.__dict__
+
+
+# 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)
+
+#p1=task("res")
+#p1.show(True)
+#p1=root.pick([0,1])
+#p1.show(True)
+
+#root.pick([0,2,1]).show(True)
+#print "should be t1"
+
+
diff --git a/ReckonPrimer.tests/collection/test_perfect_minimum_MM091214.py b/ReckonPrimer.tests/collection/test_perfect_minimum_MM091214.py
new file mode 100644
index 0000000..8e1134b
--- /dev/null
+++ b/ReckonPrimer.tests/collection/test_perfect_minimum_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!
+
+
+
+