diff options
author | Walther Neuper <neuper@neuper.(none)> | 2009-11-23 17:57:03 (GMT) |
---|---|---|
committer | Walther Neuper <neuper@neuper.(none)> | 2009-11-23 17:57:03 (GMT) |
commit | 9115543c52c0c62c857d149e70cf7602a8fb6afc (patch) | |
tree | 859abf168bbf770650d4f662a5bd121065de7881 | |
parent | b40cdaec00b4fa388d524965f12e6691b2ae7246 (diff) |
cleaned up the exercises ;; test_exercise_format.py
-rwxr-xr-x | ReckonPrimer.activity/Exercise.py | 54 | ||||
-rwxr-xr-x | ReckonPrimer.activity/exaddsimp.py | 30 | ||||
-rwxr-xr-x | ReckonPrimer.activity/expassten.py | 27 | ||||
-rwxr-xr-x | ReckonPrimer.activity/extimesdiv.py | 26 | ||||
-rwxr-xr-x | ReckonPrimer.activity/session.py | 2 | ||||
-rw-r--r-- | ReckonPrimer.tests/exercise/test_exercise_format.py | 41 |
6 files changed, 114 insertions, 66 deletions
diff --git a/ReckonPrimer.activity/Exercise.py b/ReckonPrimer.activity/Exercise.py index 3223ead..c481a48 100755 --- a/ReckonPrimer.activity/Exercise.py +++ b/ReckonPrimer.activity/Exercise.py @@ -30,50 +30,56 @@ class Exercise: """ An Exercise needs the Display for updating the settings""" self._display = None - def get_setting(self): - pass - def get_topic(self): - """The topic is preliminarily used to identify an exercise; - TODO: use self._sett['ID'] instead as soon as exs are stored.""" - pass + """The topic is preliminarily used to identify an exercise.""" + return (self._sett)['topic'] + def get_setting(self): + return self._sett + def update_setting(self, sett): - """The settings may be changed by the user. This method - is inherited and thus not contained in subclasses.""" - ####self._sett = sett + """ Update the settings and generate calculations accordingly. """ + self._sett = sett + self._calcs = self._generate_calcs() - def format(self, calc): - """Prepare the representation of a calculation for Display. - This method is public for eventual use on calculations - coming through the net (TODO cooperative games, etc)""" - pass + def get_next_calc(self): + """ Get the next calculation from the Exercise. + TODO.WN091123: handle exception after last exercise. """ + return (self._calcs).pop() + + def count(self): + """ Return the number of calculations generated by + the current settings """ + return len(self._calcs) def format_addsub_simp(self, (calc, linepos)): - """ Format the calc for display, prepare overlays for input. - Used within several subclasses. """ + """ Prepare the representation of a calculation for Display + on 1 line. Used within several subclasses. """ #@print('in Display.format_addsub_simp: calc=', (calc, linepos))#@ _ccs = collect_digits(calc) - print('in Exercise.format_addsub_simp: _ccs=',_ccs ) + #print('in Exercise.format_addsub_simp: _ccs=',_ccs ) _l0 = make_line(_ccs, linepos) _ip = make_input(_ccs, linepos) #@print('in Display.format_addsub_simp: return=', ([_l0], _ip)) #@ return ([_l0], _ip) #return ([[' ', '1', '0', ' ', '-', ' ', '7', ' ', '=', ' ', '_', ' ']], [(0, 10, '3', ' 10 - 7 = _ ', ' 10 - 7 = 3 ', [' ', '1', '0', ' ', '-', ' ', '7', ' ', '=', ' ', '3', ' '])]) - def generate_calcs(self): #WN091123 make private !!! - """TODO""" + #===== methods of subclasses different for topic-specific settings + def format(self, calc): + """ Prepare the representation of a calculation for Display. + This method is public for eventual use on calculations + coming through the net (TODO cooperative games, etc)""" pass - def count(self): - """TODO""" + def _generate_calcs(self): + """ Generate calculations according to topic-specific settings. + Called on each call of update_setting""" pass - #return len(self._calcs) def define_buttons(self): - """XXX""" + """ Define buttons for update settings. """ pass def set_buttons(self, sett): - """XXX""" + """ Display buttons according to the current setting. """ pass diff --git a/ReckonPrimer.activity/exaddsimp.py b/ReckonPrimer.activity/exaddsimp.py index 0ce6634..3772940 100755 --- a/ReckonPrimer.activity/exaddsimp.py +++ b/ReckonPrimer.activity/exaddsimp.py @@ -34,17 +34,17 @@ class ExAddSimp(Exercise): 'cut-max': True # cut set of all calcs down to MAX } - def get_setting(self): - return self._sett - - def get_topic(self): - return (self._sett)['topic'] - - def update_setting(self, sett): - self._calcs = self.generate_calcs() - self._sett = sett - - def generate_calcs(self): +# def get_setting(self): +# return self._sett +# +# def get_topic(self): +# return (self._sett)['topic'] +# +# def update_setting(self, sett): +# self._sett = sett +# self._calcs = self._generate_calcs() + + def _generate_calcs(self): _dic = self._sett _calcs = [] if _dic['+']: # '+' or '-' are True @@ -89,10 +89,10 @@ class ExAddSimp(Exercise): #[(0, 10, '3', ' 10 - 7 = _ ', ' 10 - 7 = 3 ', #[' ', '1', '0', ' ', '-', ' ', '7', ' ', '=', ' ', '3', ' '])]) - def count(self): - """TODO""" - print('in Display.count: len=', len(self._calcs)) - return len(self._calcs) +# def count(self): +# """TODO""" +# print('in Display.count: len=', len(self._calcs)) +# return len(self._calcs) def define_buttons(self): self.toggle_shuffle = gtk.ToggleButton("@") diff --git a/ReckonPrimer.activity/expassten.py b/ReckonPrimer.activity/expassten.py index 3b1bbfe..c517064 100755 --- a/ReckonPrimer.activity/expassten.py +++ b/ReckonPrimer.activity/expassten.py @@ -35,15 +35,15 @@ class ExPassTen(Exercise): 'cut-max' : True # cut set of all calcs down to MAX } - def get_setting(self): - return self._sett +# def get_setting(self): +# return self._sett - def get_topic(self): - return (self._sett)['topic'] +# def get_topic(self): +# return (self._sett)['topic'] - def update_setting(self, sett): - self._calcs = self.generate_calcs() - self._sett = sett +# def update_setting(self, sett): +# self._sett = sett +# self._calcs = self._generate_calcs() def format(self, (cs, ms, linepos)): """format the calc for display, prepare overlays for input""" @@ -206,9 +206,9 @@ class ExPassTen(Exercise): print('in Display.format_passten: not exists linepos=', linepos) #TODO exit, programmer mode - def generate_calcs(self): + def _generate_calcs(self): _dic = self._sett - print("in ExPassTen.generate_calcs: _dic=", _dic) + #print("in ExPassTen._generate_calcs: _dic=", _dic) _calcs = [] _c = [] # generate all calcs @@ -224,12 +224,12 @@ class ExPassTen(Exercise): random.shuffle(_calcs) return _calcs - def count(self): - """TODO""" - return len(self._calcs) +# def count(self): +# """TODO""" +# return len(self._calcs) def define_buttons(self): - + """ See comment in Exercies.define_buttons. """ self.toggle_plus = gtk.ToggleButton("+")
self.toggle_label = self.toggle_plus.get_child()
self.toggle_label.modify_font(pango.FontDescription("sans %d" % style.zoom(12)))
@@ -321,6 +321,7 @@ class ExPassTen(Exercise): self.number_butts.append(self.toggle) def set_buttons(self, sett): + """ See comment in Exercies.set_buttons. """ for i in range(sett['min'],sett['max']+1):
self.number_butts[i-1].set_active(True) diff --git a/ReckonPrimer.activity/extimesdiv.py b/ReckonPrimer.activity/extimesdiv.py index c677976..ec0b716 100755 --- a/ReckonPrimer.activity/extimesdiv.py +++ b/ReckonPrimer.activity/extimesdiv.py @@ -33,15 +33,15 @@ class ExTimesDiv(Exercise): 'cut-max' : True # cut set of all calcs down to MAX } - def get_setting(self): - return self._sett - - def get_topic(self): - return (self._sett)['topic'] - - def update_setting(self, sett): - self._calcs = self.generate_calcs() - self._sett = sett +# def get_setting(self): +# return self._sett +# +# def get_topic(self): +# return (self._sett)['topic'] +# +# def update_setting(self, sett): +# self._sett = sett +# self._calcs = self._generate_calcs() def format(self, (calc, linepos)): """format the calc for display, prepare overlays for input""" @@ -60,7 +60,7 @@ class ExTimesDiv(Exercise): #print('in Display.format_times_div: return=', ([_l0], _ip)) #@ return ([_l0], _ip) - def generate_calcs(self): + def _generate_calcs(self): """generate all calculations between min..max given in dict""" #print('in Generate.times_div, (min, max)=',(_dic['min'], _dic['max'], _dic['remainder'])) _dic = self._sett @@ -78,9 +78,9 @@ class ExTimesDiv(Exercise): random.shuffle(_calcs) return _calcs - def count(self): - """TODO""" - return len(self._calcs) +# def count(self): +# """TODO""" +# return len(self._calcs) def define_buttons(self): """buttons for this setting, which is specific for TimesDiv""" diff --git a/ReckonPrimer.activity/session.py b/ReckonPrimer.activity/session.py index 9a0ad64..dd92662 100755 --- a/ReckonPrimer.activity/session.py +++ b/ReckonPrimer.activity/session.py @@ -31,7 +31,7 @@ class Session: #print('in Session.notify: msg=,data=', msg, data) if msg == 'setting-done': # from Coach self._ex = data - self._calcs = data.generate_calcs() + self._calcs = data._generate_calcs() self._key = data.get_topic() (self._calcs).reverse() _calc = (self._calcs).pop() diff --git a/ReckonPrimer.tests/exercise/test_exercise_format.py b/ReckonPrimer.tests/exercise/test_exercise_format.py new file mode 100644 index 0000000..4f00baf --- /dev/null +++ b/ReckonPrimer.tests/exercise/test_exercise_format.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +#(c) Walther Neuper 2009 + +print("==================================_____________________===============") +print("===== ReckonPrimer.tests/timesdiv/test_exercise_format.py ============") + +#WN091116 Exercise <10> does not generate calculations +# with settings "1+2 <" OFF +#Traceback (most recent call last): +# File "/home/neuper/Activities/ReckonPrimer.activity/display.py", line 251, in clicked_start_callback +# self._co.notify(('setting-done', self._sett)) +# File "/home/neuper/Activities/ReckonPrimer.activity/coach.py", line 90, in notify +# self._sess.notify((msg, self._ex)) +# File "/home/neuper/Activities/ReckonPrimer.activity/session.py", line 39, in notify +# _lines, self._input = data.format(_calc) +# File "/home/neuper/Activities/ReckonPrimer.activity/expassten.py", line 52, in format +# return Exercise.format_addsub_simp((cs, linepos)) +#TypeError: unbound method format_addsub_simp() must be called with Exercise instance as first argument (got tuple instance instead) +#===== correction ============================================================ +# in expassten.py: +# return Exercise.format_addsub_simp((cs, linepos)) +#-->return self.format_addsub_simp((cs, linepos)) + +from expassten import ExPassTen +_ex = ExPassTen(None) #need no Display for this test +_sett = {'cut-max': True, 'newline': False, 'MIN': 10, 'shuffle_all': False, 'MAX': 150, '+': True, 'min': 2, '-': False, 'topic': 'passten', 'calclines': 1, 'max': 2, 'input': [5], 'shuffle_inner': False} #copied from logs +_ex.update_setting(_sett) +print("in test_exercise_format.py: _ex._sett=", _ex.get_setting()) +for _i in range(0, _ex.count()): + _calc = _ex.get_next_calc() + print("in test_exercise_format.py: _calc=", _calc) + print("in test_exercise_format.py: format(calc)=",_ex.format(_calc)) + if _i == 0 and (not _calc == (['2', '+', '9', '=', '1', '1'], None, 5)): + raise Exception() + if _i == 1 and (not _calc == (['2', '+', '8', '=', '1', '0'], None, 5)): + raise Exception() + +print("===== ReckonPrimer.tests/timesdiv/test_exercise_format.py ============") +print("========================= SUCCESS ~~~~~~~~~~~~~~~~~~~~~~~=============") + + |