|
3 | 3 | import pandas as pd
|
4 | 4 | import pytest
|
5 | 5 |
|
6 |
| -from problems.pandas import problem_176, problem_584, problem_1321, problem_1757 |
| 6 | +from problems.pandas import ( |
| 7 | + problem_176, |
| 8 | + problem_584, |
| 9 | + problem_595, |
| 10 | + problem_1321, |
| 11 | + problem_1757, |
| 12 | +) |
7 | 13 |
|
8 | 14 |
|
9 | 15 | @pytest.mark.parametrize(
|
@@ -82,6 +88,60 @@ def test_problem_584(input_data, expected_data):
|
82 | 88 | ), f"Expected table {expected_table}, but got {result}"
|
83 | 89 |
|
84 | 90 |
|
| 91 | +@pytest.mark.parametrize( |
| 92 | + "input_data, expected_data", |
| 93 | + [ |
| 94 | + pytest.param( |
| 95 | + { |
| 96 | + "name": ["Afghanistan", "Albania", "Algeria", "Andorra", "Angola"], |
| 97 | + "continent": ["Asia", "Europe", "Africa", "Europe", "Africa"], |
| 98 | + "area": [652_230, 28_748, 2_381_741, 468, 1_246_700], |
| 99 | + "population": [25_500_100, 2_831_741, 37_100_000, 78_115, 20_609_294], |
| 100 | + "gdp": [ |
| 101 | + 20_343_000_000, |
| 102 | + 12_960_000_000, |
| 103 | + 188_681_000_000, |
| 104 | + 3_712_000_000, |
| 105 | + 100_990_000_000, |
| 106 | + ], |
| 107 | + }, |
| 108 | + { |
| 109 | + "name": ["Afghanistan", "Algeria"], |
| 110 | + "population": [25_500_100, 37_100_000], |
| 111 | + "area": [652_230, 2_381_741], |
| 112 | + }, |
| 113 | + id="happy_path_various_countries", |
| 114 | + ), |
| 115 | + pytest.param( |
| 116 | + { |
| 117 | + "name": ["CountryA", "CountryB"], |
| 118 | + "continent": ["ContinentA", "ContinentB"], |
| 119 | + "area": [3_000_000, 4_000_000], |
| 120 | + "population": [30_000_000, 40_000_000], |
| 121 | + "gdp": [1_000_000_000, 2_000_000_000], |
| 122 | + }, |
| 123 | + { |
| 124 | + "name": ["CountryA", "CountryB"], |
| 125 | + "population": [30_000_000, 40_000_000], |
| 126 | + "area": [3_000_000, 4_000_000], |
| 127 | + }, |
| 128 | + id="edge_case_all_countries_meeting_criteria", |
| 129 | + ), |
| 130 | + ], |
| 131 | +) |
| 132 | +def test_problem_595(input_data, expected_data): |
| 133 | + table = pd.DataFrame(input_data) |
| 134 | + expected_table = pd.DataFrame(expected_data) |
| 135 | + result = problem_595(table).reset_index(drop=True) |
| 136 | + if result.shape == (0, len(expected_table.columns)): |
| 137 | + assert result.shape == expected_table.shape |
| 138 | + assert result.columns.equals(expected_table.columns) |
| 139 | + else: |
| 140 | + assert result.equals( |
| 141 | + expected_table |
| 142 | + ), f"Expected table {expected_table}, but got {result}" |
| 143 | + |
| 144 | + |
85 | 145 | @pytest.mark.parametrize(
|
86 | 146 | "input_data, expected_data",
|
87 | 147 | [
|
|
0 commit comments