def test_lowest_drive(): ship = Spacecraft(100) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 100 drive = ship.get_lowest_drive() assert drive == "A"
def test_incompatible_drive(): ship = Spacecraft(100) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 100 assert ship.mdrive is None ship.add_mdrive(MDrive("Z")) assert ship.mdrive is None
def test_normal_add(): ship = Spacecraft(100) # Adding and removing a Fuel Processor fuel_processor = Misc("Fuel Processors", 1) ship.modify_misc(fuel_processor) assert ship.get_remaining_cargo() == 99 assert ship.get_total_cost() == 2.05 ship.remove_misc("Fuel Processors") assert ship.get_remaining_cargo() == 100 assert ship.get_total_cost() == 2.0
def test_escape_pods(): ship = Spacecraft(100) # Adding a stateroom then an escape pod stateroom = Misc("Staterooms", 1) ship.modify_misc(stateroom) assert ship.get_remaining_cargo() == 96 assert ship.get_total_cost() == 2.5 escape_pod = Misc("Escape Pods", 1) ship.modify_misc(escape_pod) assert ship.get_remaining_cargo() == 95.5 assert ship.get_total_cost() == 2.6
def test_spacecraft_init(): """ Tests the initialization of a new Spacecraft (hull) """ spacecraft = Spacecraft(1000) assert spacecraft.tonnage == 1000 assert spacecraft.get_remaining_cargo() == 1000 assert spacecraft.hull_hp == 1000 // 50 assert spacecraft.structure_hp == 1000 // 50 assert spacecraft.fuel_max == 0 assert spacecraft.armour_total == 0 assert spacecraft.hull_type.type == "Standard" assert spacecraft.hull_designation == "B"
def test_repair_drones(): ship = Spacecraft(100) # Adding repair drones and checking dynamic costs repair_drones = Misc("Repair Drones", 1) ship.modify_misc(repair_drones) assert ship.get_remaining_cargo() == 99.0 assert ship.get_total_cost() == 2.2 # Removing the drone ship.remove_misc("Repair Drones") assert ship.get_remaining_cargo() == 100 assert ship.get_total_cost() == 2.0
def test_swap(): ship = Spacecraft(100) # Adding repair drones and checking dynamic costs repair_drones = Misc("Repair Drones", 1) ship.modify_misc(repair_drones) assert ship.get_remaining_cargo() == 99.0 assert ship.get_total_cost() == 2.2 # Swapping for more drones repair_drones = Misc("Repair Drones", 2) ship.modify_misc(repair_drones) assert ship.get_remaining_cargo() == 98.0 assert ship.get_total_cost() == 2.4
def test_adding(): # Tests adding hull objects to the ship spacecraft = Spacecraft(100) reflec = Option("Reflec") stealth = Option("Stealth") spacecraft.modify_hull_option(reflec) assert spacecraft.get_remaining_cargo() == 100 assert spacecraft.get_total_cost() == 12.0 assert len(spacecraft.hull_options) == 1 spacecraft.modify_hull_option(stealth) assert spacecraft.get_remaining_cargo() == 100 assert spacecraft.get_total_cost() == 22.0 assert len(spacecraft.hull_options) == 2
def test_removing(): # Tests removing a hull object from the ship spacecraft = Spacecraft(100) reflec = Option("Reflec") spacecraft.modify_hull_option(reflec) assert spacecraft.get_remaining_cargo() == 100 assert spacecraft.get_total_cost() == 12.0 assert len(spacecraft.hull_options) == 1 new_reflec = Option("Reflec") spacecraft.modify_hull_option(new_reflec) assert spacecraft.get_remaining_cargo() == 100 assert spacecraft.get_total_cost() == 2.0 assert len(spacecraft.hull_options) == 0
def test_init(): # Test ship rating check before computer addition ship = Spacecraft(100) assert ship.check_rating_ratio() == 0 # Initializing a computer and adding a mod to it, testing the end values computer = Computer("Model 5") assert computer.rating == 25 assert computer.tl == 13 assert computer.get_cost() == 10.0 computer.modify_addon("Jump Control Spec") assert computer.rating == 25 assert computer.get_cost() == 15.0 computer.modify_addon("Hardened System") assert computer.get_cost() == 20.0
def test_check_ratio(): # Tests the available rating check ship = Spacecraft(100) computer = Computer("Model 3") jump = Software("Jump Control", 2) ship.add_computer(computer) assert ship.get_total_cost() == 4.0 # Check before addition assert ship.check_rating_ratio() == 15 # Adding the level 2 jump ship.modify_software(jump) assert ship.get_total_cost() == 4.2 assert len(ship.software) == 1 # Check after addition assert ship.check_rating_ratio() == 5
def test_adding(): # Testing adding a single piece of software to a ship ship = Spacecraft(100) computer = Computer("Model 3") jump = Software("Jump Control", 2) ship.add_computer(computer) assert ship.get_total_cost() == 4.0 ship.modify_software(jump) assert ship.get_total_cost() == 4.2 assert len(ship.software) == 1
def test_adding(): # Initializing a ship and adding a computer system to it, checking for correct values ship = Spacecraft(100) assert ship.get_total_cost() == 2.0 computer = Computer("Model 3") ship.add_computer(computer) assert ship.get_total_cost() == 4.0 assert ship.check_rating_ratio() == 15
def test_fuel_add(): ship = Spacecraft(100) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 100 assert ship.fuel_max == 0 ship.set_fuel(50) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 50 assert ship.fuel_max == 50
def test_fuel_scoop(): ship = Spacecraft(100) assert ship.hull_type.type == "Standard" assert ship.fuel_scoop is False assert ship.get_total_cost() == 2.0 ship.modify_fuel_scoops() assert ship.hull_type.type == "Standard" assert ship.fuel_scoop is True assert ship.get_total_cost() == 3.0
def test_turret_functionality(): """ Tests the functionality of adding and removing a turret from a ship """ ship = Spacecraft(100) # Turret init with a wep and addon hardpoint = Hardpoint("1") turret = Turret("Single Turret") hardpoint.add_turret(turret) turret.modify_weapon("Beam Laser", 0) # Adding and removing the turret, checking ship specs ship.add_hardpoint(hardpoint) assert ship.get_remaining_cargo() == 99 assert ship.get_total_cost() == 3.2 turret.modify_weapon("---", 0) assert ship.get_remaining_cargo() == 99 assert ship.get_total_cost() == 2.2
def test_add(): """ Tests adding a piece of armour to a ship """ ship = Spacecraft(200) armour = Armour("Titanium Steel") assert armour.tl == 7 assert armour.protection == 2 assert armour.hull_amount == 0.05 assert armour.cost_by_hull_percentage == 0.05 ship.add_armour(armour) assert ship.get_remaining_cargo() == 190 assert ship.armour_total == 2 assert ship.get_total_cost() == 8.4
def test_empty_ship(): ship = Spacecraft(0) assert ship.tonnage == 0 assert ship.get_remaining_cargo() == 0 assert ship.jdrive is None ship.add_jdrive(JDrive("A")) assert ship.tonnage == 0 assert ship.get_remaining_cargo() == 0 assert ship.jdrive is None ship.add_mdrive(MDrive("A")) assert ship.tonnage == 0 assert ship.get_remaining_cargo() == 0 assert ship.mdrive is None ship.add_pplant(PPlant("A")) assert ship.tonnage == 0 assert ship.get_remaining_cargo() == 0 assert ship.pplant is None
def test_add_replace(): # Testing adding and replacing a sensor system ship = Spacecraft(100) assert ship.get_remaining_cargo() == 100 assert ship.get_total_cost() == 2.0 sensor = Sensor("Advanced") ship.add_sensors(sensor) assert ship.get_remaining_cargo() == 97 assert ship.get_total_cost() == 4.0 assert ship.sensors is not None sensor = Sensor("Basic Civilian") ship.add_sensors(sensor) assert ship.get_remaining_cargo() == 99 assert ship.get_total_cost() == 2.05
def test_jdrive(): # Testing valid drive to tonnage match spacecraft = Spacecraft(200) spacecraft.add_jdrive(JDrive("A")) assert spacecraft.jump == 1 # Testing invalid drive to tonnage match spacecraft = Spacecraft(100) spacecraft.add_jdrive(JDrive("J")) assert spacecraft.jump == 0 # Testing valid larger drive to tonnage match spacecraft = Spacecraft(1600) spacecraft.add_jdrive(JDrive("Z")) assert spacecraft.jump == 5
def test_mdrive(): # Testing valid drive to tonnage match spacecraft = Spacecraft(100) spacecraft.add_mdrive(MDrive("A")) assert spacecraft.thrust == 2 # Testing invalid drive to tonnage match spacecraft = Spacecraft(100) spacecraft.add_mdrive(MDrive("J")) assert spacecraft.thrust == 0 # Testing valid larger drive to tonnage match spacecraft = Spacecraft(2000) spacecraft.add_mdrive(MDrive("U")) assert spacecraft.thrust == 4
def test_small(): spacecraft = Spacecraft(100) spacecraft.set_bridge() assert spacecraft.get_remaining_cargo() == 90 assert spacecraft.get_total_cost() == 2.5
def test_bigly(): spacecraft = Spacecraft(2000) spacecraft.set_bridge() assert spacecraft.get_remaining_cargo() == 1960 assert spacecraft.get_total_cost() == 210.0
def test_large(): spacecraft = Spacecraft(1200) spacecraft.set_bridge() assert spacecraft.get_remaining_cargo() == 1170 assert spacecraft.get_total_cost() == 126.0
def test_medium(): spacecraft = Spacecraft(400) spacecraft.set_bridge() assert spacecraft.get_remaining_cargo() == 380 assert spacecraft.get_total_cost() == 18.0
def test_adding(): """ Tests adding both types of drives to a ship """ ship = Spacecraft(100) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 100 assert ship.get_total_cost() == 2 assert ship.mdrive is None assert ship.jdrive is None ship.add_jdrive(JDrive("A")) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 90 assert ship.get_total_cost() == 12 assert ship.jdrive is not None ship.add_mdrive(MDrive("A")) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 88 assert ship.get_total_cost() == 16 assert ship.mdrive is not None ship.add_pplant(PPlant("A")) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 84 assert ship.get_total_cost() == 24 assert ship.pplant is not None
def test_pplant_validity(): # Tests 4 cases for pplant validities ship = Spacecraft(100) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 100 ship.add_jdrive(JDrive("B")) ship.add_pplant(PPlant("B")) assert ship.check_pplant_validity() == True ship.add_pplant(PPlant("A")) assert ship.check_pplant_validity() == "Error: PPlant under J-Drive. A < B" ship = Spacecraft(100) ship.add_mdrive(MDrive("B")) ship.add_pplant(PPlant("A")) assert ship.check_pplant_validity() == "Error: PPlant under M-Drive. A < B" ship.add_jdrive(JDrive("B")) assert ship.check_pplant_validity( ) == "Error: PPlant under max M/J-Drive. A < B"
def test_removing(): # Tests removing a screen object from the ship ship = Spacecraft(200) assert ship.get_remaining_cargo() == 200 assert ship.get_total_cost() == 8.0 damper = Screen("Nuclear Damper") ship.modify_screen(damper) assert ship.get_remaining_cargo() == 150 assert ship.get_total_cost() == 58.0 new_damper = Screen("Nuclear Damper") ship.modify_screen(new_damper) assert ship.get_remaining_cargo() == 200 assert ship.get_total_cost() == 8.0
def test_changing(): """ Tests changing a drive type from one to another """ ship = Spacecraft(100) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 100 assert ship.get_total_cost() == 2 assert ship.jdrive is None ship.add_jdrive(JDrive("A")) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 90 assert ship.get_total_cost() == 12 assert ship.jdrive.drive_type == "A" ship.add_jdrive(JDrive("B")) assert ship.tonnage == 100 assert ship.get_remaining_cargo() == 85 assert ship.get_total_cost() == 22 assert ship.jdrive.drive_type == "B" ship.add_mdrive(MDrive("A")) assert ship.get_remaining_cargo() == 83 assert ship.get_total_cost() == 26 assert ship.mdrive.drive_type == "A" ship.add_mdrive(MDrive("B")) assert ship.get_remaining_cargo() == 82 assert ship.get_total_cost() == 30 assert ship.mdrive.drive_type == "B" ship.add_pplant(PPlant("A")) assert ship.get_remaining_cargo() == 78 assert ship.get_total_cost() == 38 assert ship.pplant.type == "A" ship.add_pplant(PPlant("B")) assert ship.get_remaining_cargo() == 75 assert ship.get_total_cost() == 46 assert ship.pplant.type == "B"
def load_model(self, path, window): """ Handles loading in a model from a SRD file and setting both the backend and front end to the contents of the file :param path: full path to the file :param window: QMainWindow object to interact with """ # Loading in the model template for ships with open(path, 'r') as f: model = json.load(f) # Wiping out the active turret box for i in reversed(range(0, window.turret_config_layout.count())): window.turret_config_layout.itemAt(i).widget().setParent(None) # Setting hull option flags to False initially window.reflec_check.setChecked(False) window.stealth_check.setChecked(False) window.seal_check.setChecked(False) window.fuel_scoop.setChecked(False) # Setting screen option flags to False initially window.meson_screen.setChecked(False) window.nuclear_damper.setChecked(False) # Adding software labels back to box my_path = os.path.abspath(os.path.dirname(__file__)) path = os.path.join(my_path, "../resources/hull_software.json") with open(path) as f: data = json.load(f) window.software_box.clear() window.software_box.addItem("---") for item in data.keys(): window.software_box.addItem(item) # Adding misc labels back to box my_path = os.path.abspath(os.path.dirname(__file__)) path = os.path.join(my_path, "../resources/hull_misc.json") with open(path) as f: data = json.load(f) window.misc_dict = {} idx = 1 window.misc_box.clear() window.misc_box.addItem(" ") for item in data.keys(): window.misc_dict[item] = idx window.misc_box.addItem(item) idx += 1 # Setting spacecraft to new template window.spacecraft = Spacecraft(100) # Setting stats window.tonnage_box.setCurrentText(str(model['stats']['tonnage'])) window.edit_tonnage() window.fuel_line_edit.setText(str(model['stats']['fuel'])) window.edit_fuel() window.discount.setText( str(round(100 * (1 - model['stats']['discount'])))) window.edit_discount() # Setting drives window.jump_label.setText("-") window.thrust_label.setText("-") window.pplant_label.setText("-") if model['drives']['jdrive'] is not None: window.jump_line_edit.setText(model['drives']['jdrive']) window.edit_jdrive() if model['drives']['mdrive'] is not None: window.thrust_line_edit.setText(model['drives']['mdrive']) window.edit_mdrive() if model['drives']['pplant'] is not None: window.pplant_line_edit.setText(model['drives']['pplant']) window.edit_pplant() # Setting configs window.bridge_check.setChecked(model['config']['bridge']) window.check_bridge() options = model['config']['options'] if options[0] is True: window.reflec_check.setChecked(True) if options[1] is True: window.seal_check.setChecked(True) if options[2] is True: window.stealth_check.setChecked(True) screens = model['config']['screens'] if screens[0] is True: window.meson_screen.setChecked(True) if screens[1] is True: window.nuclear_damper.setChecked(True) window.hull_config_box.setCurrentText(model['config']['hull_type']) window.edit_hull_config() # Check for checked fuel scoops when standard config if model['config']['hull_type'] not in ['Distributed', 'Streamlined']: window.fuel_scoop.setChecked(model['config']['fuel_scoop']) window.sensors.setCurrentText(model['config']['sensors']) window.edit_sensors() # Redisplaying armour before adding rest window.edit_armor() for armour in model['config']['armour']: window.armor_combo_box.setCurrentText(armour) window.edit_armor() # Editing computer/software window.computers.setCurrentText(model['computer']['model']) window.edit_computer() window.jump_control_spec.setChecked( model['computer']['jump_control_spec']) window.hardened_system.setChecked(model['computer']['hardened_system']) for sname, slevel in model['computer']['software']: window.spacecraft.modify_software(Software(sname, slevel)) window.software_box.setCurrentText(sname) window.software_box.removeItem(window.software_box.currentIndex()) window.software_box.setCurrentIndex(0) window.display_software() # Adding all misc items for mname, mnumber in model['misc']['misc']: window.spacecraft.modify_misc(Misc(mname, mnumber)) window.display_misc_items() # Adding hardpoints and turrets for hardpoint in model['hardpoints']: # Making hp object hp = Hardpoint(hardpoint['id']) # Modifying its addons if hardpoint['popup']: hp.modify_addon('Pop-up Turret') if hardpoint['fixed']: hp.modify_addon('Fixed Mounting') # Making turret and adding it turret_dict = hardpoint['turret'] if turret_dict is not None: turret = Turret(turret_dict['type']) turret.weapons = turret_dict['weapons'] turret.missiles = turret_dict['missiles'] turret.sandcaster_barrels = turret_dict['sandcaster_barrels'] hp.add_turret(turret) window.spacecraft.add_hardpoint(hp) # Resetting HP total/avail window.total_hp.setText(str(window.spacecraft.num_hardpoints)) window.avail_hp.setText( str(window.spacecraft.num_hardpoints - len(window.spacecraft.hardpoints))) # Setting active hardpoint to None, displaying new hardpoints window.active_hp_id = None window.display_hardpoints() # Updating stats at end window.update_stats()