Files
Bubberstation/code/modules/unit_tests/cargo_crate_sanity.dm
SmArtKar bdfe18fbad Blacklists certain RNG-dependant crates from testing (#90333)
## About The Pull Request

Blacklists dumpster, hide, random toys, contraband and random medical
equipment crates from the cargo_crate_sanity unit test. These crates are
innately random, and while we have to be aware of potentially having
their average be over their price, we cannot (sanely) test for that
(without spawning a thousand crates, and even then we're affected by
random). The whole point of these crates is gambling on their value.

Closes #90328 
Closes #90314
Closes #90298
Closes #90253
Closes #90216
Closes #90181
Closes #90178

## Changelog

Not player facing
2025-03-30 21:12:30 +02:00

43 lines
2.0 KiB
Plaintext

/**
* This unit test loops through all cargo crates that are available to purchase, and confirms that they're below the expected sanity minimum when sold.
* This prevents us from merging a crate that sells for more that it costs to buy.
*/
/datum/unit_test/cargo_crate_sanity
/datum/unit_test/cargo_crate_sanity/Run()
for(var/crate in subtypesof(/datum/supply_pack))
var/datum/supply_pack/new_crate = allocate(crate)
if(new_crate.test_ignored)
continue // We can safely ignore custom supply packs like the stock market or mining supply crates, or packs that have innate randomness.
if(!new_crate?.crate_type)
continue
var/obj/crate_type = allocate(new_crate.crate_type)
var/turf/open/floor/testing_floor = get_turf(crate_type)
var/datum/export_report/minimum_cost = export_item_and_contents(crate_type, delete_unsold = TRUE, dry_run = TRUE)
var/crate_value = counterlist_sum(minimum_cost.total_value)
var/obj/results = new_crate.generate(testing_floor)
var/datum/export_report/export_log = export_item_and_contents(results, apply_elastic = TRUE, delete_unsold = TRUE, export_market = EXPORT_MARKET_STATION)
// The value of the crate and all of it's contents.
var/value = counterlist_sum(export_log.total_value)
// We're selling the crate and it's contents for more value than it's supply_pack costs.
if(value > new_crate.get_cost())
TEST_FAIL("Cargo crate [new_crate.type] had a sale value of [value], Selling for more than [new_crate.get_cost()], the cost to buy")
// We're selling the crate & it's contents for less than the value of it's own crate, meaning you can buy and infinite number
if(crate_value > new_crate.get_cost())
TEST_FAIL("Cargo crate [new_crate.type] container sells for [crate_value], Selling for more than [new_crate.get_cost()], the cost to buy")
for(var/atom/stuff as anything in results.contents)
qdel(stuff)
stuff = null
qdel(results)
results = null
new_crate = null
minimum_cost = null
export_log = null