diff options
author | Pablo Astigarraga <poteland@gmail.com> | 2010-04-02 22:33:02 (GMT) |
---|---|---|
committer | Pablo Astigarraga <poteland@gmail.com> | 2010-04-02 22:33:02 (GMT) |
commit | 3a49d29f1630a090f02a5059ab981f5a8108e57f (patch) | |
tree | 26425e9017a412eb911f7a8c5fe6290854013aa3 | |
parent | b09bafdf6a0b26e46985052aeb265eac9f59e620 (diff) |
overran __eq__ in fraction class
-rw-r--r-- | fracciones.activity/fractionlogic.py | 16 | ||||
-rw-r--r-- | fracciones.activity/fractionpresentation.py | 3 |
2 files changed, 17 insertions, 2 deletions
diff --git a/fracciones.activity/fractionlogic.py b/fracciones.activity/fractionlogic.py index 10fd8e0..79cfe62 100644 --- a/fracciones.activity/fractionlogic.py +++ b/fracciones.activity/fractionlogic.py @@ -13,7 +13,13 @@ class Fraction(object): def __init__(self): self.numerator = None self.denominator = None - + + def __eq__(self,other_fraction): + if (self.numerator * other_fraction.denominator == self.denominator * other_fraction.numerator) and type(other_fraction) is Fraction: + return True + else: + return False + class FractionLogic(object): @@ -35,6 +41,14 @@ class FractionLogic(object): if self.fraction.denominator is None: raise Exception("generate_fraction must be called before get_current_fraction") return (self.fraction.numerator, self.fraction.denominator) + + + def get_current_cake(self): + """Return the current fraction, raise an exception if generate_fraction + hasn't called before""" + if self.fraction.denominator is None: + raise Exception("generate_fraction must be called before get_current_fraction") + return (self.fraction) def is_equal(self, fraction): diff --git a/fracciones.activity/fractionpresentation.py b/fracciones.activity/fractionpresentation.py index 2bdd42e..5a73b4b 100644 --- a/fracciones.activity/fractionpresentation.py +++ b/fracciones.activity/fractionpresentation.py @@ -102,7 +102,8 @@ class FractionPresentation(gtk.VBox): def check_cake(self, widget): """Clicked button check""" log.debug("on_clicked_check") - if self.logic.is_equal(self.cake.current_fraction): + current_cake = self.logic.get_current_cake() + if current_cake == self.cake.current_fraction: md = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE, _("GOOD!")) md.run() md.destroy() |