Skip to content

Commit

Permalink
Genericized atom-counting unit tests (#1172)
Browse files Browse the repository at this point in the history
* Genericized atom-counting unit test

* fuck me

* Fix standards failures

* This one's experimental.

* whoops

* Update code/modules/unit_tests/mapping_standards/no_renamed_areas.dm

* Update code/modules/unit_tests/mapping_standards/enforce_count/_enforce_count.dm

* Killing you, asshole.

* If it so pleases the court jester

* Area exemption functionality

---------

Co-authored-by: Kapu1178 <[email protected]>
  • Loading branch information
francinum and Kapu1178 authored Dec 29, 2024
1 parent 27fdd1a commit 6bb8e09
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 53 deletions.
26 changes: 4 additions & 22 deletions _maps/map_files/Theseus/Theseus.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,6 @@
},
/obj/machinery/atmospherics/pipe/smart/manifold4w/supply/hidden/layer4,
/obj/machinery/atmospherics/pipe/smart/manifold4w/scrubbers/hidden/layer2,
/obj/machinery/door/firedoor,
/turf/open/floor/iron,
/area/station/hallway/primary/port)
"aDo" = (
Expand Down Expand Up @@ -23015,7 +23014,6 @@
/obj/structure/disposalpipe/segment{
dir = 4
},
/obj/machinery/door/firedoor,
/turf/open/floor/iron,
/area/station/hallway/primary/port)
"iEh" = (
Expand Down Expand Up @@ -24697,7 +24695,6 @@
/obj/structure/cable/yellow{
icon_state = "12"
},
/obj/machinery/door/firedoor,
/turf/open/floor/iron,
/area/station/hallway/primary/port)
"joU" = (
Expand Down Expand Up @@ -39900,12 +39897,6 @@
req_access_txt = "69"
},
/obj/machinery/door/firedoor,
/obj/machinery/door/airlock/medical{
name = "Chemical Storage";
stripe_paint = "#ff9900";
req_access_txt = "69"
},
/obj/machinery/door/firedoor,
/turf/open/floor/iron/white,
/area/station/medical/medbay/central)
"oPj" = (
Expand Down Expand Up @@ -63583,15 +63574,6 @@
},
/turf/open/floor/iron,
/area/station/hallway/primary/central/fore)
"xGi" = (
/obj/machinery/door/airlock/security/glass{
name = "Security Deck";
req_one_access_txt = "1;4"
},
/obj/machinery/door/firedoor,
/obj/machinery/door/firedoor,
/turf/open/floor/iron/dark,
/area/station/security/deck)
"xGs" = (
/obj/structure/disposalpipe/segment{
dir = 4
Expand Down Expand Up @@ -96273,9 +96255,9 @@ cgC
cgC
bhW
gbw
xGi
iWI
hQr
iWI
cgB
tIJ
wOR
fBp
Expand Down Expand Up @@ -96530,9 +96512,9 @@ uiW
uiW
uiW
aeU
xGi
iWI
hQr
iWI
cgB
nBb
iuP
eyI
Expand Down
6 changes: 5 additions & 1 deletion code/modules/unit_tests/mapping_standards/__include.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
#include "_mapping_standards.dm"

#include "ladders_must_have_openspace.dm"
#include "one_light_per_tile.dm"
#include "no_renamed_areas.dm"

#include "enforce_count\_enforce_count.dm"
#include "enforce_count\lights.dm"
#include "enforce_count\doors.dm"
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/datum/unit_test/mapping_standards/enforce_count
abstract_type = /datum/unit_test/mapping_standards/enforce_count


var/allowed_count = 1

/// Type to check. Includes subtypes.
var/checked_type = null
/// 'Friendly Name' used in fail messages.
var/failed_name = "Bad Objects"

/datum/unit_test/mapping_standards/enforce_count/proc/get_collection()
TEST_FAIL("Missing Collection Setup, Bad Test!")

/datum/unit_test/mapping_standards/enforce_count/Run()
if(..())
return

/// Turfs we've passed once. We don't fully count every tile.
var/list/turf/checked_turfs = list()
/// Tiles we've fully counted, If we reach these again, we can
/// safely skip them.
var/list/turf/counted_turfs = list()

for(var/atom/checked_atom as anything in get_collection())
if(!istype(checked_atom, checked_type))
continue //Skip types we aren't checking.
var/area/atom_area = get_area(checked_atom)
if(!(atom_area.type in GLOB.the_station_areas))
continue //Not on station, Skip.

var/turf/atom_turf = get_turf(checked_atom)
if(atom_turf in checked_turfs)
if(atom_turf in counted_turfs)
continue //Already reported.
counted_turfs.Add(atom_turf)
var/atom_count = 0
for(var/_counter as anything in atom_turf)
if(!istype(_counter, checked_type))
continue // Not of the type we care about.
atom_count++
if(atom_count < allowed_count)
continue //We've counted, but the count came up short. Not a failure.
TEST_FAIL("[atom_count] [failed_name] on tile at [AREACOORD(atom_turf)]")
continue //Already added to the checked list.
//Else
checked_turfs.Add(atom_turf)
20 changes: 20 additions & 0 deletions code/modules/unit_tests/mapping_standards/enforce_count/doors.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/datum/unit_test/mapping_standards/enforce_count/doors
abstract_type = /datum/unit_test/mapping_standards/enforce_count/doors

/datum/unit_test/mapping_standards/enforce_count/doors/get_collection()
return INSTANCES_OF(/obj/machinery/door)

/datum/unit_test/mapping_standards/enforce_count/doors/airlock
name = "MAPSTANDARDS: Tiles Must Have At Most 1 Airlock"
checked_type = /obj/machinery/door/airlock
failed_name = "Airlocks"

/datum/unit_test/mapping_standards/enforce_count/doors/firedoor
name = "MAPSTANDARDS: Tiles Must Have At Most 1 Firedoor"
checked_type = /obj/machinery/door/firedoor
failed_name = "Firedoors"

/datum/unit_test/mapping_standards/enforce_count/doors/blastdoor
name = "MAPSTANDARDS: Tiles Must Have At Most 1 Blast Door"
checked_type = /obj/machinery/door/poddoor
failed_name = "Blast Doors"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/datum/unit_test/mapping_standards/enforce_count/lights
name = "MAPSTANDARDS: Tiles Must Have At Most 1 Light"

checked_type = /obj/machinery/light
failed_name = "Lights"

/datum/unit_test/mapping_standards/enforce_count/lights/get_collection()
return INSTANCES_OF(/obj/machinery/light)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
name = "MAPSTANDARDS: Ladders must have openspace"

/datum/unit_test/mapping_standards/ladders_must_have_openspace/Run()
if(..()) {return};
if(..())
return

for(var/obj/structure/ladder/ladder as anything in INSTANCES_OF(/obj/structure/ladder))
if(ladder.down && (!isopenspaceturf(get_turf(ladder))))
TEST_FAIL("Ladder with down linkage is not on openspace turf, at: [AREACOORD(ladder)]")
15 changes: 15 additions & 0 deletions code/modules/unit_tests/mapping_standards/no_renamed_areas.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/datum/unit_test/mapping_standards/no_renamed_areas
name = "MAPSTANDARDS: Areas must not be renamed"

var/list/area/exempt_areas = list(
//None
)

/datum/unit_test/mapping_standards/no_renamed_areas/Run()
if(..())
return

for(var/area/area in GLOB.areas)
if(!(area.type in exempt_areas) && (area.name != initial(area.name)))
// Unique areas might be worth exempting here? But at the same time, there's no throws here with no check. -Francinum
TEST_FAIL("Area [area]/([initial(area.name)]) at [AREACOORD(area.contents[1])] (Unique: [BOOLEAN(area.area_flags & UNIQUE_AREA)]) has been renamed. ")
29 changes: 0 additions & 29 deletions code/modules/unit_tests/mapping_standards/one_light_per_tile.dm

This file was deleted.

0 comments on commit 6bb8e09

Please sign in to comment.