Пример #1
0
 def test_sub_current_unequal_station_ids(self):
     curr_dict1 = {'PS-001' : 0.25, 'PS-002' : 0.50, 'PS-003' : -0.25}
     self.current1 = Current(curr_dict1)
     curr_dict2 = {'PS-006' : 0.30, 'PS-004' : -0.60, 'PS-002' : 0.50}
     self.current2 = Current(curr_dict2)
     self.diff_curr = self.current1 - self.current2
     self.assertIsInstance(self.diff_curr, Current)
     pd.testing.assert_series_equal(
         self.diff_curr, pd.Series(
             [0.25, 0.00, -0.25, 0.60, -0.30], index=['PS-001', 'PS-002', 'PS-003', 'PS-004', 'PS-006']))
Пример #2
0
 def test_add_current_equal_station_ids(self):
     curr_dict1 = {'PS-001' : 0.25, 'PS-002' : 0.50, 'PS-003' : -0.25}
     self.current1 = Current(curr_dict1)
     curr_dict2 = {'PS-001' : 0.30, 'PS-002' : -0.60, 'PS-003' : 0.50}
     self.current2 = Current(curr_dict2)
     self.sum_curr = self.current1 + self.current2
     self.assertIsInstance(self.sum_curr, Current)
     pd.testing.assert_series_equal(
         self.sum_curr, pd.Series(
             [0.55, -0.10, 0.25], index=['PS-001', 'PS-002', 'PS-003']))
Пример #3
0
 def setUp(self):
     self.network = ChargingNetwork()
     self.network.register_evse(EVSE('PS-001'), 240, 0)
     self.network.register_evse(EVSE('PS-004'), 240, 0)
     self.network.register_evse(EVSE('PS-003'), 240, 0)
     self.network.register_evse(EVSE('PS-002'), 240, 0)
     self.network.register_evse(EVSE('PS-006'), 240, 0)
     curr_dict1 = {'PS-001' : 0.25, 'PS-002' : 0.50, 'PS-003' : -0.25}
     current1 = Current(curr_dict1)
     curr_dict2 = {'PS-006' : 0.30, 'PS-004' : -0.60, 'PS-002' : 0.50}
     current2 = Current(curr_dict2)
     self.network.add_constraint(current1, 50, name='first_constraint')
     self.network.add_constraint(current2, 10)
Пример #4
0
 def setUp(self):
     self.network = ChargingNetwork()
     self.network.register_evse(EVSE("PS-001"), 240, 0)
     self.network.register_evse(EVSE("PS-004"), 240, 0)
     self.network.register_evse(EVSE("PS-003"), 240, 0)
     self.network.register_evse(EVSE("PS-002"), 240, 0)
     self.network.register_evse(EVSE("PS-006"), 240, 0)
     curr_dict1 = {"PS-001": 0.25, "PS-002": 0.50, "PS-003": -0.25}
     current1 = Current(curr_dict1)
     curr_dict2 = {"PS-006": 0.30, "PS-004": -0.60, "PS-002": 0.50}
     current2 = Current(curr_dict2)
     self.network.add_constraint(current1, 50, name="first_constraint")
     self.network.add_constraint(current2, 10)
Пример #5
0
 def test_add_current_equal_station_ids(self):
     curr_dict1 = {"PS-001": 0.25, "PS-002": 0.50, "PS-003": -0.25}
     self.current1 = Current(curr_dict1)
     curr_dict2 = {"PS-001": 0.30, "PS-002": -0.60, "PS-003": 0.50}
     self.current2 = Current(curr_dict2)
     self.sum_curr = self.current1 + self.current2
     self.assertIsInstance(self.sum_curr, Current)
     pd.testing.assert_series_equal(
         self.sum_curr,
         pd.Series([0.55, -0.10, 0.25],
                   index=["PS-001", "PS-002", "PS-003"]),
         check_series_type=False,
     )
Пример #6
0
 def test_sub_current_unequal_station_ids(self):
     curr_dict1 = {"PS-001": 0.25, "PS-002": 0.50, "PS-003": -0.25}
     self.current1 = Current(curr_dict1)
     curr_dict2 = {"PS-006": 0.30, "PS-004": -0.60, "PS-002": 0.50}
     self.current2 = Current(curr_dict2)
     self.diff_curr = self.current1 - self.current2
     self.assertIsInstance(self.diff_curr, Current)
     pd.testing.assert_series_equal(
         self.diff_curr,
         pd.Series(
             [0.25, 0.00, -0.25, 0.60, -0.30],
             index=["PS-001", "PS-002", "PS-003", "PS-004", "PS-006"],
         ),
     )
