def __init__(self, max_power=8): System.__init__(self) self.power = max_power self.max_power = max_power self.shields = self.power // 2 self.max_shields = self.power // 2
def test_addQuantityIngredient_correct_input(): sys = System() sys.addQuantityIngredient('bun', 'm', 20, 5) new = sys.ingredients[0] assert new.id == 1 assert new.name == 'bun' assert new.kind == 'm' assert new.stock == 20 assert new.price == 5
def test_remIngredient_incorrect_input_no_ings_in_order(): sys = System() wrap = Main('wrap') sys.addQuantityIngredient('beef patty', 'm', 50, 1.50) ing1 = sys.ingredients[0] with pytest.raises(UserError) as error: wrap.remIngredient(ing1, 1, None) assert "You don't have any ingredients in your main to remove." in str(error.value)
def simulate(system: System, time: float): # time in (fs) state_list = [] while system.t < time: print(system.t / time) system.step() state_list.append(system.make_data()) return state_list
def test_remIngredient_correctinput(): sys = System() sys.addQuantityIngredient('sesame bun', 'm', 20, 1.00) sys.addWeightIngredient('fries', 'm', 2000, 60, 100, 140, 2, 2.8, 3.4) sys.remIngredient(4) assert len(sys.ingredients) == 1 assert sys.ingredients[0].name == 'sesame bun'
def test_addWeightIngredient_correct_input(): sys = System() sys.addWeightIngredient('fries', 's', 2000, 60, 100, 140, 2, 2.8, 3.4) new = sys.ingredients[0] assert new.id == 2 assert new.name == 'fries' assert new.kind == 's' assert new.stock == 2000 assert new.sWeight == 60 assert new.mWeight == 100 assert new.lWeight == 140 assert new.sPrice == 2 assert new.mPrice == 2.8 assert new.lPrice == 3.4
def main(argv): # Read instance folder if len(argv) < 1 : displayHelp() sys.exit(2) folderPath=argv[-1] if argv[-1].endswith(("/","\\")) else argv[-1]+"/" if not os.path.exists(folderPath): raise Exception('Folder \"%s\" does not exists.' % folderPath) outputSolutionFile="data.xml" # Parse options maximumIterations=20 convergenceTolerance=None try: opts, args = getopt.getopt(argv[0:-1],"dlm:o:t:f:",["im=","gamma=","maxiterations=","operationfolder=","cplex"]) except getopt.GetoptError as err: tools.log(err) displayHelp() sys.exit(2) for opt, arg in opts: if opt in ["-o"]: outputSolutionFile = arg elif opt in ["-l"]: options.OPF_METHOD = "linearOpf" elif opt in ["-d"]: options.DEBUG = True elif opt in ["--maxiterations"]: maximumIterations = max(1,int(arg)) elif opt in ["-t"]: convergenceTolerance = float(arg) elif opt in ["-f","--operationfolder"]: options.FOLDER = arg elif opt in ["--cplex"]: options.SOLVER = 'cplex' # Log file options.log=outputSolutionFile+".log" # Create and launch system lockFile='lock.lock' if options.COPY: # If copy mode, the lock file is specific to the operation folder. lockFile='%s.lock'%(options.FOLDER) with tools.fileLock(lockFile): tools.cleanLog(options.LOG) system=System(dataFolder=folderPath,maximumIterations=maximumIterations,outputSolutionFile=outputSolutionFile,convergenceTolerance=convergenceTolerance) tools.log(system.run(),options.LOG,options.PRINT_TO_SCREEN)
def plot_gamma(system: System, state_list, t_goal: float, zmin: float, zmax: float, gamma_min: float, gamma_max: float): i_best: int = 0 cost: float = math.inf for i in range(len(state_list)): (t, gamma, mu0_up, mu0_dn, hot_up, hot_dn, mu0_hot_up, mu0_hot_dn, j_hot_up, j_hot_dn, j_up, j_dn, j_spin) = state_list[i] cost_new = math.fabs(t_goal - t) if cost_new < cost: i_best = i cost = cost_new (t, gamma, mu0_up, mu0_dn, hot_up, hot_dn, mu0_hot_up, mu0_hot_dn, j_hot_up, j_hot_dn, j_up, j_dn, j_spin) = state_list[i_best] (ticks_slices, ticks_planes) = system.make_ticks() plt.figure() plt.plot(ticks_slices, gamma) plt.xlim([zmin, zmax]) plt.ylim([gamma_min, gamma_max]) plt.ylabel('mu_s (eV)') plt.xlabel('z (nm)') plt.grid(True) title = 'gamma at = {} fs'.format(t) #plt.suptitle(title) plt.show()
def test_remIngredient_incorrectinput(): sys = System() sys.addQuantityIngredient('sesame bun', 'm', 20, 1.00) with pytest.raises(DevError) as err: sys.remIngredient(1) assert 'cannot delete. no such ingredient in the inventory' in str( err.value)
def plot(): data = { "hp": { "cop": 3.0 }, "swhe": { "pipe": { "outer-dia": 0.02667, "inner-dia": 0.0215392, "length": 100, "density": 950, "conductivity": 0.4 }, "diameter": 1.2, "horizontal-spacing": 0.05, "vertical-spacing": 0.05, }, "fluid": { "fluid-name": "PG", "concentration": 20 } } system = System(data) x = np.arange(-3000, 3000, 200) y_a = [system.simulate(m, 0.1, 15) for m in x] y_b = [system.simulate(m, 0.25, 15) for m in x] y_c = [system.simulate(m, 1.0, 15) for m in x] fig, ax = plt.subplots() ax.plot(x, y_a, label=r"$T_{appr}$ $\dot{m}=0.10$ [kg/s]") ax.plot(x, y_b, label=r"$T_{appr}$ $\dot{m}=0.25$ [kg/s]", linestyle="--") ax.plot(x, y_c, label=r"$T_{appr}$ $\dot{m}=1.00$ [kg/s]", linestyle=":") ax.set_xlabel(r"$\dot{q}_{zone}$ [W]") ax.set_ylabel(r"$T_{appr}$ [C]") ax.legend() ax.grid() f_name = Path(__file__).parent / "_system_approach_temp.png" plt.savefig(f_name, bbox_inches="tight")
def test_remIngredient_incorrect_input(): sys = System() sys.addQuantityIngredient('beef patty', 'm', 50, 1.50) sys.addQuantityIngredient('cheese', 'm', 50, 1.00) sys.addQuantityIngredient('egg', 'm', 50, 1.50) ing1 = sys.ingredients[0] ing2 = sys.ingredients[1] ing3 = sys.ingredients[2] wrap = Main('wrap') wrap.addIngredient(ing1, 2, None) wrap.addIngredient(ing2, 2, None) with pytest.raises(UserError) as error: wrap.remIngredient(ing3, 1, None) assert "You don't have any egg in your order to remove." in str(error.value)
def test_search_order_incorrect_input(): sys = System() order0 = sys.newOrder() order1 = sys.newOrder() order2 = sys.newOrder() with pytest.raises(UserError) as err: sys.searchOrder(32) assert 'OrderID not exist in the system' in str(err.value)
def test_remIngredient_correct_input(): sys = System() sys.addQuantityIngredient('beef patty', 'm', 50, 1.50) sys.addQuantityIngredient('cheese', 'm', 50, 1.00) sys.addQuantityIngredient('egg', 'm', 50, 1.50) ing1 = sys.ingredients[0] ing2 = sys.ingredients[1] ing3 = sys.ingredients[2] wrap = Main('wrap') wrap.addIngredient(ing1, 2, None) wrap.addIngredient(ing2, 2, None) wrap.addIngredient(ing3, 1, None) wrap.remIngredient(ing3, 1, None) assert len(wrap.ingredients) == 2 assert sys.ingredients[2].stock == 50
from src.erc20 import Connection from src.system import System app = Flask(__name__) f = open("secretkey", "r") secretkey = f.read().rstrip() f.close() app.secret_key = secretkey f = open("infuraapi", "r") apikey = f.read().rstrip() f.close() infura_url = "https://mainnet.infura.io/{}".format(apikey) infura = Connection(infura_url) f = open("bdc.abi") bdcabi = f.read().rstrip() f.close() f = open("default.abi") defaultABI = f.read().rstrip() f.close() bdcaddress = "0x8b84715c41bfb75f8E8CE47447180450758332b3" system = System() system.add_connection(infura) system.create_token(bdcaddress, bdcabi)
def test_addQuantityIngredient_wrong_name(): sys = System() with pytest.raises(UserError) as error: sys.addQuantityIngredient(465, 'm', 20, 5) assert 'Name of ingredient must be in alphabets' in str(error.value)
def bootstrap_system(): system = System() return system
def test_search_order_correct_input(): sys = System() order0 = sys.newOrder() order1 = sys.newOrder() order2 = sys.newOrder() assert sys.searchOrder(1) == order1
def test_addWeightIngredient_weight_is_string(): sys = System() with pytest.raises(UserError) as e: sys.addWeightIngredient('fries', 'm', 1000, 'ewf', 'ewf', 'wef', 2.8, 3.4, 3.8) assert 'All weights of ingredient must be in number' in str(e.value)
def test_addWeightIngredient_stock_is_negative(): sys = System() with pytest.raises(UserError) as e: sys.addWeightIngredient('fries', 'm', -1000, 60, 100, 140, 2, 2.8, 3.4) assert 'Stock of ingredient must be equal to or larger than 0' in str( e.value)
def test_addWeightIngredient_weight_is_negative(): sys = System() with pytest.raises(UserError) as e: sys.addWeightIngredient('fries', 'm', 1000, -70, -90, -120, 4, 3, 1) assert 'All weights of ingredient must be larger than zero' in str(e.value)
def test_addWeightIngredient_stock_is_string(): sys = System() with pytest.raises(UserError) as e: sys.addWeightIngredient('ranch sauce', 'm', 'one hundred', 2, 3, 4, 5, 5, 4) assert 'Stock of ingredient must be in number' in str(e.value)
def test_addQuantityIngredient_price_is_negative(): sys = System() with pytest.raises(UserError) as e: sys.addQuantityIngredient('sesame bun', 'm', 20, -5) assert 'Price of ingredient must be positive' in str(e.value)
def test_orders_overview(): sys = System() order1 = sys.newOrder() order2 = sys.newOrder() order3 = sys.newOrder() assert sys.ordersOverview() == [order1, order2, order3]
def test_addWeightIngredient_price_is_string(): sys = System() with pytest.raises(UserError) as e: sys.addWeightIngredient('fries', 'm', 1000, 152, 400, 600, 'f', 'g', 'h') assert 'All prices of ingredient must be in number' in str(e.value)
"inner-dia": 0.0215392, "length": 100, "density": 950, "conductivity": 0.4 }, "diameter": 1.2, "horizontal-spacing": 0.05, "vertical-spacing": 0.05, }, "fluid": { "fluid-name": "PG", "concentration": 20 } } system = System(data) def obj_f(pipe_length, q_zone, m_dot, t_sw, t_appr_target): system.swhe.pipe.update_pipe(pipe_length) t_appr = system.simulate(q_zone, m_dot, t_sw) return (t_appr - t_appr_target)**2 def create_diagram(): q_cooling = -3516.85 t_appr = np.arange(1.5, 6.5, 0.25) pipe_length_init = 200 pipe_length = [pipe_length_init]
def test_addWeightIngredient_price_is_negative(): sys = System() with pytest.raises(UserError) as e: sys.addWeightIngredient('fries', 'm', 100, 70, 90, 120, -4, -3, -1) assert 'All prices of ingredient must be positive' in str(e.value)
def test_addQuantityIngredient_stock_is_string(): sys = System() with pytest.raises(UserError) as error: sys.addQuantityIngredient('sugar', 'm', 'unsw', 5) assert 'Stock of ingredient must be in number' in str(error.value)
def test_addQuantityIngredient_stock_is_negative(): sys = System() with pytest.raises(UserError) as error: sys.addQuantityIngredient('sugar', 's', -20, 3) assert 'Stock of ingredient must be positive' in str(error.value)
def __init__(self, max_power=3): System.__init__(self) self.weapons = [] self.power = 0 self.max_power = max_power
def test_addQuantityIngredient_price_is_string(): sys = System() with pytest.raises(UserError) as e: sys.addQuantityIngredient('sesame bun', 'm', 20, 'asdf') assert 'Price of ingredient must be a number' in str(e.value)
print(documentation) print("THE OPTIONS ARE: ") print(" 1 - SHOW THE SPECIFICATIONS OF THE SYSTEM") print(" 2 - LIST VERSION NUMBERS OF CRITICAL DEVELOPMENT TOOLS - ONLY FOR LINUX MACHINES") print(" 3 - EXIT FROM THE PROGRAM ") try: option = int(input("YOUR OPTION IS: ")) # converts a string to a integer and read the value with input except ValueError as e: print(e, " - The value is not valid, please enter a valid value!") # instantiation of the two classes syst = System() develop = Development() if option == 1: print("YOU HAVE CHOSEN THE OPTION (1 - SHOW THE SPECIFICATIONS OF THE SYSTEM)\n") # \n - puts another line if platform.system() == "Linux": syst.linux_machine() # object.method_name() elif platform.system() == "MacOSX": syst.macos_machine() # object.method_name() elif platform.system() == "Windows": syst.windows_machine() # object.method_name() elif option == 2: print("YOU HAVE CHOSEN THE OPTION (2 - LIST VERSION NUMBERS OF CRITICAL DEVELOPMENT TOOLS - ONLY FOR LINUX MACHINES)\n") # - puts another line if platform.system() == "Linux": develop.linux() # object.method_name()
def test_checkOrderStatus_blank(): sys = System() sys.newOrder() assert sys.checkOrderStatus(0) == None