Skip to content

Commit

Permalink
Add Hypothesis tests for TradeCodes (#71)
Browse files Browse the repository at this point in the history
* Add hypothesis to requirements

* Bump ruff requirement

* Fix ruff complaints in Calculation folder

* Empty-guard allegiance reduction

* Fix ruff complaints in root folder

* Add initial hypothesis test for TradeCodes

* Extend tradeCodes hypothesis check to round-trips

* Add common-use allowed trade pairs

* Stich together split homeworld codes when creating TradeCode object

* Add remaining common-use trade code pair

* Handle homeworlds with unknown populations

* Assorted trade-code fixes and blast damage fixen

* Enforce no trade-code duplication

* Add accumulated bunch of previously-problematic trade codes

* Unpack compact Chirper/Droyne trade codes

* Explain ok_pairs rationale

* Update allowed residuals

* Fix more test blowups

* Trim malformed trade codes when parsing starlines

* Move malformed code trimming inside TradeCode ctor

* Add unicode char for RS Omega

* Sort codes before rebuilding initial_codes string

* Unpack homeworlds in stat calculation

* Compile homeworld-match regex

* Compile sophont-list and dieback-world regexen

* Start enforcing strict Trav5 sophont codes

* Wring out sophont and homeworld list generation

* Exclude new-type sophont codes from invalid-pair checks

* Start verifying major-race homeworlds

* Handle explicit populations for major race homeworlds

* Verify major races can share homeworlds

* Explicitly reject multiple W-pop sophont codes

* Fix test blast damage

* Drop dead code

* Handle <4-char codes in StatCalculation

* Add stub total-checks

* Dodge homeworld-importance jam-ups in star lines
  • Loading branch information
CyberiaResurrection authored Nov 19, 2023
1 parent 5fcdd27 commit 8a672f9
Show file tree
Hide file tree
Showing 14 changed files with 656 additions and 51 deletions.
18 changes: 18 additions & 0 deletions PyRoute/Calculation/RouteCalculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,21 @@ def unilateral_filter(self, star):
@return: Whether the star can be unilaterally filtered
"""
return False

def is_sector_trade_balanced(self):
pass

def is_sector_pass_balanced(self):
pass

def is_allegiance_trade_balanced(self):
pass

def is_allegiance_pass_balanced(self):
pass

def multilateral_balance_trade(self):
pass

def multilateral_balance_pass(self):
pass
2 changes: 1 addition & 1 deletion PyRoute/Calculation/TradeCalculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def get_trade_between(self, star, target):
"This route from " + str(star) + " to " + str(target) + " has already been processed in reverse"

try:
rawroute, diag = astar_path_indexes(self.galaxy.stars, star.index, target.index, self.galaxy.heuristic_distance_indexes)
rawroute, _ = astar_path_indexes(self.galaxy.stars, star.index, target.index, self.galaxy.heuristic_distance_indexes)
except nx.NetworkXNoPath:
return

Expand Down
8 changes: 4 additions & 4 deletions PyRoute/Calculation/TradeMPCalculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def intrasector_process(working_queue, processed_queue):
continue

try:
rawroute, diag = astar_path_indexes(tradeCalculation.galaxy.stars, star.index, neighbor.index,
rawroute, _ = astar_path_indexes(tradeCalculation.galaxy.stars, star.index, neighbor.index,
tradeCalculation.galaxy.heuristic_distance_indexes)
except nx.NetworkXNoPath:
continue
Expand Down Expand Up @@ -82,7 +82,7 @@ def long_route_process(working_queue, processed_queue):
break

try:
route, diag = astar_path_indexes(tradeCalculation.galaxy.stars, star, neighbor,
route, _ = astar_path_indexes(tradeCalculation.galaxy.stars, star, neighbor,
tradeCalculation.galaxy.heuristic_distance_indexes)
except nx.NetworkXNoPath:
continue
Expand Down Expand Up @@ -153,7 +153,7 @@ def calculate_routes(self):

# This is the multiprocess method, which contains all the logic for using multi-process in the parent (core) process
# When this is completed, all the child process should be completed.
def start_mp_services (self):
def start_mp_services(self):
global tradeCalculation
tradeCalculation = self

Expand Down Expand Up @@ -281,7 +281,7 @@ def get_trade_between(self, star, target):
f"This route from {star} to {target} has already been processed in reverse"

try:
rawroute, diag = astar_path_indexes(self.galaxy.stars, star.index, target.index, self.galaxy.heuristic_distance_indexes)
rawroute, _ = astar_path_indexes(self.galaxy.stars, star.index, target.index, self.galaxy.heuristic_distance_indexes)
except nx.NetworkXNoPath:
return

Expand Down
2 changes: 1 addition & 1 deletion PyRoute/DeltaDebug/DeltaReduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def is_initial_state_interesting(self):
sectors = self.sectors
args = self.args

interesting, msg, _ = self._check_interesting(args, sectors)
interesting, _, _ = self._check_interesting(args, sectors)

if not interesting:
raise AssertionError("Original input not interesting - aborting")
Expand Down
4 changes: 4 additions & 0 deletions PyRoute/DeltaPasses/AllegianceReducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def run(self, singleton_only=False):
continue

temp_sectors = best_sectors.allegiance_subset(raw_lines)
temp_lines = len(temp_sectors.lines)
if 0 == temp_lines:
# nothing to do, move on
continue

interesting, msg, _ = self.reducer._check_interesting(self.reducer.args, temp_sectors)
# We've found a chunk of input and have _demonstrated_ its irrelevance,
Expand Down
7 changes: 5 additions & 2 deletions PyRoute/StatCalculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,22 @@ def add_alg_stats(self, area, star, alg):
self.max_tl(algStats, star)

def add_pop_to_sophont(self, stats, star):

total_pct = 100
default_soph = 'Huma'
home = None
for sophont in star.tradeCode.sophonts:
soph_code = sophont[0:4]
soph_pct = sophont[4:]

if 4 == len(sophont):
soph_code = sophont[0:3]
soph_pct = sophont[3:]

if soph_pct == 'A':
default_soph = soph_code
continue

soph_pct = 100.0 if soph_pct == 'W' else 0.0 if soph_pct in ['X', 'A'] else \
soph_pct = 100.0 if soph_pct == 'W' else 0.0 if soph_pct in ['X', 'A', '?'] else \
5.0 if soph_pct == '0' else 10.0 * int(soph_pct)

if any([soph for soph in star.tradeCode.homeworld if soph.startswith(soph_code)]):
Expand Down
Loading

0 comments on commit 8a672f9

Please sign in to comment.