Files
Bubberstation/code/modules/unit_tests/container_sanity.dm
san7890 b55d7c2350 Unit Tests Overstuffing Reagent Containers with more than their defined volume (#71327)
## About The Pull Request

Simple Unit Test that seeks to ensure that we don't put too much of a
reagent in a container when the container doesn't have enough volume to
accept all of it. Nothing bad would happen, but it's just silly really.

I also fixed all of the instances that this was broken in.
## Why It's Good For The Game

Prevents buggy regressions, such as those found in #71206.

```txt
[2022-11-18 03:32:30.736]     FAILURE #1: Canned Laughter (/obj/item/reagent_containers/cup/soda_cans/canned_laughter) has 50 units of reagents, but only 30 units of space. at code/modules/unit_tests/container_sanity.dm:21
 -     FAILURE #2: T-Borg's tonic water (/obj/item/reagent_containers/cup/soda_cans/tonic) has 50 units of reagents, but only 30 units of space. at code/modules/unit_tests/container_sanity.dm:21
 -     FAILURE #3: The soda water (/obj/item/reagent_containers/cup/soda_cans/sodawater) has 50 units of reagents, but only 30 units of space. at code/modules/unit_tests/container_sanity.dm:21
```
## Changelog

🆑
fix: Canned Laughter, T-Borg's Tonic Water, and Soda Water cans should
all come with the expected marketed 50 units of goodness, rather than
cheaping out on materials for only 30 units of can volume.
/🆑

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2022-11-18 23:11:23 -08:00

20 lines
1.3 KiB
Plaintext

/// Test to ensure that all possible reagent containers have enough space to hold any reagents they spawn in with.
/// A drink can with only 30 units of space should not be able to hold 50 units of drink, as an example.
/datum/unit_test/reagent_container_sanity
/datum/unit_test/reagent_container_sanity/Run()
for(var/entry in subtypesof(/obj/item/reagent_containers))
var/obj/item/reagent_containers/container = allocate(entry)
var/initialized_volume = 0
if(!length(container.list_reagents))
continue
// Get the volume of the reagents in the container that we initialize with, must tally up all of the values in the associated list because checking it through
// the reagents datum will only ever return the maximum volume of the container when "overfull" (adding 120 units to a 100 unit beaker means you only get 100 units of stuff contained).
for(var/reagent in container.list_reagents)
initialized_volume += container.list_reagents[reagent]
if(initialized_volume > container.volume)
// include the path as well here since there's up to like five "hypospray" or "beaker" or "soda water" types that aren't distinct enough to be differentiated by name alone.
TEST_FAIL("[container] ([container.type]) has [initialized_volume] units of reagents, but only [container.volume] units of space.")