def test_update_dual_costs(): # TEST_UPDATE_DUAL_COSTS() - test method update_dual_costs() that creates # or revises the dual costs in active time intervals using active vertices, # scheduled powers, and marginal prices. # NOTE: This test is virtually identical to the NeighborModel test of the # same name. print('Running LocalAssetModel.test_update_dual_costs()') pf = 'pass' # Create a test Market object. test_market = Market() # Create and store a TimeInterval object. dt = datetime.now() # datetime that may be used for most datetime arguments time_interval = TimeInterval(dt, timedelta(hours=1), test_market, dt, dt) test_market.timeIntervals = [time_interval] # Create and store a marginal price IntervalValue object. test_market.marginalPrices = [ IntervalValue(test_market, time_interval, test_market, MeasurementType.MarginalPrice, 0.1)] # Create a test LocalAssetModel object. test_model = LocalAssetModel() # Create and store a scheduled power IntervalValue in the active time # interval. test_model.scheduledPowers = [ IntervalValue(test_model, time_interval, test_market, MeasurementType.ScheduledPower, 100)] # Create and store a production cost IntervalValue object in the active # time interval. test_model.productionCosts = [ IntervalValue(test_model, time_interval, test_market, MeasurementType.ProductionCost, 1000)] # TEST 1 print('- Test 1: First calculation of a dual cost') test_model.update_dual_costs(test_market) print(' - the method ran without errors') if len(test_model.dualCosts) != 1: pf = 'fail' print(' - the wrong number of dual cost values was created') else: print(' - the right number of dual cost values was created') dual_cost = test_model.dualCosts[0].value if dual_cost != (1000 - 100 * 0.1): pf = 'fail' print(' - an unexpected dual cost value was found') else: print(' - the expected dual cost value was found') # TEST 2 print('- Test 2: Reassignment of an existing dual cost') # Configure the test by modifying the marginal price value. test_market.marginalPrices[0].value = 0.2 test_model.update_dual_costs(test_market) print(' - the method ran without errors') if len(test_model.dualCosts) != 1: pf = 'fail' print(' - the wrong number of dual cost values was created') else: print(' - the right number of dual cost values was created') dual_cost = test_model.dualCosts[0].value if dual_cost != (1000 - 100 * 0.2): pf = 'fail' print(' - an unexpected dual cost value was found') else: print(' - the expected dual cost value was found') # Success. print('- the test ran to completion') print('\nResult: #s\n\n', pf)
def test_schedule(): print('Running Market.test_schedule()') print('WARNING: This test may be affected by NeighborModel.schedule()') print('WARNING: This test may be affected by NeighborModel.schedule()') pf = 'pass' # Establish a myTransactiveNode object mtn = myTransactiveNode() # Establish a test market test_mkt = Market() # Create and store one TimeInterval dt = datetime(2018, 1, 1, 12, 0, 0) # Noon Jan 1, 2018 at = dt dur = timedelta(hours=1) mkt = test_mkt mct = dt st = dt ti = TimeInterval(at, dur, mkt, mct, st) test_mkt.timeIntervals = [ti] # Create and store a marginal price in the active interval. test_mkt.marginalPrices = [ IntervalValue(test_mkt, ti, test_mkt, MeasurementType.MarginalPrice, 0.01) ] print('- configuring a test Neighbor and its NeighborModel') # Create a test object that is a Neighbor test_obj1 = Neighbor() test_obj1.maximumPower = 100 # Create the corresponding model that is a NeighborModel test_mdl1 = NeighborModel() test_mdl1.defaultPower = 10 test_obj1.model = test_mdl1 test_mdl1.object = test_obj1 mtn.neighbors = [test_obj1] print('- configuring a test LocalAsset and its LocalAssetModel') # Create a test object that is a Local Asset test_obj2 = LocalAsset test_obj2.maximumPower = 100 # Create the corresponding model that is a LocalAssetModel test_mdl2 = LocalAssetModel() test_mdl2.defaultPower = 10 test_obj2.model = test_mdl2 test_mdl2.object = test_obj2 mtn.localAssets = [test_obj2] try: test_mkt.schedule(mtn) print('- method ran without errors') except: raise ('- method did not run due to errors') if len(test_mdl1.scheduledPowers) != 1: raise ( '- the wrong numbers of scheduled powers were stored for the Neighbor' ) else: print( '- the right number of scheduled powers were stored for the Neighbor' ) if len(test_mdl2.scheduledPowers) != 1: raise ( '- the wrong numbers of scheduled powers were stored for the LocalAsset' ) else: print( '- the right number of scheduled powers were stored for the LocalAsset' ) # Success print('- the test ran to completion') print('Result: #s\n\n', pf)