Browse Source

[Tests] First unit tests of OrderAnalyser

monf 8 years ago
parent
commit
201c26691c
3 changed files with 41 additions and 8 deletions
  1. 4 3
      core/OrderAnalyser.py
  2. 36 5
      core/Tests/OrderAnalyserTest.py
  3. 1 0
      core/Tests/__init__.py

+ 4 - 3
core/OrderAnalyser.py

@@ -150,7 +150,8 @@ class OrderAnalyser:
         next(ite, None)
         next(ite, None)
         return next(ite, None)
         return next(ite, None)
 
 
-    def _spelt_order_match_brain_order_via_table(self, order_to_analyse, user_said):
+    @classmethod
+    def _spelt_order_match_brain_order_via_table(cls, order_to_analyse, user_said):
         """
         """
         return true if all string that are in the sentence are present in the order to test
         return true if all string that are in the sentence are present in the order to test
         :param order_to_analyse: String order to test
         :param order_to_analyse: String order to test
@@ -158,10 +159,10 @@ class OrderAnalyser:
         :return: True if all string are present in the order
         :return: True if all string are present in the order
         """
         """
         list_word_user_said = user_said.split()
         list_word_user_said = user_said.split()
-        split_order_without_bracket = self._get_split_order_without_bracket(order_to_analyse)
+        split_order_without_bracket = cls._get_split_order_without_bracket(order_to_analyse)
 
 
         # if all words in the list of what the user said in in the list of word in the order
         # if all words in the list of what the user said in in the list of word in the order
-        return self._counter_subset(split_order_without_bracket, list_word_user_said)
+        return cls._counter_subset(split_order_without_bracket, list_word_user_said)
 
 
     @staticmethod
     @staticmethod
     def _get_split_order_without_bracket(order):
     def _get_split_order_without_bracket(order):

+ 36 - 5
core/Tests/OrderAnalyserTest.py

@@ -1,13 +1,44 @@
 import unittest
 import unittest
-from ..OrderAnalyser import *
+
+from core.OrderAnalyser import OrderAnalyser
 
 
 
 
 class OrderAnalyserTest(unittest.TestCase):
 class OrderAnalyserTest(unittest.TestCase):
 
 
     """Test case for the OrderAnalyser Class"""
     """Test case for the OrderAnalyser Class"""
 
 
-    def setUp(self):
-        pass
+    def test_is_containing_bracket(self):
+        #  Success
+        self.assertTrue(OrderAnalyser._is_containing_bracket("This test contains {{ bracket }}"))
+
+        #  Failure
+        self.assertFalse(OrderAnalyser._is_containing_bracket("This test does not contain bracket"))
+
+    def test_get_next_value_list(self):
+        # Success
+        list_to_test = {1, 2, 3}
+        self.assertEqual(OrderAnalyser._get_next_value_list(list_to_test),2)
+
+        # Failure
+        list_to_test = {1}
+        self.assertEqual(OrderAnalyser._get_next_value_list(list_to_test), None)
+
+        # Behaviour
+        list_to_test = {}
+        self.assertEqual(OrderAnalyser._get_next_value_list(list_to_test), None)
+
+    def test_spelt_order_match_brain_order_via_table(self):
+        order_to_test = "this is the order"
+        sentence_to_test = "this is the order"
+
+        # Success
+        self.assertTrue(OrderAnalyser._spelt_order_match_brain_order_via_table(order_to_test,
+                                                                               sentence_to_test))
+
+        # Failure
+        sentence_to_test = "unexpected sentence"
+        self.assertFalse(OrderAnalyser._spelt_order_match_brain_order_via_table(order_to_test,
+                                                                                 sentence_to_test))
 
 
-    def test__is_containing_bracket(self):
-        self.assertTrue(OrderAnalyser._is_containing_bracket("This test contains {{ bracket }}"))
+if __name__ == '__main__':
+    unittest.main()

+ 1 - 0
core/Tests/__init__.py

@@ -0,0 +1 @@
+from OrderAnalyserTest import OrderAnalyserTest