Преглед на файлове

more test messages + test typo checking

feature/find_holes
Figg преди 9 месеца
родител
ревизия
c01b29a710
променени са 3 файла, в които са добавени 167 реда и са изтрити 12 реда
  1. 57
    0
      million/analyze/count_analysis.py
  2. 34
    12
      test/model/message_test.py
  3. 76
    0
      test/model/typo_test.py

+ 57
- 0
million/analyze/count_analysis.py Целия файл

@@ -0,0 +1,57 @@
1
+def check_extra_or_missing_letter(word, reference):
2
+    len_word = len(word)
3
+    len_ref = len(reference)
4
+
5
+    if abs(len_word - len_ref) != 1:
6
+        return False
7
+
8
+    shortest = word if len_word < len_ref else reference
9
+    longest = word if len_word > len_ref else reference
10
+
11
+    for i in range(len(shortest)):
12
+        if shortest[i] != longest[i]:
13
+            return shortest[i:] == longest[i + 1 :]
14
+
15
+    return True
16
+
17
+
18
+def check_single_letter_differ(word, reference):
19
+    return sum(1 for x, y in zip(reference, word) if x != y) == 1
20
+
21
+
22
+def check_letter_swap(word, reference):
23
+    if len(word) != len(reference):
24
+        return False
25
+
26
+    for i in range(len(word) - 1):
27
+        if word[i] != reference[i]:
28
+            return word[i + 1] + word[i] + word[i + 2 :] == reference[i:]
29
+
30
+    return False
31
+
32
+
33
+def check_typo(word, reference):
34
+    if len(reference) == len(word):
35
+        return _check_single_letter_differ(word, reference) or \
36
+            _check_letter_swap(word, reference)
37
+    else:
38
+        return _check_extra_or_missing_letter(word, reference)
39
+
40
+
41
+def find_value_around_index(messages, value, idx, amplitude) -> int:
42
+    check_value = lambda x: msg_val.get(messages[x]) == value
43
+
44
+    if check_value(idx):
45
+        return idx
46
+
47
+    for offset in range(1, amplitude):
48
+        o_idx = idx + offset * +1
49
+        if check_value(o_idx):
50
+            return o_idx
51
+
52
+        o_idx = idx + offset * -1
53
+        if check_value(o_idx):
54
+            return o_idx
55
+
56
+    return -1
57
+

+ 34
- 12
test/model/message_test.py Целия файл

@@ -1,28 +1,50 @@
1
-
2
-
3
-from million.model.message import Message
4 1
 import million.analyze.message_evaluation as msg_val
5 2
 from test.TestCase import TestCase
6 3
 
7 4
 
8 5
 class MessageTest(TestCase):
9 6
 
10
-    def test_message_nominal(self, overrides=None, exclude=None):
7
+    def test_single_digit(self, overrides=None, exclude=None):
11 8
         message = self._message_with_text("1")
12 9
 
13 10
         assert 1 == msg_val.get(message)
14 11
 
12
+    def test_message_nominal(self, overrides=None, exclude=None):
13
+        message = self._message_with_text("1234")
14
+
15
+        assert 1234 == msg_val.get(message)
16
+
15 17
     def test_message_with_text(self, overrides=None, exclude=None):
16
-        message = self._message_with_text("1 text")
18
+        message = self._message_with_text("... 😏😏 269")
17 19
 
18
-        assert 1 == msg_val.get(message)
20
+        assert 269 == msg_val.get(message)
19 21
 
20
-    def test_message_floored_dot(self, overrides=None, exclude=None):
21
-        message = self._message_with_text("1.5")
22
+    def test_message_with_text_2(self, overrides=None, exclude=None):
23
+        message = self._message_with_text("331 allez la")
22 24
 
23
-        assert 1 == msg_val.get(message)
25
+        assert 331 == msg_val.get(message)
24 26
 
25
-    def test_message_floored_comma(self, overrides=None, exclude=None):
26
-        message = self._message_with_text("1,5")
27
+    def test_message_with_text_3(self, overrides=None, exclude=None):
28
+        message = self._message_with_text("Ok 2160")
27 29
 
28
-        assert 1 == msg_val.get(message)
30
+        assert 2160 == msg_val.get(message)
31
+
32
+    def test_message_value_cut(self, overrides=None, exclude=None):
33
+        message = self._message_with_text("66...😏😏😏9")
34
+
35
+        assert 669 == msg_val.get(message)
36
+
37
+    def test_message_value_cut_2(self, overrides=None, exclude=None):
38
+        message = self._message_with_text("82heyyyyyy69")
39
+
40
+        assert 8269 == msg_val.get(message)
41
+
42
+    def test_message_value_cut_2(self, overrides=None, exclude=None):
43
+        message = self._message_with_text("9339 9339 9339 9339")
44
+
45
+        assert 9339 == msg_val.get(message)
46
+
47
+    def test_message_in_middle(self, overrides=None, exclude=None):
48
+        message = self._message_with_text("A peine 5565 ouais...")
49
+
50
+        assert 5565 == msg_val.get(message)

+ 76
- 0
test/model/typo_test.py Целия файл

@@ -0,0 +1,76 @@
1
+import million.analyze.count_analysis as ca
2
+from test.TestCase import TestCase
3
+
4
+
5
+class TypoTest(TestCase):
6
+
7
+    def test_missing_letter_1(self, overrides=None, exclude=None):
8
+        assert ca.check_extra_or_missing_letter("4976", "45976") == True
9
+
10
+    def test_missing_letter_2(self, overrides=None, exclude=None):
11
+        assert ca.check_extra_or_missing_letter("4596", "45976") == True
12
+
13
+    def test_missing_letter_3(self, overrides=None, exclude=None):
14
+        assert ca.check_extra_or_missing_letter("5976", "45976") == True
15
+
16
+    def test_missing_letter_4(self, overrides=None, exclude=None):
17
+        assert ca.check_extra_or_missing_letter("4597", "45976") == True
18
+
19
+
20
+    
21
+    def test_extra_letter_1(self, overrides=None, exclude=None):
22
+        assert ca.check_extra_or_missing_letter("459766", "45976") == True
23
+
24
+    def test_extra_letter_2(self, overrides=None, exclude=None):
25
+        assert ca.check_extra_or_missing_letter("545976", "45976") == True
26
+
27
+    def test_extra_letter_3(self, overrides=None, exclude=None):
28
+        assert ca.check_extra_or_missing_letter("452976", "45976") == True
29
+
30
+    def test_extra_letter_4(self, overrides=None, exclude=None):
31
+        assert ca.check_extra_or_missing_letter("459776", "45976") == True
32
+
33
+    def test_extra_letter_5(self, overrides=None, exclude=None):
34
+        assert ca.check_extra_or_missing_letter("45976", "45976") == False
35
+
36
+
37
+    def test_single_letter_differ_1(self, overrides=None, exclude=None):
38
+        assert ca.check_single_letter_differ("35976", "45976") == True
39
+
40
+    def test_single_letter_differ_2(self, overrides=None, exclude=None):
41
+        assert ca.check_single_letter_differ("45986", "45976") == True
42
+
43
+    def test_single_letter_differ_3(self, overrides=None, exclude=None):
44
+        assert ca.check_single_letter_differ("44986", "45976") == False
45
+
46
+    def test_single_letter_differ_4(self, overrides=None, exclude=None):
47
+        assert ca.check_single_letter_differ("35975", "45976") == False
48
+
49
+    def test_single_letter_differ_5(self, overrides=None, exclude=None):
50
+        assert ca.check_single_letter_differ("4976", "45976") == False
51
+
52
+    def test_single_letter_differ_6(self, overrides=None, exclude=None):
53
+        assert ca.check_single_letter_differ("4597", "45976") == False
54
+        
55
+    def test_single_letter_differ_7(self, overrides=None, exclude=None):
56
+        assert ca.check_single_letter_differ("45976", "45976") == False
57
+
58
+
59
+    
60
+    def test_letter_swap_1(self, overrides=None, exclude=None):
61
+        assert ca.check_letter_swap("45976", "45976") == False
62
+
63
+    def test_letter_swap_2(self, overrides=None, exclude=None):
64
+        assert ca.check_letter_swap("49576", "45976") == True
65
+
66
+    def test_letter_swap_3(self, overrides=None, exclude=None):
67
+        assert ca.check_letter_swap("45967", "45976") == True
68
+
69
+    def test_letter_swap_4(self, overrides=None, exclude=None):
70
+        assert ca.check_letter_swap("47956", "45976") == False
71
+
72
+    def test_letter_swap_5(self, overrides=None, exclude=None):
73
+        assert ca.check_letter_swap("54966", "45976") == False
74
+
75
+    def test_letter_swap_6(self, overrides=None, exclude=None):
76
+        assert ca.check_letter_swap("54967", "45976") == False

Loading…
Отказ
Запис