exercism

Exercism solutions.
git clone git://code.dwrz.net/exercism
Log | Files | Refs

high_scores_test.py (1860B)


      1 import unittest
      2 
      3 from high_scores import (
      4     latest,
      5     latest_after_top_three,
      6     personal_best,
      7     personal_top_three,
      8     scores_after_top_three,
      9 )
     10 
     11 # Tests adapted from `problem-specifications//canonical-data.json`
     12 
     13 
     14 class HighScoresTest(unittest.TestCase):
     15     def test_latest_score(self):
     16         scores = [100, 0, 90, 30]
     17         expected = 30
     18         self.assertEqual(latest(scores), expected)
     19 
     20     def test_personal_best(self):
     21         scores = [40, 100, 70]
     22         expected = 100
     23         self.assertEqual(personal_best(scores), expected)
     24 
     25     def test_personal_top_three_from_a_list_of_scores(self):
     26         scores = [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]
     27         expected = [100, 90, 70]
     28         self.assertEqual(personal_top_three(scores), expected)
     29 
     30     def test_personal_top_highest_to_lowest(self):
     31         scores = [20, 10, 30]
     32         expected = [30, 20, 10]
     33         self.assertEqual(personal_top_three(scores), expected)
     34 
     35     def test_personal_top_when_there_is_a_tie(self):
     36         scores = [40, 20, 40, 30]
     37         expected = [40, 40, 30]
     38         self.assertEqual(personal_top_three(scores), expected)
     39 
     40     def test_personal_top_when_there_are_less_than_3(self):
     41         scores = [30, 70]
     42         expected = [70, 30]
     43         self.assertEqual(personal_top_three(scores), expected)
     44 
     45     def test_personal_top_when_there_is_only_one(self):
     46         scores = [40]
     47         expected = [40]
     48         self.assertEqual(personal_top_three(scores), expected)
     49 
     50     def test_latest_score_after_personal_top_scores(self):
     51         scores = [70, 50, 20, 30]
     52         expected = 30
     53         self.assertEqual(latest_after_top_three(scores), expected)
     54 
     55     def test_scores_after_personal_top_scores(self):
     56         scores = [30, 50, 20, 70]
     57         expected = [30, 50, 20, 70]
     58         self.assertEqual(scores_after_top_three(scores), expected)