Beispiel #1
0
 def setUp(self):
     self.exercise_type = ExerciseType("Exercise type name", "Exercise type description", "42")
Beispiel #2
0
class TestExerciseType(unittest.TestCase):
    'Test the ExerciseType class'
    
    # Before each test
    def setUp(self):
        self.exercise_type = ExerciseType("Exercise type name", "Exercise type description", "42")
 
    # After each test
    def tearDown(self):
        self.exercise_type = None
    
    # Tests for load_score
    def test_load_score_empty(self):
        empty_dict = {}
        self.exercise_type.load_score(empty_dict)
        self.assertEqual(self.exercise_type.top_score, 0) 
        self.assertEqual(self.exercise_type.last_score, 0)
    
    def test_load_score_normal(self):
        score_dict = {"2011": 12, "2015": 14, "2013": 16, "2014": 13}
        self.exercise_type.load_score(score_dict)
        self.assertEqual(self.exercise_type.top_score, 16)
        self.assertEqual(self.exercise_type.last_score, 14)
        
    # Tests for load_score_from_whole_dict
    def test_load_score_from_whole_dict(self):
        all_score_dict = {}
        self_score_dict = {"2011": 12, "2015": 14, "2013": 16, "2014": 13}
        all_score_dict["Exercise type name"] = self_score_dict
        other_ex_dict = {"1970": 42}
        all_score_dict["other exercise"] = other_ex_dict
        self.exercise_type.load_score_from_whole_dict(all_score_dict)
        self.assertEqual(self.exercise_type.top_score, 16)
        self.assertEqual(self.exercise_type.last_score, 14)
        
    # Tests for register_score
    def test_register_score(self):
        self.exercise_type.register_score(16)
        self.assertEqual(self.exercise_type.top_score, 16)
        self.assertEqual(self.exercise_type.last_score, 16)
        self.exercise_type.register_score(18)
        self.assertEqual(self.exercise_type.top_score, 18)
        self.assertEqual(self.exercise_type.last_score, 18)
        self.exercise_type.register_score(12)
        self.assertEqual(self.exercise_type.top_score, 18)
        self.assertEqual(self.exercise_type.last_score, 12)
        
    def test_apply(self):
        application = self.exercise_type.apply()
        self.assertEqual(application.name, self.exercise_type.name)
        self.assertEqual(len(application.series_list), 0)
        self.assertEqual(application.total_repetitions, 0)