Пример #7
0
 def test_init_none_input(self):
     self.current = Current()
     # The object type is specified explicitly here to address a
     # warning in pandas 1.x.
     pd.testing.assert_series_equal(self.current,
                                    pd.Series(dtype="float64"),
                                    check_series_type=False)
Пример #8
0
 def test_mul_current(self):
     curr_dict = {'PS-001' : 0.25, 'PS-002' : 0.50, 'PS-003' : -0.25}
     self.current = Current(curr_dict)
     self.current *= 2
     self.assertIsInstance(self.current, Current)
     pd.testing.assert_series_equal(
         self.current, pd.Series(
             [0.50, 1.00, -0.5], index=['PS-001', 'PS-002', 'PS-003']))
Пример #9
0
 def test_update_constraint_new_name(self):
     curr_dict3 = {'PS-001' : -0.25, 'PS-002' : -0.50, 'PS-003' : 0.25}
     current3 = Current(curr_dict3)
     self.network.update_constraint('first_constraint', current3, 25, new_name='negated_first')
     self.assertEqual(self.network.constraint_index, ['_const_1', 'negated_first'])
     np.testing.assert_allclose(self.network.magnitudes, np.array([10, 25]))
     np.testing.assert_allclose(self.network.constraint_matrix,
         np.array([[0.00, -0.60, 0.00, 0.50, 0.30], [-0.25, 0.00, 0.25, -0.50, 0.00]]))
Пример #10
0
 def test_init_loads_dict_input(self):
     curr_dict = {"PS-001": 0.25, "PS-002": 0.50, "PS-003": -0.25}
     self.current = Current(curr_dict)
     pd.testing.assert_series_equal(
         self.current,
         pd.Series([0.25, 0.50, -0.25],
                   index=["PS-001", "PS-002", "PS-003"]),
     )
Пример #11
0
 def test_init_str_lst_input(self):
     curr_strs = ["PS-001", "PS-002", "PS-003"]
     self.current = Current(curr_strs)
     pd.testing.assert_series_equal(
         self.current,
         pd.Series([1, 1, 1], index=["PS-001", "PS-002", "PS-003"]),
         check_series_type=False,
     )
Пример #12
0
 def test_mul_current(self):
     curr_dict = {"PS-001": 0.25, "PS-002": 0.50, "PS-003": -0.25}
     self.current = Current(curr_dict)
     self.current *= 2
     self.assertIsInstance(self.current, Current)
     pd.testing.assert_series_equal(
         self.current,
         pd.Series([0.50, 1.00, -0.5], index=["PS-001", "PS-002",
                                              "PS-003"]),
     )
Пример #13
0
 def test_update_constraint(self) -> None:
     curr_dict3 = {"PS-001": -0.25, "PS-002": -0.50, "PS-003": 0.25}
     current3 = Current(curr_dict3)
     self.network.update_constraint("first_constraint", current3, 25)
     self.assertEqual(self.network.constraint_index,
                      ["_const_1", "first_constraint"])
     np.testing.assert_allclose(self.network.magnitudes, np.array([10, 25]))
     np.testing.assert_allclose(
         self.network.constraint_matrix,
         np.array([[0.00, -0.60, 0.00, 0.50, 0.30],
                   [-0.25, 0.00, 0.25, -0.50, 0.00]]),
     )
Пример #14
0
 def test_add_constraint_warning(self):
     curr_dict3 = {'PS-001' : -0.25, 'PS-002' : -0.50, 'PS-003' : 0.25}
     current3 = Current(curr_dict3)
     with self.assertWarns(UserWarning):
         self.network.add_constraint(current3, 25, name='_const_1')
     np.testing.assert_allclose(self.network.magnitudes, np.array([50, 10, 25]))
     np.testing.assert_allclose(
         self.network.constraint_matrix,
         np.array([[0.25, 0.00, -0.25, 0.50, 0.00],
                   [0.00, -0.60, 0.00, 0.50, 0.30],
                   [-0.25, 0.00, 0.25, -0.50, 0.00]]))
     self.assertEqual(self.network.constraint_index[0], 'first_constraint')
     self.assertEqual(self.network.constraint_index[1], '_const_1')
     self.assertEqual(self.network.constraint_index[2], '_const_1_v2')
