Commits

Marcin Kasperski  committed 66b41b4

Added GameType.variant - weaker comparison which makes wild equal to wild/fr

  • Participants
  • Parent commits 9cd9a1a

Comments (0)

Files changed (2)

File src/mekk/fics/datatypes/game_type.py

     def __eq__(self, other):
         return self._game_type == other._game_type
 
+    def matches(self, other):
+        """
+        Weaker comparison, returns True when wild is compred with wild/fr and in similar
+        cases
+        """
+        return self._game_type == other._game_type \
+            or self._game_type.startswith(other._game_type + "/") \
+            or other._game_type.startswith(self._game_type + "/")
+
     def __repr__(self):
         return "GameType(%s)" % self._game_type
 

File tests/test_gameType.py

             gt = GameType(spec)
             self.failUnlessEqual(gt.name, spec)
 
+    def test_wild_comparisons(self):
+        wild_generic = GameType("wild")
+        wild_fr = GameType("wild/fr")
+        wild_3 = GameType("wild/3")
+        self.failIfEqual(wild_generic, wild_3)
+        self.failIfEqual(wild_generic, wild_fr)
+        self.failIfEqual(wild_fr, wild_3)
+        self.failUnless(wild_generic.matches(wild_3))
+        self.failUnless(wild_generic.matches(wild_fr))
+        self.failUnless(wild_generic.matches(wild_generic))
+        self.failUnless(wild_fr.matches(wild_generic))
+        self.failUnless(wild_3.matches(wild_generic))
+        self.failUnless(wild_fr.matches(wild_fr))
+        self.failUnless(wild_3.matches(wild_3))
+        self.failIf(wild_fr.matches(wild_3))
+        self.failIf(wild_3.matches(wild_fr))
+
     def test_equalable(self):
         g1 = GameType('standard')
         g2 = GameType('s')