-
Notifications
You must be signed in to change notification settings - Fork 0
/
asl_test_recognizer.py
31 lines (27 loc) · 1.62 KB
/
asl_test_recognizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from unittest import TestCase
import unittest
from asl_data import AslDb
from asl_utils import train_all_words
from my_model_selectors import SelectorConstant
from my_recognizer import recognize
FEATURES = ['right-y', 'right-x']
class TestRecognize(TestCase):
def setUp(self):
self.asl = AslDb()
self.training_set = self.asl.build_training(FEATURES)
self.test_set = self.asl.build_test(FEATURES)
self.models = train_all_words(self.training_set, SelectorConstant)
def test_recognize_probabilities_interface(self):
probs, _ = recognize(self.models, self.test_set)
self.assertEqual(len(probs), self.test_set.num_items, "Number of test items in probabilities list incorrect.")
self.assertEqual(len(probs[0]), self.training_set.num_items,
"Number of training word probabilities in test item dictionary incorrect.")
self.assertEqual(len(probs[-1]), self.training_set.num_items,
"Number of training word probabilities in test item dictionary incorrect.")
self.assertIn('FRANK', probs[0], "Dictionary of probabilities does not contain correct keys")
self.assertIn('CHICKEN', probs[-1], "Dictionary of probabilities does not contain correct keys")
def test_recognize_guesses_interface(self):
_, guesses = recognize(self.models, self.test_set)
self.assertEqual(len(guesses), self.test_set.num_items, "Number of test items in guesses list incorrect.")
self.assertIsInstance(guesses[0], str, "The guesses are not strings")
self.assertIsInstance(guesses[-1], str, "The guesses are not strings")