def test_top_when_there_are_more_keys_than_the_limit_encountered_equal_times( self): logs = [ { "timestamp": "2020-05-11T13:42:50", "status": "error", "countryISO2": "BG" }, { "timestamp": "2020-05-11T13:43:20", "status": "success", "countryISO2": "UK" }, { "timestamp": "2020-05-11T13:44:30", "status": "warning", "countryISO2": "NZ" }, ] res = set(solution.top(logs, 'status', 2).items()) expected = set({"error": 1, "success": 1, "warning": 1}.items()) self.assertEqual(len(res), 2, msg="len(result) != 2") self.assertTrue(res < expected)
def test_top(self): logs = [ { "timestamp": "2020-05-11T13:42:50", "status": "error", "countryISO2": "BG" }, { "timestamp": "2020-05-11T13:43:20", "status": "success", "countryISO2": "UK" }, { "timestamp": "2020-05-11T13:44:30", "status": "success", "countryISO2": "NZ" }, ] res = solution.top(logs, 'status', 2) self.assertEqual({'success': 2, 'error': 1}, res)
def test_top_returns_all_matchings_if_N_is_bigger_than_count_of_logs(self): res = solution.top(self.logs, 'status', 100) self.assertEqual({'success': 2, 'error': 1}, res)
def test_top_returns_multiple_results_in_correct_order(self): res = solution.top(self.logs, 'status', 2) self.assertEqual({'success': 2, 'error': 1}, res)
def test_top_returns_top_one_result(self): res = solution.top(self.logs, 'status', 1) self.assertEqual({'success': 2}, res)
def test_top_when_no_logs(self): res = solution.top([], 'status', 0) self.assertEqual({}, res)
def test_top_return_top_zero(self): res = solution.top(self.logs, 'status', 0) self.assertEqual({}, res)
def test_top_when_count_greater_than_logs_count(self): res = solution.top(self.logs, 'status', 10) self.assertEqual({'success': 2, 'error': 1, 'warning': 1}, res)
def test_top_when_key_not_found(self): res = solution.top(self.logs, 'random_key', 2) self.assertEqual({}, res)
def test_top(self): res = solution.top(self.logs, 'status', 2) self.assertEqual({'success': 2, 'error': 1}, res)