|
3 | 3 | import pandas as pd
|
4 | 4 | import pytest
|
5 | 5 |
|
6 |
| -from problems.pandas import problem_176, problem_1321, problem_1757 |
| 6 | +from problems.pandas import problem_176, problem_584, problem_1321, problem_1757 |
7 | 7 |
|
8 | 8 |
|
9 | 9 | @pytest.mark.parametrize(
|
@@ -37,6 +37,51 @@ def test_problem_176(input_data, expected_data):
|
37 | 37 | assert result.equals(expected_table)
|
38 | 38 |
|
39 | 39 |
|
| 40 | +@pytest.mark.parametrize( |
| 41 | + "input_data, expected_data", |
| 42 | + [ |
| 43 | + pytest.param( |
| 44 | + { |
| 45 | + "id": [1, 2, 4, 5], |
| 46 | + "name": ["Will", "Jane", "Bill", "Zack"], |
| 47 | + "referee_id": [None, None, None, 1], |
| 48 | + }, |
| 49 | + {"name": ["Will", "Jane", "Bill", "Zack"]}, |
| 50 | + id="happy_path_all_valid", |
| 51 | + ), |
| 52 | + pytest.param( |
| 53 | + { |
| 54 | + "id": [3, 6], |
| 55 | + "name": ["Alex", "Mark"], |
| 56 | + "referee_id": [2, 2], |
| 57 | + }, |
| 58 | + {"name": []}, |
| 59 | + id="edge_case_all_referee_id_2", |
| 60 | + ), |
| 61 | + pytest.param( |
| 62 | + { |
| 63 | + "id": [1, 3, 5, 6], |
| 64 | + "name": ["Will", "Alex", "Zack", "Mark"], |
| 65 | + "referee_id": [None, 2, 1, 2], |
| 66 | + }, |
| 67 | + {"name": ["Will", "Zack"]}, |
| 68 | + id="mixed_case_some_valid", |
| 69 | + ), |
| 70 | + ], |
| 71 | +) |
| 72 | +def test_problem_584(input_data, expected_data): |
| 73 | + table = pd.DataFrame(input_data) |
| 74 | + expected_table = pd.DataFrame(expected_data) |
| 75 | + result = problem_584(table).reset_index(drop=True) |
| 76 | + if result.shape == (0, len(expected_table.columns)): |
| 77 | + assert result.shape == expected_table.shape |
| 78 | + assert result.columns.equals(expected_table.columns) |
| 79 | + else: |
| 80 | + assert result.equals( |
| 81 | + expected_table |
| 82 | + ), f"Expected table {expected_table}, but got {result}" |
| 83 | + |
| 84 | + |
40 | 85 | @pytest.mark.parametrize(
|
41 | 86 | "input_data, expected_data",
|
42 | 87 | [
|
@@ -162,11 +207,9 @@ def test_problem_1321(input_data, expected_data):
|
162 | 207 | "recyclable": ["Y", "Y", "Y", "Y", "Y"],
|
163 | 208 | },
|
164 | 209 | {"product_id": [0, 1, 2, 3, 4]},
|
165 |
| - ) |
166 |
| - ], |
167 |
| - ids=[ |
168 |
| - "happy_path_mixed_values", "all_ys" |
| 210 | + ), |
169 | 211 | ],
|
| 212 | + ids=["happy_path_mixed_values", "all_ys"], |
170 | 213 | )
|
171 | 214 | def test_problem_1757(input_data, expected_data):
|
172 | 215 | table = pd.DataFrame(input_data)
|
|
0 commit comments