OP+ and Test-Driven Development
(→Example: Mauler) |
(→Verbose output, all coded tests) |
||
Line 36: | Line 36: | ||
ok 56 - SpecialRole A are maulers, and maulers are A or R. | ok 56 - SpecialRole A are maulers, and maulers are A or R. | ||
</pre> | </pre> | ||
+ | |||
+ | |||
=== Verbose output, all coded tests === | === Verbose output, all coded tests === |
Revision as of 02:28, 5 May 2011
Contents |
OPPlus and Test-Driven Development
Testing the Shiplist
Test Driven Development
I have spent a lot of time writing tests for the shiplist, making sure that it is sane. The idea here is to implement "Test Driven Development", normally a method/philosophy used by coders.
The method is simple:
- determine a condition that must be met
- find a way to code tests to the data that confirms the condition is true
- run the tests against the whole mod.
- clean up the issues detected
- run ALL the tests each time new changes are introduced, in case we introduced problems.
By doing this, over and over, I know that the quality of this shiplist is at its best ever.
Example: Mauler
Maulers should all have the SpecialCode 'A' for Assault. The only exception is when the ship is set to 'R'estricted. The Mauler will have a Mauler weapon on it, and will have the role MAULER in the Enhanced Role or Enhanced Secondary Role column for this ship.
This is testable!
- for each ship in the shiplist
- for all weapons on this ship
- if there's a Mauler
- is this ship's SPECIAL code set to A or R?
- If not, return an error about this ship.
- is this ship's Enhanced Role or Enhanced Secondary Role set to MAULER?
- If not, return an error about this ship
- is this ship's SPECIAL code set to A or R?
- if there's a Mauler
- for all weapons on this ship
Result:
# Check that maulers have appropriate special role 'A' or 'R' and that all 'A ships have a mauler ok 56 - SpecialRole A are maulers, and maulers are A or R.
Verbose output, all coded tests
2010-05-01 test results:
$ bash t/runtests.sh --verbose /cygdrive/c/opplus/opplus41/t /cygdrive/c/opplus/opplus41 -- ./tests.t ./tests.t syntax OK ok 1 - shiplist loaded ok. # ships loaded: 8257 ok 2 - more than 0 ships loaded # Checking for race-hull count. Is everything 64/128 or less? ok 3 - Hull limits are ok: no race-hull count over 64 or 128 (if applicable) # Checking that Hull type column contains only known and sane hull types ok 4 - Hull type column contains only known and sane hull types # Checking that all ship tags are unique. ok 5 - All ship tags unique, case insensitive or not ok 6 - got shipnames data back # Check that each shiptag has 1 or more shipnames ok 7 - each ship has 1 or more shipnames ok 8 - got model_siz data back # Check that all shiplist models in OP+ have a size in model.siz ok 9 - All models used have a size defined in model.siz ok 10 - got strings data back # Check refits strings: all refits are included in strings.txt ok 11 - all refits are in strings.txt # Check Full Name strings: all Full Shipnames are included in strings.txt ok 12 - All 'Full shipnames' are in strings.txt ok 13 - got fighter list data back # Checking for phasers in heavy weapon mounts. # Exceptions: H-XSB, H-XSBF ok 14 - No phasers in heavy weapon mounts # Checking for energy heavy weapons in phaser weapon mounts. # Exceptions: Drones, ADDs, PLaDs. ok 15 - No heavy weapons in phaser mounts # Check that shield total is indeed the total of all the shields ok 16 - Total shields indeed are the total of all shields # Check weapons: are they all valid weapons? ok 17 - All weapons are valid weapons # Check that G racks >= ADD6 ok 18 - each ship: count of DroG is less than count of ADD6 # check_that_ADDs_add_up ok 19 - ADDs add up correctly # Confirm that non X2 ships with mirv have cargo and at least 5 drone racks # Exceptions: Z-BBx, Z-DNMx, Z-DNWx, Z-MTxCVA ok 20 - mirv variant sanity. # Look for bad weapon arcs. ie: plasma RAL/RAR or FAL/FAR # Exceptions: F-CFS, M-LCM, B-LCL, F-NCMx, F-CFSx, M-LCL, F-CFS+, B-LCM, F-NCM, M-LCS, B-LCS, G-LCL+ ok 21 - weapon arcs are sane. # PLaS was introduced in Y170. Check that none exist before # Exceptions: G-BF ok 22 - PLaS are all Y170 or later # PLaI was introduced in Y171. Check that none exist before # Exceptions: ok 23 - PLaI are all Y171 or later # PPD was introduced in Y168. Check that none exist before # Exceptions: ok 24 - PPD are all Y168 or later # Drones A, B, C, F were introduced in Y65. Check that none exist before # Exceptions: ok 25 - Drones A,B,C,F are all Y65 or later # Drone G racks were introduced in Y160. Check that none exist before # Exceptions: F-GSC ok 26 - Drone G racks are all Y160 or later # PlasmaD were introduced in Y165. Check that none exist before # Exceptions: R-KRTc1, R-KRTc2, R-KRTG, R-KRT, R-KBT ok 27 - PlasmaD racks are all Y165 or later # Hellbores were introduced in Y158. Check that none exist before # Exceptions: ok 28 - Hellbores are all Y158 or later # Check that SFB YFA and YLA matches game YFA and YLA ok 29 - SFB YFA and YLA matches game YFA and YLA # New Construction X1 ship sanity checks: batteries, acceleration, bases have PFs/FTRs ok 30 - New Construction X1 ship sanity checks # New Construction X2 ship sanity checks: bases have PFs/fighters ok 31 - New Construction X2 ship sanity checks # Generic X1 tech sanity checks: no G racks, ADD6 ok 32 - generic x1 tech sanity checks # All entries have at least 1 battery. Don't ask me why, but this is important. ok 33 - all shiplist entries have batteries # All entries have at least 1 excess damage. ok 34 - all shiplist entries have excess damage # All entries have at least 1 damcon ok 35 - all shiplist entries have damcon, except where expected not to have any # Races column: check that there are no weird races ok 36 - Races column is sane. # Check that all tbombs base and max are sane # Exceptions: F-BT, F-BT+, F-BTR, F-BTV, F-BTVR, F-CVT, F-CVTC, F-CVTCR, F-FXE, F-FXEx, H-GRV, I-ECA, I-ECC, I-ECL, I-EDD, I-EFF, I-ESR ok 37 - tbombs base and max are sane # Check that all Romulan warships have 1 NSM and 1 NSM max ok 38 - NSMs are sane. # Check that all appropriate ships have an explosion strength > 0 ok 39 - explosion strengths are sane # test the test! check sizeclass hash data ok 40 - testing size class data is correct # Check the turnmodes and prove the values are sane ok 41 - turnmode column data is sane. # Check that the number of deckcrews >= # fighters. ok 42 - There are enough deck crews to service fighters # Check boarding parties and boarding parties max # Exceptions: R-DMH-GG, R-DMHGGx ok 43 - boarding parties are sane. # Check that crew values are sane ok 44 - crew values are sane. # Check that all 'CARGO' role ships (and no other role) are in 'F'reighter hull class. ok 45 - All CARGO ships are Freighter class type # expected ships with shields to have at least 1 lab ok 46 - expected ships with shields have labs # check that shuttle loadouts are sane: (shuttlebase <= shuttlemax) and (Shuttle Size <= ShuttleMax AND ShuttleBase) ok 47 - ships have sane shuttlebay numbers # check that number of weapons per mount are not 0 or less nor 5 or more ok 48 - weapon numbers per mount are sane # Check that there are no heavy weapons in HDW mounts on Escorts ok 49 - no heavy weapons in escort mounts # If ship has shields, all shield sides must not be 0 ok 50 - ships with shields have shields in all facings # If ship has cloak, make sure there's no ESG. # Exceptions: T-CX3, T-TBR3, C-CX3, C-TBR2 ok 51 - ALL ships with cloak have no ESG or drones # Confirm that for each race, all ships are defined within that race's block. ok 52 - all ships are defined within each race's block # Confirm that the races are listed in the correct order ok 53 - all races are in correct order # Check that no ship has a drone control higher than 12 or lower than 0 ok 54 - Drone Control on all ships is sane # Check weapons BPV used for health bar and damages ok 55 - Weapons BPV are accurate # Check that maulers have appropriate special role 'A' or 'R' and that all 'A ships have a mauler ok 56 - SpecialRole A are maulers, and maulers are A or R. # Check that specialrole 'C' are Leader ships in enhanced shiplist ok 57 - SpecialRole C are Command ships. LEADER ships in enhanced shiplist # Check that specialrole 'D' are Drone bombardment ships and at least 2 drone racks ok 58 - SpecialRole D are Drone bombardment ships # Check that specialrole 'E' are Escort ships in enhanced shiplist ok 59 - SpecialRole E are escort ships # Check that specialrole 'L' are sublight ships ok 60 - SpecialRole L are .. were.. sublight ships # Check that specialrole 'M' are commando ships, and they have barracks and transporters ok 61 - SpecialRole M are sane commando ships # Check that specialrole 'NT' is assigned to things you can't transport to: PFs, DEFs, some planets ok 62 - Specialrole NT are PFs, DEFs or sometimes planets # Check that specialrole 'P' are Police ships or local defense ships in enhanced shiplist ok 63 - SpecialRole P are police ships and/or local defense ships # Check that specialrole 'Q' are QSHIPS in enhanced shiplist, and they must be freighters ok 64 - SpecialRole Q are Qships and are freighter hulls # Check that specialrole 'S' are scouts, and they have special sensors ok 65 - SpecialRole S are scouts and have special sensors # Check that specialrole 'T' are tournament ships ok 66 - SpecialRole T are tournament ships # Check that specialrole 'V' are CARRIER in enhanced shiplist, and they have fighters/PFs ok 67 - SpecialRole V ships are carriers # Check that all ships have Enhanced Class Type column, and that it is sane. ok 68 - Enhanced Class Type column is sane # Check that all ships have Enhanced Production Availability column, and that it is sane. ok 69 - enhanced Production Availability column is sane # Check that the enhanced role columns have at least 1 role, and that they are sane. ok 70 - enhanced role columns are sane # Check that the enhanced xtech column is sane, and that Xships should have xtech level defined ok 71 - enhXtech x1 and x2 ship entries are sane # Check that all enhanced shiplist type FREIGHTER are Freighters in the shiplist ok 72 - Enhtype freighters are sane # Check that all enhanced shiplist type CARRIER have fighters, and the fighters are valid ok 73 - Enhrole carriers are sane # Check that all enhanced shiplist type PF_TENDER have PFs, and the PFs are valid ok 74 - Enhrole PF Tenders are sane # Check that all enhanced shiplist type CARGO have cargo boxes ok 75 - Enhrole cargo ships are sane # Check that all enhanced shiplist type REPAIR have repair boxes ok 76 - Enhrole repair ships are sane # Check that all enhanced shiplist type BASE are really bases ok 77 - EnhRole bases are sane # Check that all enhanced shiplist type LISTENING_POST are really listening posts ok 78 - EnhRole listening posts are sane # Check that all enhanced shiplist type PLANET are really planets ok 79 - EnhRole planets are sane. # Check that all defense platforms are enhrole LOCAL_DEFENSE, enhtype PLATFORM and have ?DP UI ok 80 - EnhRole Defense platforms are sane # Check that all FRDs are enhtype FLEET_REPAIR_DOCK, enhrole REPAIR and have XSS UI ok 81 - EnhType FRDs are sane # Check that all enhanced shiplist roles COMMANDO are indeed commando ships and are sane. ok 82 - EnhRole COMMANDO ships are sane. # Check that all enhanced shiplist type SHUTTLE are indeed shuttles. ok 83 - EnhType SHUTTLE entries are sane. # Check that all enhanced shiplist type ASTEROID are indeed asteroids. ok 84 - EnhType ASTEROID entries are sane. # Check that all enhanced shiplist types for monsters are indeed monsters. ok 85 - EnhType for monsters are sane. # Check that LDR and WYN ships are all SPECIAL ok 86 - LDR and WYN ships are all SPECIAL. # Check that all Availability UNIQUE ships are 'R' or SPECIAL ok 87 - all Availability UNIQUE ships are 'R' or SPECIAL # Check that all Asteroid bases use the XAB UI, and that XAB UI are Asteroid Bases ok 88 - All asteroid bases use XAB UI # Check that all BattleStations, SectorBases and Starbases ?SB UI (except Orions) ok 89 - All BattleStations, SectorBases and Starbases use ?SB UI # Check that all Base Stations and mobile bases use the ?BS or ?SB UI (except Orions) ok 90 - All base station and mobile bases use ?BS or ?SB UI # Check that all BOXes use the ?BOX UI ok 91 - All boxes use ?BOX UI # Check that everything has a UI ok 92 - All ships have UI # Check that weapons are all mounted in UI-usable points # Exceptions: K-B10Vx, K-B11Vx # ship K-B10Txm: WARNING! Shared mount in use for both heavy and phaser weapons ok 93 - all weapons use sane UI mountpoints. # Verify that no carrier predates its own fighters ok 94 - no carrier predates its own fighters # Check that refits are sane. ok 95 - refits are sane # Eliminate unwanted PF versions of ships: check to see if PF version and normal version is same YFA, and that the normal version has mechlinks. # Exceptions: G-BCHF, L-BCHT ok 96 - no unwanted PF variants # Check that any ships with PFs should have mechlinks of equal or greater number ok 97 - mechlinks are ok # Confirm the Fighter BPV columns are accurate ok 98 - Fighter BPV columns are accurate # Refitted ships have proper YFA and YLA. ok 99 - refitted ships YLA are sane. new refit ships YFA are also sane # Confirm that the weapon refit occured: gets PLaS somewhere. ok 100 - PLaS refits all have PLaS on ship. # Confirm that the weapon refit occured: gets Ph3 somewhere. ok 101 - Ph3 refits all have Ph3 on ship. # Confirm that the weapon refit occured: gets Ph1 somewhere. ok 102 - Ph1 refits all have Ph1 on ship. # Confirm that the weapon refit occured: gets Ph2 somewhere. ok 103 - Ph2 refits all have Ph2 on ship. # Confirm that the weapon refit occured: gets DroG somewhere. ok 104 - DRONE G refits all have DroG on ship. # Confirm that the weapon refit occured: gets PLaF somewhere. ok 105 - PLaF refits all have PLaF on ship. # Confirm that the weapon refit occured: gets PLaG somewhere. ok 106 - PLaG refits all have PLaG on ship. # Confirm that the weapon refit occured: gets ESG somewhere. ok 107 - ESG refits all have ESG on ship. # Confirm that the weapon refit occured: gets HB somewhere. ok 108 - HB refits all have HB on ship. # Confirm that the weapon refit occured: gets PPD somewhere. ok 109 - PPD refits all have PPD on ship. # Confirm that the weapon refit occured: gets MIRV somewhere. ok 110 - MIRV refits all have DroM on ship. # Confirm that the weapon refit occured: gets PLaD somewhere. ok 111 - PLaD refits all have PLaD on ship. # Confirm that the weapon refit occured: gets PLaI somewhere. ok 112 - PLaI refits all have PLaI on ship. # Confirm that the weapon refit occured: gets ADD somewhere. ok 113 - ADD UPG refit : ships get ADD somewhere on ship. # Confirm that the weapon refit occured: gets ADD or Drone somewhere. ok 114 - DRONE UPG refit : ships get ADD/Drone somewhere on ship. # Confirm that the weapon refit occured: gets Drone on DRONE refit ok 115 - DRONE refits all have a form of Drone or other on ship. # Confirm shield refit actually increased shields. ok 116 - shield refits all increase shields on ships # Confirm power refit actually increased total power. ok 117 - power refits all increase total power on ships # Check that Fast Cruisers from PF races get PFs ok 118 - Fast Cruisers from PF races get PFs # Check that no weapons with reloads have just 1 reload after Y175. ok 119 - all weapons with reloads have more than 1 reload past Y175 # Check that fighter weapons are all valid weapons ok 120 - All fighter weapons are sane and valid # Check that fighter races are all valid races ok 121 - All fighter races are sane and valid # Check that fighter ECM is valid ok 122 - All fighters' ECM is valid # Check that fighter ECCM is valid ok 123 - All fighters' ECCM is valid # Check that fighters have valid UI ok 124 - All fighters have valid UI # Check that all fighter models in OP+ have a size in model.siz ok 125 - All models used have a size defined in model.siz # Check that fighter speeds are sane ok 126 - All fighter speeds are sane. # Check that fighter PhG aren't available too early ok 127 - All fighter PhG are Y170 and later # Check that fighter Fus aren't available too early ok 128 - All fighter Fus are Y135 and later # Check that all fighter shiptags are unique. ok 129 - All fighter tags entries are unique # Confirm that all starter fighters are available really early ok 130 - all starter fighters are all available early 1..130
Code refactored
I have created a perl module to refactor code I like to use between multiple scripts. I have not (yet?) released this code.. but here it some documentation on how it's set up, below:
NAME OPPlus::Shiplist - Perl extension for OP+ shiplist scripts and tests SYNOPSIS use OPPlus::Shiplist; my $o_s = OPPlus::Shiplist->new(); my ($shiplist_data, $return_code) = $o_s->load_shiplist( $shiplist_file ); my $shipnames_data = $o_s->load_shipnames( $shipnames_file ); my $strings_data = $o_s->load_strings( $strings_file ); my $modelsiz_data = $o_s->load_model_siz( $model_siz_file ); my $fighter_list_data = $o_s->load_fighter_list( $ftrlist_file ); my $bool = $o_s->is_size_class( $sizeclass, $shiplist_data, $ship_tag ); my $sizeclass = $o_s->get_size_class( $shiplist_data, $ship_tag ); my @heavy_mounts = $o_s->heavy_mounts_list(); my @phaser_mounts = $o_s->phaser_mounts_list(); my @fighter_weapon_mounts = $o_s->fighter_weapon_mounts_list(); my @numeric_columns = $o_s->numeric_columns_list(); my @integer_columns = $o_s->integer_columns_list(); my @float_columns = $o_s->float_columns_list(); my @shields_columns = $o_s->shields_columns_hashref(); my @ftr_bays = $o_s->ftr_bays_list(); my $valid_weapons_and_load_costs = $o_s->valid_weapons_and_load_costs_hashref(); my $valid_weapons_arcs_and_reloads = $o_s->valid_weapons_arcs_and_reloads_hashref(); my $valid_weapons_arcs = $o_s->valid_weapons_arcs_hashref(); my $valid_weapons_reloads = $o_s->valid_weapons_reloads_hashref(); my $valid_fighter_weapons = $o_s->valid_fighter_weapons_hashref(); my $valid_refits_data = $o_s->valid_refits_data_hashref(); my $not_a_refit = $o_s->not_a_refit_hashref(); my $UI_data = $o_s->UI_data_hashref(); my $valid_UI = $o_s->valid_UI_hashref(); my $races = $o_s->races_hashref(); my $pirate_races = $o_s->pirate_races_hashref(); my $annex_8B_weapons = $o_s->annex_8B_hashref(); my $annex_8B_systems = $o_s->annex_8B_systems_hashref(); my $annex_8H_weapons = $o_s->annex_8H_weapons_hashref(); my $annex_8H_systems = $o_s->annex_8B_systems_hashref(); my $bpvdata__systems_BPV = $o_s->bpvdata__systems_BPV_hashref(); my $hulllimit_per_race = $o_s->hulllimit(); my $valid_hull_types = $o_s->valid_hull_types_hashref(); my $valid_enhanced_production_availability = $o_s->valid_enhanced_production_availability_hashref(); my $valid_enhanced_roles = $o_s->valid_enhanced_roles_hashref(); my $sizeclass_by_enhanced_class_type = $o_s->sizeclass_by_enhanced_class_type_hashref(); @shiprow = $o_s->update_weapon_BPV_columns(\@shiprow); @shiprow = $o_s->update_systems_BPV(\@shiprow); @shiprow = $o_s->update_BPV_subtotal(\@shiprow); @shiprow = $o_s->update_SFB_YFA_and_YLA(\@shiprow); @shiprow = $o_s->update_fighter_bays_BPV(\@shiprow, $shiplist_file, $ftrlist_file;) $o_s->write_ship($outputfilename, $shiprow_arrayref); $o_s->write_shipnames( $outputfilename, $ship_tag, $shipnames_arrayref ); # $shipnames_arrayref example: $shipnames_data->{'shipnames'}->{$source_ship_tag} DESCRIPTION This module is a refactor of various functions I wanted refactored and shared between multiple OP+ related shiplist scripts. EXPORT None by default. SEE ALSO http://klingon.pet.dhs.org/OP_plusrefit/ http://pet.dhs.org/mediawiki/index.php/OPPlus_4.1_project_wiki AUTHOR FireSoul, firesoul@pet.dhs.org COPYRIGHT AND LICENSE Copyright (C) 2011 by FireSoul This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.
Model Testing
To test models, I simply reuse some old tools I have created way-back-when: 3 scripts that loads and then blows up a ship of each model.
The scripts do the following:
- Find all the model files relevant to the current script (complete, single race, bases)
- load up a ship for each model file, to test the .MOD file
- blow up the ship, to test the _BRK.MOD file
The idea is that for each ship that it loads and then blows up, results are written to disk. To see the results, you can review a log file. The file is C:\TestModels.txt . If you run these scripts and you crashed, you should check this logfile!
There are 3 scripts:
- Standard version, 1 race at a time:
- Ski_test_models.scr size: 470kb (Version 1.23, 20040627)
- Ski_test_models-20040627.zip size: 72kb (sources)
- Complete test version, all models tested in a single run:
- Ski_test_all_models.scr size: 470kb (Version 1.00, 20040714)
- Ski_test_all_models-20040714.zip size: 77kb (sources)
- 'Test all bases' models, all in a single run:
- Ski_test_bases_models.scr size: 470kb (Version 1.00, 20040714)
- Ski_test_bases_models-20040714.zip size: 90kb (sources)
Look for "SFC:OP Models Tester" scripts on http://klingon.pet.dhs.org/sources_and_utils/ .