Skip to content

Commit

Permalink
Update unit tests for unit_conversions. Update distance column in the…
Browse files Browse the repository at this point in the history
… before_df and after_df dataframe.
  • Loading branch information
iantei committed Nov 28, 2024
1 parent 8952810 commit aaf7a9e
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions viz_scripts/tests/test_scaffolding.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def before_df():
"Mode_confirm":["Other", "Other", "Walk", "Bus", "Walk", "Car", "Bike", "Bike"],
"raw_trip":["trip_0", "trip_1", "trip_2", "trip_3", "trip_4", "trip_5", "trip_6", "trip_7"],
"start_ts":[1.690e+09, 1.690e+09, 1.690e+09, 1.690e+09, 1.690e+09, 1.690e+09, 1.690e+09, 1.690e+09],
"duration": [1845.26, 1200.89, 1000.56, 564.54, 456.456, 156.45, 1564.456, 156.564]
"duration": [1845.26, 1200.89, 1000.56, 564.54, 456.456, 156.45, 1564.456, 156.564],
"distance": [100, 150, 600, 500, 300, 200, 50, 20]
})

@pytest.fixture
Expand All @@ -150,7 +151,8 @@ def after_df():
"Mode_confirm":["Other", "Other", "Bike", "Bike"],
"raw_trip":["trip_0", "trip_1", "trip_6", "trip_7"],
"start_ts":[1.690e+09, 1.690e+09, 1.690e+09, 1.690e+09],
"duration": [1845.26, 1200.89, 1564.456, 156.564]
"duration": [1845.26, 1200.89, 1564.456, 156.564],
"distance": [100, 150, 50, 20]
})

def test_get_quality_text(before_df, after_df):
Expand Down Expand Up @@ -196,4 +198,22 @@ def test_get_file_suffix():
month = 12
program = "default"
result = scaffolding.get_file_suffix(year, month, program)
assert result == "_2024_12_default"
assert result == "_2024_12_default"

def test_unit_conversions(before_df):
test_df = before_df.copy()
scaffolding.unit_conversions(test_df)
assert 'distance_miles' in test_df.columns
assert 'distance_kms' in test_df.columns

np.testing.assert_almost_equal(
test_df['distance_miles'],
[0.062, 0.093, 0.373, 0.311, 0.186, 0.124, 0.031, 0.012],
decimal=2
)

np.testing.assert_almost_equal(
test_df['distance_kms'],
[0.1, 0.15, 0.6, 0.5, 0.3, 0.2, 0.05, 0.02],
decimal=2
)

0 comments on commit aaf7a9e

Please sign in to comment.