Skip to content

Commit

Permalink
refactor: simplify testing by removing need to .copy()
Browse files Browse the repository at this point in the history
  • Loading branch information
danielolsen committed Jun 11, 2020
1 parent 0c50759 commit 4b039b2
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions postreise/analyze/generation/tests/test_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,31 @@ def setUp(self):
})
self.default_expected.set_index('UTC', inplace=True)

def get_default_expected(self):
return self.default_expected.copy()

def test_ramp_constraints_default(self):
binding_ramps = ramp_constraints(self.mock_scenario)
expected = self.default_expected.copy()
assert binding_ramps.equals(expected)
expected = self.get_default_expected()
assert binding_ramps.equals(self.get_default_expected())

def test_ramp_constraints_spec_epsilon1(self):
# Same results as test_ramp_constraints_default
binding_ramps = ramp_constraints(self.mock_scenario, epsilon=1e-3)
expected = self.default_expected.copy()
expected = self.get_default_expected()
assert binding_ramps.equals(expected)

def test_ramp_constraints_spec_epsilon2(self):
# One differece from test_ramp_constraints_default: ('A', 't3')
binding_ramps = ramp_constraints(self.mock_scenario, epsilon=1e-6)
expected = self.default_expected.copy()
expected = self.get_default_expected()
expected.loc['t3', 'A'] = False
assert binding_ramps.equals(expected)

def test_ramp_constraints_spec_epsilon3(self):
# Two differeces from test_ramp_constraints_default: ('A', ['t3'/'t4'])
binding_ramps = ramp_constraints(self.mock_scenario, epsilon=1e-9)
expected = self.default_expected.copy()
expected = self.get_default_expected()
expected.loc[:, 'A'] = False
assert binding_ramps.equals(expected)

Expand Down Expand Up @@ -131,25 +134,28 @@ def setUp(self):
})
self.default_expected.set_index('UTC', inplace=True)

def get_default_expected(self):
return self.default_expected.copy()

def test_pmin_constraints_default(self):
binding_pmins = pmin_constraints(self.mock_scenario)
expected = self.default_expected.copy()
expected = self.get_default_expected()
assert binding_pmins.equals(expected)

def test_pmin_constraints_default_spec_epsilon1(self):
binding_pmins = pmin_constraints(self.mock_scenario, epsilon=1e-3)
expected = self.default_expected.copy()
expected = self.get_default_expected()
assert binding_pmins.equals(expected)

def test_pmin_constraints_default_spec_epsilon2(self):
binding_pmins = pmin_constraints(self.mock_scenario, epsilon=1e-6)
expected = self.default_expected.copy()
expected = self.get_default_expected()
expected.loc['t1', 'B'] = False
assert binding_pmins.equals(expected)

def test_pmin_constraints_default_spec_epsilon3(self):
binding_pmins = pmin_constraints(self.mock_scenario, epsilon=1e-9)
expected = self.default_expected.copy()
expected = self.get_default_expected()
expected.loc['t1', 'B'] = False
expected.loc['t2', 'C'] = False
assert binding_pmins.equals(expected)
Expand Down Expand Up @@ -181,25 +187,28 @@ def setUp(self):
})
self.default_expected.set_index('UTC', inplace=True)

def get_default_expected(self):
return self.default_expected.copy()

def test_pmax_constraints_default(self):
binding_pmaxs = pmax_constraints(self.mock_scenario)
expected = self.default_expected.copy()
expected = self.get_default_expected()
assert binding_pmaxs.equals(expected)

def test_pmax_constraints_default_sepc_epsilon1(self):
binding_pmaxs = pmax_constraints(self.mock_scenario, epsilon=1e-3)
expected = self.default_expected.copy()
expected = self.get_default_expected()
assert binding_pmaxs.equals(expected)

def test_pmax_constraints_default_sepc_epsilon2(self):
binding_pmaxs = pmax_constraints(self.mock_scenario, epsilon=1e-6)
expected = self.default_expected.copy()
expected = self.get_default_expected()
expected.loc['t1', 'B'] = False
assert binding_pmaxs.equals(expected)

def test_pmax_constraints_default_sepc_epsilon3(self):
binding_pmaxs = pmax_constraints(self.mock_scenario, epsilon=1e-9)
expected = self.default_expected.copy()
expected = self.get_default_expected()
expected.loc['t1', 'B'] = False
expected.loc['t2', 'C'] = False
assert binding_pmaxs.equals(expected)

0 comments on commit 4b039b2

Please sign in to comment.