alessandro trinca tornidor commited on
Commit
58d92fd
·
1 Parent(s): 42e76ea

test: add some test cases for the python module WordMatching

Browse files
cosmic_ray_config.toml CHANGED
@@ -1,8 +1,8 @@
1
  [cosmic-ray]
2
- module-path = "aip_trainer/lambdas/lambdaSpeechToScore.py"
3
  timeout = 30.0
4
  excluded-modules = []
5
- test-command = "python -m pytest tests/lambdas/test_lambdaSpeechToScore.py tests/lambdas/test_lambdaSpeechToScore_librosa.py"
6
 
7
  [cosmic-ray.distributor]
8
  name = "local"
 
1
  [cosmic-ray]
2
+ module-path = "aip_trainer/WordMatching.py"
3
  timeout = 30.0
4
  excluded-modules = []
5
+ test-command = "python -m pytest tests/test_worldmatching.py"
6
 
7
  [cosmic-ray.distributor]
8
  name = "local"
tests/test_worldmatching.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+ import numpy as np
3
+ from aip_trainer import WordMatching
4
+
5
+
6
+ class TestWordMatching(unittest.TestCase):
7
+
8
+ def test_get_word_distance_matrix(self):
9
+ words_estimated = ["hello", "world"]
10
+ words_real = ["hello", "word"]
11
+ expected_matrix = np.array([[0.0, 5.0], [4.0, 1.0], [5.0, 4.0]])
12
+ result_matrix = WordMatching.get_word_distance_matrix(words_estimated, words_real)
13
+ np.testing.assert_array_equal(result_matrix, expected_matrix)
14
+
15
+ def test_get_best_path_from_distance_matrix(self):
16
+ word_distance_matrix = np.array([[0, 4], [5, 1], [5, 4]])
17
+ expected_indices = np.array([0, 1])
18
+ result_indices = WordMatching.get_best_path_from_distance_matrix(word_distance_matrix)
19
+ np.testing.assert_array_equal(result_indices, expected_indices)
20
+
21
+ def test_get_resulting_string(self):
22
+ mapped_indices = np.array([0, 1])
23
+ words_estimated = ["hello", "world"]
24
+ words_real = ["hello", "word"]
25
+ expected_words = ["hello", "world"]
26
+ expected_indices = [0, 1]
27
+ result_words, result_indices = WordMatching.get_resulting_string(mapped_indices, words_estimated, words_real)
28
+ self.assertEqual(result_words, expected_words)
29
+ self.assertEqual(result_indices, expected_indices)
30
+
31
+ def test_getWhichLettersWereTranscribedCorrectly(self):
32
+ real_word = "hello"
33
+ transcribed_word = "hxllo"
34
+ expected_result = [1, 0, 1, 1, 1]
35
+ result = WordMatching.getWhichLettersWereTranscribedCorrectly(real_word, transcribed_word)
36
+ self.assertEqual(result, expected_result)
37
+
38
+ def test_get_best_mapped_words(self):
39
+ words_estimated = ["hello", "world"]
40
+ words_real = ["hello", "word"]
41
+ expected_words = ["hello", "world"]
42
+ expected_indices = [0, 1]
43
+ result_words, result_indices = WordMatching.get_best_mapped_words(words_estimated, words_real)
44
+ self.assertEqual(result_words, expected_words)
45
+ self.assertEqual(result_indices, expected_indices)
46
+
47
+
48
+ if __name__ == '__main__':
49
+ unittest.main()