OP+ and Test-Driven Development

(Verbose output, all coded tests)
(Model Testing)
 
(One intermediate revision by one user not shown)
Line 441: Line 441:
  
  
TODO: script download links
+
For more information and download links, see:
 +
[http://klingon.pet.dhs.org/mediawiki/index.php?title=SFC-related_missions,_sources,_patches_and_misc_utilities#SFC:OP_Models_Tester http://klingon.pet.dhs.org/mediawiki/index.php?title=SFC-related_missions,_sources,_patches_and_misc_utilities#SFC:OP_Models_Tester]

Latest revision as of 15:28, 5 June 2011

Contents

[edit] OPPlus and Test-Driven Development

[edit] Testing the Shiplist

[edit] 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.


[edit] 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

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.


[edit] Verbose output, all coded tests

2010-06-05 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: 8299
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
# confirm that no planet can cloak
ok 56 - no planet can cloak
# check that all planets use new models
ok 57 - all planets use new models
# check planet weapons and arcs
ok 58 - planet weapons and arcs are good.
# check that planets have correct # of tractor
ok 59 - planets have correct \# of tractors
# Check that maulers have appropriate special role 'A' or 'R' and that all 'A ships have a mauler
ok 60 - SpecialRole A are maulers, and maulers are A or R.
# Check that specialrole 'C' are Leader ships in enhanced shiplist
ok 61 - 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 62 - SpecialRole D are Drone bombardment ships
# Check that specialrole 'E' are Escort ships in enhanced shiplist
ok 63 - SpecialRole E are escort ships
# Check that specialrole 'L' are sublight ships
ok 64 - SpecialRole L are .. were.. sublight ships
# Check that specialrole 'M' are commando ships, and they have barracks and transporters
ok 65 - SpecialRole M are sane commando ships
# Check that specialrole 'NT' is assigned to things you can't transport to: PFs, DEFs, some planets
ok 66 - Specialrole NT are PFs, DEFs or sometimes planets
# Check that specialrole 'P' are Police ships or local defense ships in enhanced shiplist
ok 67 - 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 68 - SpecialRole Q are Qships and are freighter hulls
# Check that specialrole 'S' are scouts, and they have special sensors
ok 69 - SpecialRole S are scouts and have special sensors
# Check that specialrole 'T' are tournament ships
ok 70 - SpecialRole T are tournament ships
# Check that specialrole 'V' are CARRIER in enhanced shiplist, and they have fighters/PFs
ok 71 - SpecialRole V ships are carriers
# check that excess ?-PE homeworlds are 'R'estricted
ok 72 - Excess -PE homeworlds are 'R'estricted
# Check that all ships have Enhanced Class Type column, and that it is sane.
ok 73 - Enhanced Class Type column is sane
# Check that all ships have Enhanced Production Availability column, and that it is sane.
ok 74 - enhanced Production Availability column is sane
# Check that the enhanced role columns have at least 1 role, and that they are sane.
ok 75 - enhanced role columns are sane
# Check that the enhanced xtech column is sane, and that Xships should have xtech level defined
ok 76 - enhXtech x1 and x2 ship entries are sane
# Check that all enhanced shiplist type FREIGHTER are Freighters in the shiplist
ok 77 - Enhtype freighters are sane
# Check that all enhanced shiplist type CARRIER have fighters, and the fighters are valid
ok 78 - Enhrole carriers are sane
# Check that all enhanced shiplist type PF_TENDER have PFs, and the PFs are valid
ok 79 - Enhrole PF Tenders are sane
# Check that all enhanced shiplist type CARGO have cargo boxes
ok 80 - Enhrole cargo ships are sane
# Check that all enhanced shiplist type REPAIR have repair boxes
ok 81 - Enhrole repair ships are sane
# Check that all enhanced shiplist type BASE are really bases
ok 82 - EnhRole bases are sane
# Check that all enhanced shiplist type LISTENING_POST are really listening posts
ok 83 - EnhRole listening posts are sane
# Check that all enhanced shiplist type PLANET are really planets
ok 84 - EnhRole planets are sane.
# Check that all defense platforms are enhrole LOCAL_DEFENSE, enhtype PLATFORM and have ?DP UI
ok 85 - EnhRole Defense platforms are sane
# Check that all FRDs are enhtype FLEET_REPAIR_DOCK, enhrole REPAIR and have XSS UI
ok 86 - EnhType FRDs are sane
# Check that all enhanced shiplist roles COMMANDO are indeed commando ships and are sane.
ok 87 - EnhRole COMMANDO ships are sane.
# Check that all enhanced shiplist type SHUTTLE are indeed shuttles.
ok 88 - EnhType SHUTTLE entries are sane.
# Check that all enhanced shiplist type ASTEROID are indeed asteroids.
ok 89 - EnhType ASTEROID entries are sane.
# Check that all enhanced shiplist types for monsters are indeed monsters.
ok 90 - EnhType for monsters are sane.
# Check that LDR and WYN ships are all SPECIAL
ok 91 - LDR and WYN ships are all SPECIAL.
# Check that all Availability UNIQUE ships are 'R' or SPECIAL
ok 92 - all Availability UNIQUE ships are 'R' or SPECIAL
# Check that MEDIUM_CRUISER are really the HEAVY_WAR_CRUISERs that are missing, and are 0.75 move cost
Exceptions: F-CL, F-CLD, F-CLH, F-CLV, F-ECLok 93 - All MEDIUM_CRUISER are movecost 0.75
# Check that all Asteroid bases use the XAB UI, and that XAB UI are Asteroid Bases
ok 94 - All asteroid bases use XAB UI
# Check that all BattleStations, SectorBases and Starbases ?SB UI (except Orions)
ok 95 - 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 96 - All base station and mobile bases use ?BS or ?SB UI
# Check that all BOXes use the ?BOX UI
ok 97 - All boxes use ?BOX UI
# Check that everything has a UI
ok 98 - 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 99 - all weapons use sane UI mountpoints.
# Check that refits are sane.
ok 100 - 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 101 - no unwanted PF variants
# Check that any ships with PFs should have mechlinks of equal or greater number
ok 102 - mechlinks are ok
# Refitted ships have proper YFA and YLA.
ok 103 - refitted ships YLA are sane. new refit ships YFA are also sane
# Confirm that the weapon refit occured: gets PLaS somewhere.
ok 104 - PLaS refits all have PLaS on ship.
# Confirm that the weapon refit occured: gets Ph3 somewhere.
ok 105 - Ph3 refits all have Ph3 on ship.
# Confirm that the weapon refit occured: gets Ph1 somewhere.
ok 106 - Ph1 refits all have Ph1 on ship.
# Confirm that the weapon refit occured: gets Ph2 somewhere.
ok 107 - Ph2 refits all have Ph2 on ship.
# Confirm that the weapon refit occured: gets DroG somewhere.
ok 108 - DRONE G refits all have DroG on ship.
# Confirm that the weapon refit occured: gets PLaF somewhere.
ok 109 - PLaF refits all have PLaF on ship.
# Confirm that the weapon refit occured: gets PLaG somewhere.
ok 110 - PLaG refits all have PLaG on ship.
# Confirm that the weapon refit occured: gets ESG somewhere.
ok 111 - ESG refits all have ESG on ship.
# Confirm that the weapon refit occured: gets HB somewhere.
ok 112 - HB refits all have HB on ship.
# Confirm that the weapon refit occured: gets PPD somewhere.
ok 113 - PPD refits all have PPD on ship.
# Confirm that the weapon refit occured: gets MIRV somewhere.
ok 114 - MIRV refits all have DroM on ship.
# Confirm that the weapon refit occured: gets PLaD somewhere.
ok 115 - PLaD refits all have PLaD on ship.
# Confirm that the weapon refit occured: gets PLaI somewhere.
ok 116 - PLaI refits all have PLaI on ship.
# Confirm that the weapon refit occured: gets ADD somewhere.
ok 117 - ADD UPG refit : ships get ADD somewhere on ship.
# Confirm that the weapon refit occured: gets ADD or Drone somewhere.
ok 118 - DRONE UPG refit : ships get ADD/Drone somewhere on ship.
# Confirm that the weapon refit occured: gets Drone on DRONE refit
ok 119 - DRONE refits all have a form of Drone or other on ship.
# Confirm shield refit actually increased shields.
ok 120 - shield refits all increase shields on ships
# Confirm power refit actually increased total power.
ok 121 - power refits all increase total power on ships
# Check that Fast Cruisers from PF races get PFs
ok 122 - Fast Cruisers from PF races get PFs
# Check that no weapons with reloads have just 1 reload after Y175.
ok 123 - all weapons with reloads have more than 1 reload past Y175
# Check for any missed Advanced Era ships that should have expired
ok 124 - All ships in advanced era aren't just leftovers from late era
# Verify that no carrier predates its own fighters
ok 125 - no carrier predates its own fighters
# Confirm the Fighter BPV columns are accurate
ok 126 - Fighter BPV columns are accurate
# Check that fighter weapons are all valid weapons
ok 127 - All fighter weapons are sane and valid
# Check that fighter races are all valid races
ok 128 - All fighter races are sane and valid
# Check that fighter ECM is valid
ok 129 - All fighters' ECM is valid
# Check that fighter ECCM is valid
ok 130 - All fighters' ECCM is valid
# Check that fighters have valid UI
ok 131 - All fighters have valid UI
# Check that all fighter models in OP+ have a size in model.siz
ok 132 - All models used have a size defined in model.siz
# Check that fighter speeds are sane
ok 133 - All fighter speeds are sane.
# Check that fighter PhG aren't available too early
ok 134 - All fighter PhG are Y170 and later
# Check that fighter Fus aren't available too early
ok 135 - All fighter Fus are Y135 and later
# Check that all fighter shiptags are unique.
ok 136 - All fighter tags entries are unique
# Confirm that all starter fighters are available really early
ok 137 - all starter fighters are all available early
1..137

[edit] 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.


[edit] 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!


For more information and download links, see: http://klingon.pet.dhs.org/mediawiki/index.php?title=SFC-related_missions,_sources,_patches_and_misc_utilities#SFC:OP_Models_Tester

-->