Пример #15
0
 def test_add_constraint_warning(self) -> None:
     curr_dict3 = {"PS-001": -0.25, "PS-002": -0.50, "PS-003": 0.25}
     current3 = Current(curr_dict3)
     with self.assertWarns(UserWarning):
         self.network.add_constraint(current3, 25, name="_const_1")
     np.testing.assert_allclose(self.network.magnitudes,
                                np.array([50, 10, 25]))
     np.testing.assert_allclose(
         self.network.constraint_matrix,
         np.array([
             [0.25, 0.00, -0.25, 0.50, 0.00],
             [0.00, -0.60, 0.00, 0.50, 0.30],
             [-0.25, 0.00, 0.25, -0.50, 0.00],
         ]),
     )
     self.assertEqual(self.network.constraint_index[0], "first_constraint")
     self.assertEqual(self.network.constraint_index[1], "_const_1")
     self.assertEqual(self.network.constraint_index[2], "_const_1_v2")
Пример #16
0
 def setUp(self) -> None:
     """ Run this setup function once before each test. """
     self.simulator = create_autospec(Simulator)
     self.network = ChargingNetwork()
     self.simulator.network = self.network
     self.interface = Interface(self.simulator)
     evse1 = EVSE("PS-001")
     self.network.register_evse(evse1, 120, -30)
     evse2 = EVSE("PS-002")
     evse3 = DeadbandEVSE("PS-003")
     self.network.register_evse(evse3, 360, 150)
     self.network.register_evse(evse2, 240, 90)
     # Include a FiniteRatesEVSE for more thorough testing.
     self.allowable_rates: List[int] = [0, 8, 16, 24, 32]
     evse4: FiniteRatesEVSE = FiniteRatesEVSE("PS-004",
                                              self.allowable_rates)
     self.network.register_evse(evse4, 120, -30)
     for i, station_id in enumerate(self.network.station_ids):
         self.network.add_constraint(Current(station_id), 1, f"C{i+1}")
Пример #17
0
 def test_init_str_load_input(self):
     curr_str = "PS-001"
     self.current = Current(curr_str)
     pd.testing.assert_series_equal(self.current,
                                    pd.Series([1], index=["PS-001"]),
                                    check_series_type=False)
Пример #18
0
 def test_update_constraint_not_found(self):
     with self.assertRaises(KeyError):
         self.network.update_constraint("_const_100", Current(), 0)
Пример #19
0
 def test_add_constraint_unregistered_evse(self):
     curr_dict3 = {"PS-001": -0.25, "PS-005": -0.50, "PS-003": 0.25}
     current3 = Current(curr_dict3)
     with self.assertRaises(KeyError):
         self.network.add_constraint(current3, 25, name="_bad_const")
Пример #20
0
 def test_init_loads_dict_input(self):
     curr_dict = {'PS-001' : 0.25, 'PS-002' : 0.50, 'PS-003' : -0.25}
     self.current = Current(curr_dict)
     pd.testing.assert_series_equal(
         self.current, pd.Series(
             [0.25, 0.50, -0.25], index=['PS-001', 'PS-002', 'PS-003']))
Пример #21
0
 def test_register_evse_constraints_added_error(self) -> None:
     evse1 = EVSE("PS-001")
     self.network.register_evse(evse1, 240, -30)
     self.network.add_constraint(Current(["PS-001"]), 10)
     with self.assertRaises(EVSERegistrationError):
         self.network.register_evse(EVSE("PS-002"), 100, 150)
Пример #22
0
 def _add_placeholder_constraint(self) -> None:
     """ Adds a non-binding constraint to the network. Call this after registering
     EVSEs."""
     self.simulator.network.add_constraint(
         Current(self.simulator.network.station_ids), float("inf")
     )
Пример #23
0
 def test_init_str_load_input(self):
     curr_str = 'PS-001'
     self.current = Current(curr_str)
     pd.testing.assert_series_equal(
         self.current, pd.Series(
             [1], index=['PS-001']))
Пример #24
0
 def test_add_constraint_unregistered_evse(self):
     curr_dict3 = {'PS-001' : -0.25, 'PS-005' : -0.50, 'PS-003' : 0.25}
     current3 = Current(curr_dict3)
     with self.assertRaises(KeyError):
         self.network.add_constraint(current3, 25, name='_bad_const')
Пример #25
0
 def test_init_str_lst_input(self):
     curr_strs = ['PS-001', 'PS-002', 'PS-003']
     self.current = Current(curr_strs)
     pd.testing.assert_series_equal(
         self.current, pd.Series(
             [1, 1, 1], index=['PS-001', 'PS-002', 'PS-003']))