Skip to content

Instantly share code, notes, and snippets.

@LosantGists
Created July 23, 2021 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LosantGists/3da0fb69664ab03e0b1967093fed8231 to your computer and use it in GitHub Desktop.
Save LosantGists/3da0fb69664ab03e0b1967093fed8231 to your computer and use it in GitHub Desktop.
Automating Unit Tests Blog (11) 7.23.21
import pandas as pd
import importlib
nb = importlib.import_module("ipynb.fs.defs.battery-stats")
is_row_before_charging = nb.is_row_before_charging
# it should return True if the change from the previous row is positive (isn't charging)
# and the change to the next row is negative (will be charging)
about_to_charge = pd.DataFrame({
"battery_loss_this_row": [3],
"battery_loss_next_row": [-5]
})
assert is_row_before_charging( about_to_charge.iloc[0] )
# it should return False if the change from the previous row is negative (already charging)
charging = pd.DataFrame({
"battery_loss_this_row": [-3],
"battery_loss_next_row": [-5]
})
assert not is_row_before_charging( charging.iloc[0] )
# it should return False if the change to the previous row is positive (will not be charging)
discharging = pd.DataFrame({
"battery_loss_this_row": [3],
"battery_loss_next_row": [5]
})
assert not is_row_before_charging( discharging.iloc[0] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment