def ReadSystems(useLocal: bool) -> list: if useLocal: file = "rares.json" else: file = 'http://edtools.ddns.net/rares.json' allSystems = [] allGoods = pd.read_json(file) idx = 1 for good in allGoods: tempArgs = allGoods[good] if tempArgs['alloc'] is "" or tempArgs['cost'] is "": continue tempSystem = EDSystem.Initialize_System(item=good, idx=idx, **tempArgs) if tempSystem in allSystems: for system in allSystems: if system == tempSystem: system.AddRares(tempSystem) else: allSystems.append(tempSystem) idx += 1 for system in allSystems: system.CalculateDistances(allSystems) return allSystems
def test_System_AddRaresCommutative(self): ''' Assert that we get the "same" systems regardless of the order we add rares to them ''' systemsForward = [] systemsReverse = [] reverseArgs = self.Test_Args[::-1] for args in self.Test_Args: newSystem = EDSystem.Initialize_System(**args) if systemsForward.count(newSystem) != 0: for currentSystem in systemsForward: if currentSystem == newSystem: currentSystem.AddRares(newSystem) else: systemsForward.append(newSystem) for args in reverseArgs: newSystem = EDSystem.Initialize_System(**args) if systemsReverse.count(newSystem) != 0: for currentSystem in systemsReverse: if currentSystem == newSystem: currentSystem.AddRares(newSystem) else: systemsReverse.append(newSystem) #Yeah I said one assert per test but bleh #First make sure equal number of systems are created self.assertEqual(len(systemsForward), len(systemsReverse), msg="Should create equal number of systems") #Next assert that systems with the same System_Name are essentially the same for system in systemsForward: with self.subTest(sysName=system.System_Name): revSystem = [ rSys for rSys in systemsReverse if rSys.System_Name == system.System_Name ][0] self.assertSystemsEqual(system, revSystem) self.assertSystemsEqual(revSystem, system)
def test_System_AddRaresTotalCost(self): squishedSystems = [] for args in self.Test_Args: newSystem = EDSystem.Initialize_System(**args) if squishedSystems.count(newSystem) != 0: for currentSystem in squishedSystems: with self.subTest(currSystem=currentSystem): if currentSystem == newSystem: expected_Total = currentSystem.Total_Cost + newSystem.Total_Cost currentSystem.AddRares(newSystem) self.assertAlmostEqual(expected_Total, currentSystem.Total_Cost) else: squishedSystems.append(newSystem)
def test_System_AddRaresItemCosts(self): squishedSystems = [] for args in self.Test_Args: newSystem = EDSystem.Initialize_System(**args) if squishedSystems.count(newSystem) != 0: for currentSystem in squishedSystems: with self.subTest(currSystem=currentSystem): if currentSystem == newSystem: expected_Item_Costs = currentSystem.Item_Costs expected_Item_Costs.extend(newSystem.Item_Costs) currentSystem.AddRares(newSystem) self.assertListEqual(expected_Item_Costs, currentSystem.Item_Costs) else: squishedSystems.append(newSystem)
def CreateTestSystems(argsList: list) -> list: ''' "Factory" whatever for making EDSystems to use in testing ''' generatedSystems = [] for args in argsList: currentSystem = EDSystem.Initialize_System(**args) if generatedSystems.count(currentSystem) != 0: for system in generatedSystems: if system == currentSystem: system.AddRares(currentSystem) else: generatedSystems.append(currentSystem) for system in generatedSystems: system.CalculateDistances(generatedSystems) return generatedSystems
def test_System_Contructor(self): systemName = "test system" stationName = "test station" index = 0 supplyCap = 12 avgSupply = 10 itemCost = 400 itemName = "test item" distToStation = 219 permitReq = False distToOthers = [0] testSystem = EDSystem() self.assertFalse(testSystem.Is_Initialized) with self.assertRaises(Exception, msg="missing args to constructor"): testSystem = EDSystem.Initialize_System(avgSupply, itemCost, itemName, distToStation, stationName, systemName, index, permitReq) with self.assertRaises(Exception, msg="no Nones allowed"): testSystem = EDSystem(None, avgSupply, itemCost, itemName, distToStation, stationName, systemName, index, permitReq) with self.assertRaises(Exception, msg="no Nones allowed"): testSystem = EDSystem(supplyCap, None, itemCost, itemName, distToStation, stationName, systemName, index, permitReq) with self.assertRaises(Exception, msg="no Nones allowed"): testSystem = EDSystem(supplyCap, avgSupply, None, itemName, distToStation, stationName, systemName, index, permitReq) with self.assertRaises(Exception, msg="no Nones allowed"): testSystem = EDSystem(supplyCap, avgSupply, itemCost, None, distToStation, stationName, systemName, index, permitReq) with self.assertRaises(Exception, msg="no Nones allowed"): testSystem = EDSystem(supplyCap, avgSupply, itemCost, itemName, None, stationName, systemName, index, permitReq) with self.assertRaises(Exception, msg="no Nones allowed"): testSystem = EDSystem(supplyCap, avgSupply, itemCost, itemName, distToStation, None, systemName, index, permitReq) with self.assertRaises(Exception, msg="no Nones allowed"): testSystem = EDSystem(supplyCap, avgSupply, itemCost, itemName, distToStation, stationName, None, index, permitReq) with self.assertRaises(Exception, msg="no Nones allowed"): testSystem = EDSystem(supplyCap, avgSupply, itemCost, itemName, distToStation, stationName, systemName, None, permitReq) with self.assertRaises(Exception, msg="no Nones allowed"): testSystem = EDSystem(supplyCap, avgSupply, itemCost, itemName, distToStation, stationName, systemName, index, None) self.assertFalse(testSystem.Is_Initialized)