From 5002b2e1e9b7918848c7239de2b08ab5012b4cc9 Mon Sep 17 00:00:00 2001 From: Boyko03 Date: Wed, 21 Oct 2020 16:33:17 +0300 Subject: [PATCH 1/2] Fixed typos --- school_year_2020_2021/homework_1/README.md | 2 +- school_year_2020_2021/homework_1/sample_test.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/school_year_2020_2021/homework_1/README.md b/school_year_2020_2021/homework_1/README.md index f207dd3..9a5ec2b 100644 --- a/school_year_2020_2021/homework_1/README.md +++ b/school_year_2020_2021/homework_1/README.md @@ -80,7 +80,7 @@ complex_filter(logs, {"status": "success", "countryISO2": "NZ"}) => [{'timestamp': '2020-05-11T13:44:30', 'status': 'success', 'countryISO2': 'NZ'}] # Да вземем само съобщенията, които имат status = "error" И countryISO2 = "UK" -complex_filter(logs, {"status": "success", "countryISO2": "NZ"}) +complex_filter(logs, {"status": "error", "countryISO2": "UK"}) => [] # Да вземем само съобщенията, които имат status = "error" diff --git a/school_year_2020_2021/homework_1/sample_test.py b/school_year_2020_2021/homework_1/sample_test.py index 5c05bc7..59365dd 100644 --- a/school_year_2020_2021/homework_1/sample_test.py +++ b/school_year_2020_2021/homework_1/sample_test.py @@ -1,6 +1,7 @@ import unittest import solution + class SolutionTest(unittest.TestCase): def test_filter_logs(self): @@ -21,7 +22,7 @@ def test_top(self): res = solution.top(logs, 'status', 2) self.assertEqual({'success': 2, 'error': 1}, res) - def test_top(self): + def test_complex_filter(self): logs = [ {"timestamp": "2020-05-11T13:42:50", "status": "error", "countryISO2": "BG"}, {"timestamp": "2020-05-11T13:43:20", "status": "success", "countryISO2": "UK"}, From 68a6024d454de1ed76b73ef4c15d17a16d248a76 Mon Sep 17 00:00:00 2001 From: Boyko03 Date: Fri, 23 Oct 2020 19:03:08 +0300 Subject: [PATCH 2/2] Added more tests --- .../homework_1/sample_test.py | 82 +++++++++++++------ 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/school_year_2020_2021/homework_1/sample_test.py b/school_year_2020_2021/homework_1/sample_test.py index 59365dd..44da258 100644 --- a/school_year_2020_2021/homework_1/sample_test.py +++ b/school_year_2020_2021/homework_1/sample_test.py @@ -3,33 +3,67 @@ class SolutionTest(unittest.TestCase): - - def test_filter_logs(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.filter_logs(logs, 'status', 'error') - self.assertEqual([logs[0]], res) - - 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"}, + def setUp(self): + 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) + + def test_filter_logs_returns_all_matching_logs(self): + res = solution.filter_logs(self.logs, 'status', 'error') + self.assertEqual([self.logs[0]], res) + + res = solution.filter_logs(self.logs, 'status', 'success') + self.assertEqual([self.logs[1], self.logs[2]], res) + + def test_filter_logs_returns_empty_list_if_no_matchings_found(self): + res = solution.filter_logs(self.logs, 'status', 'no_status') + self.assertEqual([], res) + + def test_top_returns_top_one_result(self): + res = solution.top(self.logs, 'status', 1) + self.assertEqual({'success': 2}, 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_complex_filter(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.complex_filter(logs, {"status": "success", "countryISO2": "NZ"}) - self.assertEqual([logs[2]], 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_complex_filter_with_one_param(self): + res = solution.complex_filter( + self.logs, {"status": "error"}) + self.assertEqual([self.logs[0]], res) + + def test_complex_filter_with_multiple_params(self): + res = solution.complex_filter( + self.logs, {"status": "success", "countryISO2": "NZ"}) + self.assertEqual([self.logs[2]], res) + + def test_complex_filter_returns_empty_list_if_no_params_match(self): + res = solution.complex_filter( + self.logs, {"status": "error", "countryISO2": "UK"}) + self.assertEqual([], res) + + def test_complex_filter_returns_all_logs_if_no_params_are_given(self): + res = solution.complex_filter( + self.logs, {}) + self.assertEqual(self.logs, res) if __name__ == "__main__":