Uploading all files.

This commit is contained in:
Quotefox
2019-09-23 18:26:34 +02:00
commit 7091cdbe8c
7779 changed files with 2601004 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
//include unit test files in this module in this ifdef
//Keep this sorted alphabetically
#ifdef UNIT_TESTS
#include "reagent_id_typos.dm"
#include "reagent_recipe_collisions.dm"
#include "spawn_humans.dm"
#include "subsystem_init.dm"
#include "timer_sanity.dm"
#include "unit_test.dm"
#endif
@@ -0,0 +1,14 @@
/datum/unit_test/reagent_id_typos
/datum/unit_test/reagent_id_typos/Run()
build_chemical_reactions_list()
build_chemical_reagent_list()
for(var/I in GLOB.chemical_reactions_list)
for(var/V in GLOB.chemical_reactions_list[I])
var/datum/chemical_reaction/R = V
for(var/id in (R.required_reagents + R.required_catalysts))
if(!GLOB.chemical_reagents_list[id])
Fail("Unknown chemical id \"[id]\" in recipe [R.type]")
@@ -0,0 +1,15 @@
/datum/unit_test/reagent_recipe_collisions
/datum/unit_test/reagent_recipe_collisions/Run()
build_chemical_reactions_list()
var/list/reactions = list()
for(var/V in GLOB.chemical_reactions_list)
reactions += GLOB.chemical_reactions_list[V]
for(var/i in 1 to (reactions.len-1))
for(var/i2 in (i+1) to reactions.len)
var/datum/chemical_reaction/r1 = reactions[i]
var/datum/chemical_reaction/r2 = reactions[i2]
if(chem_recipes_do_conflict(r1, r2))
Fail("Chemical recipe conflict between [r1.type] and [r2.type]")
+7
View File
@@ -0,0 +1,7 @@
/datum/unit_test/spawn_humans/Run()
var/locs = block(run_loc_bottom_left, run_loc_top_right)
for(var/I in 1 to 5)
new /mob/living/carbon/human(pick(locs))
sleep(50)
@@ -0,0 +1,7 @@
/datum/unit_test/subsystem_init/Run()
for(var/i in Master.subsystems)
var/datum/controller/subsystem/ss = i
if(ss.flags & SS_NO_INIT)
continue
if(!ss.initialized)
Fail("[ss]([ss.type]) is a subsystem meant to initialize but doesn't get set as initialized.")
+3
View File
@@ -0,0 +1,3 @@
/datum/unit_test/timer_sanity/Run()
if(SStimer.bucket_count < 0)
Fail("SStimer is going into negative bucket count from something")
+77
View File
@@ -0,0 +1,77 @@
/*
Usage:
Override /Run() to run your test code
Call Fail() to fail the test (You should specify a reason)
You may use /New() and /Destroy() for setup/teardown respectively
You can use the run_loc_bottom_left and run_loc_top_right to get turfs for testing
*/
GLOBAL_DATUM(current_test, /datum/unit_test)
GLOBAL_VAR_INIT(failed_any_test, FALSE)
GLOBAL_VAR(test_log)
/datum/unit_test
//Bit of metadata for the future maybe
var/list/procs_tested
//usable vars
var/turf/run_loc_bottom_left
var/turf/run_loc_top_right
//internal shit
var/succeeded = TRUE
var/list/fail_reasons
/datum/unit_test/New()
run_loc_bottom_left = locate(1, 1, 1)
run_loc_top_right = locate(5, 5, 1)
/datum/unit_test/Destroy()
//clear the test area
for(var/atom/movable/AM in block(run_loc_bottom_left, run_loc_top_right))
qdel(AM)
return ..()
/datum/unit_test/proc/Run()
Fail("Run() called parent or not implemented")
/datum/unit_test/proc/Fail(reason = "No reason")
succeeded = FALSE
if(!istext(reason))
reason = "FORMATTED: [reason != null ? reason : "NULL"]"
LAZYADD(fail_reasons, reason)
/proc/RunUnitTests()
CHECK_TICK
for(var/I in subtypesof(/datum/unit_test))
var/datum/unit_test/test = new I
GLOB.current_test = test
var/duration = REALTIMEOFDAY
test.Run()
duration = REALTIMEOFDAY - duration
GLOB.current_test = null
GLOB.failed_any_test |= !test.succeeded
var/list/log_entry = list("[test.succeeded ? "PASS" : "FAIL"]: [I] [duration / 10]s")
var/list/fail_reasons = test.fail_reasons
qdel(test)
for(var/J in 1 to LAZYLEN(fail_reasons))
log_entry += "\tREASON #[J]: [fail_reasons[J]]"
log_test(log_entry.Join("\n"))
CHECK_TICK
SSticker.force_ending = TRUE
+218
View File
@@ -0,0 +1,218 @@
/datum/unit_test
var/static/default_mobloc = null
/datum/unit_test/proc/create_test_mob(var/turf/mobloc = null, var/mobtype = /mob/living/carbon/human, var/with_mind = FALSE)
if(isnull(mobloc))
if(!default_mobloc)
for(var/turf/simulated/floor/tiled/T in world)
var/pressure = T.zone.air.return_pressure()
if(90 < pressure && pressure < 120) // Find a turf between 90 and 120
default_mobloc = T
break
mobloc = default_mobloc
if(!mobloc)
Fail("Unable to find a location to create test mob")
return FALSE
var/mob/living/carbon/human/H = new mobtype(mobloc)
if(with_mind)
H.mind_initialize("TestKey[rand(0,10000)]")
return H
/datum/unit_test/space_suffocation
name = "MOB: human mob suffocates in space"
var/startOxyloss
var/endOxyloss
var/mob/living/carbon/human/H
async = 1
/datum/unit_test/space_suffocation/Run()
var/turf/open/space/T = locate()
H = new(T)
startOxyloss = H.getOxyLoss()
return 1
/datum/unit_test/space_suffocation/check_result()
if(H.life_tick < 10)
return 0
endOxyloss = H.getOxyLoss()
if(!startOxyloss < endOxyloss)
Fail("Human mob is not taking oxygen damage in space. (Before: [startOxyloss]; after: [endOxyloss])")
qdel(H)
return 1
/datum/unit_test/belly_nonsuffocation
name = "MOB: human mob does not suffocate in a belly"
var/startLifeTick
var/startOxyloss
var/endOxyloss
var/mob/living/carbon/human/pred
var/mob/living/carbon/human/prey
/datum/unit_test/belly_nonsuffocation/Run()
pred = create_test_mob()
if(!istype(pred))
return FALSE
prey = create_test_mob(pred.loc)
if(!istype(prey))
return FALSE
return TRUE
/datum/unit_test/belly_nonsuffocation/check_result()
// Unfortuantely we need to wait for the pred's belly to initialize. (Currently after a spawn())
if(!pred.vore_organs || !pred.vore_organs.len)
return FALSE
// Now that pred belly exists, we can eat the prey.
if(!pred.vore_selected)
Fail("[pred] has no vore_selected.")
return TRUE
// Attempt to eat the prey
if(prey.loc != pred.vore_selected)
pred.vore_selected.nom_mob(prey)
if(prey.loc != pred.vore_selected)
Fail("[pred.vore_selected].nom_mob([prey]) did not put prey inside [pred]")
return TRUE
// Okay, we succeeded in eating them, now lets wait a bit
startLifeTick = pred.life_tick
startOxyloss = prey.getOxyLoss()
return FALSE
if(pred.life_tick < (startLifeTick + 10))
return FALSE // Wait for them to breathe a few times
// Alright lets check it!
endOxyloss = prey.getOxyLoss()
if(startOxyloss < endOxyloss)
Fail("Prey takes oxygen damage in a pred's belly! (Before: [startOxyloss]; after: [endOxyloss])")
qdel(prey)
qdel(pred)
return TRUE
////////////////////////////////////////////////////////////////
/datum/unit_test/belly_spacesafe
name = "MOB: human mob protected from space in a belly"
var/startLifeTick
var/startOxyloss
var/startBruteloss
var/endOxyloss
var/endBruteloss
var/mob/living/carbon/human/pred
var/mob/living/carbon/human/prey
/datum/unit_test/belly_spacesafe/Run()
pred = create_test_mob()
if(!istype(pred))
return FALSE
prey = create_test_mob(pred.loc)
if(!istype(prey))
return FALSE
return TRUE
/datum/unit_test/belly_spacesafe/check_result()
// Unfortuantely we need to wait for the pred's belly to initialize. (Currently after a spawn())
if(!pred.vore_organs || !pred.vore_organs.len)
return FALSE
// Now that pred belly exists, we can eat the prey.
if(!pred.vore_selected)
Fail("[pred] has no vore_selected.")
return TRUE
// Attempt to eat the prey
if(prey.loc != pred.vore_selected)
pred.vore_selected.nom_mob(prey)
if(prey.loc != pred.vore_selected)
Fail("[pred.vore_selected].nom_mob([prey]) did not put prey inside [pred]")
return TRUE
else
var/turf/T = locate(/turf/open/space)
if(!T)
Fail("could not find a space turf for testing")
return TRUE
else
pred.forceMove(T)
// Okay, we succeeded in eating them, now lets wait a bit
startLifeTick = pred.life_tick
startOxyloss = prey.getOxyLoss()
startBruteloss = prey.getBruteloss()
return FALSE
if(pred.life_tick < (startLifeTick + 10))
return FALSE // Wait for them to breathe a few times
// Alright lets check it!
endOxyloss = prey.getOxyLoss()
endBruteloss = prey.getBruteLoss()
if(startBruteloss < endBruteloss)
Fail("Prey takes brute damage in space! (Before: [startBruteloss]; after: [endBruteloss])")
qdel(prey)
qdel(pred)
return TRUE
////////////////////////////////////////////////////////////////
/datum/unit_test/belly_damage
name = "MOB: human mob takes damage from digestion"
var/startLifeTick
var/startBruteBurn
var/endBruteBurn
var/mob/living/carbon/human/pred
var/mob/living/carbon/human/prey
/datum/unit_test/belly_damage/Run()
pred = create_test_mob()
if(!istype(pred))
return FALSE
prey = create_test_mob(pred.loc)
if(!istype(prey))
return FALSE
return TRUE
/datum/unit_test/belly_damage/check_result()
// Unfortuantely we need to wait for the pred's belly to initialize. (Currently after a spawn())
if(!pred.vore_organs || !pred.vore_organs.len)
return FALSE
// Now that pred belly exists, we can eat the prey.
if(!pred.vore_selected)
Fail("[pred] has no vore_selected.")
return TRUE
// Attempt to eat the prey
if(prey.loc != pred.vore_selected)
pred.vore_selected.nom_mob(prey)
if(prey.loc != pred.vore_selected)
Fail("[pred.vore_selected].nom_mob([prey]) did not put prey inside [pred]")
return TRUE
// Okay, we succeeded in eating them, now lets wait a bit
pred.vore_selected.digest_mode = DM_DIGEST
startLifeTick = pred.life_tick
startBruteBurn = prey.getBruteLoss() + prey.getFireLoss()
return FALSE
if(pred.life_tick < (startLifeTick + 10))
return FALSE // Wait a few ticks for damage to happen
// Alright lets check it!
endBruteBurn = prey.getBruteLoss() + prey.getFireLoss()
if(startBruteBurn >= endBruteBurn)
Fail("Prey doesn't take damage in digesting belly! (Before: [startBruteBurn]; after: [endBruteBurn])")
qdel(prey)
qdel(pred)
return TRUE