mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 04:30:44 +01:00
[MIRROR] Fixes Ticked File Enforcement and Missing Unit Test (and makes said Unit Test Compile) (and genericizes the C&D list to the base unit test datum) [MDB IGNORE] (#23117)
* Fixes Ticked File Enforcement and Missing Unit Test (and makes said Unit Test Compile) (and genericizes the C&D list to the base unit test datum) * Updates ignores --------- Co-authored-by: san7890 <the@san7890.com> Co-authored-by: Giz <13398309+vinylspiders@users.noreply.github.com>
This commit is contained in:
@@ -1,21 +1,46 @@
|
||||
// Unit test to make sure that there are no duplicate keys when modify_fantasy_variable is called when applying fantasy bonuses.
|
||||
// Also to make sure the fantasy_modifications list is null when fantasy bonuses are removed.
|
||||
/datum/unit_test/modify_fantasy_variable/Run()
|
||||
/datum/unit_test/modify_fantasy_variable
|
||||
priority = TEST_LONGER
|
||||
|
||||
for(var/obj/item/path as anything in subtypesof(/obj/item))
|
||||
/datum/unit_test/modify_fantasy_variable/Run()
|
||||
var/list/applicable_types = subtypesof(/obj/item) - uncreatables
|
||||
|
||||
for(var/obj/item/path as anything in applicable_types)
|
||||
var/obj/item/object = allocate(path)
|
||||
// objects will have fantasy bonuses inherent to their type (like butterdogs and the slippery component), so we need to take this into account
|
||||
var/number_of_extant_bonuses = LAZYLEN(object.fantasy_modifications)
|
||||
|
||||
#define TEST_SUCCESS LAZYLEN(object.fantasy_modifications) == number_of_extant_bonuses
|
||||
|
||||
// Try positive
|
||||
object.apply_fantasy_bonuses(bonus = 5)
|
||||
object.remove_fantasy_bonuses(bonus = 5)
|
||||
TEST_ASSERT_NULL(object.fantasy_modifications)
|
||||
TEST_ASSERT(TEST_SUCCESS, generate_failure_message(object))
|
||||
|
||||
// Then negative
|
||||
object.apply_fantasy_bonuses(bonus = -5)
|
||||
object.remove_fantasy_bonuses(bonus = -5)
|
||||
TEST_ASSERT_NULL(object.fantasy_modifications)
|
||||
TEST_ASSERT(TEST_SUCCESS, generate_failure_message(object))
|
||||
|
||||
// Now try the extremes of each
|
||||
object.apply_fantasy_bonuses(bonus = 500)
|
||||
object.remove_fantasy_bonuses(bonus = 500)
|
||||
TEST_ASSERT_NULL(object.fantasy_modifications)
|
||||
TEST_ASSERT(TEST_SUCCESS, generate_failure_message(object))
|
||||
|
||||
object.apply_fantasy_bonuses(bonus = -500)
|
||||
object.remove_fantasy_bonuses(bonus = -500)
|
||||
TEST_ASSERT_NULL(object.fantasy_modifications)
|
||||
TEST_ASSERT(TEST_SUCCESS, generate_failure_message(object))
|
||||
|
||||
/// Returns a string that we use to describe the failure of the test.
|
||||
/datum/unit_test/modify_fantasy_variable/proc/generate_failure_message(obj/item/failed_object)
|
||||
var/list/cached_modifications = failed_object.fantasy_modifications
|
||||
var/length_of_modifications = LAZYLEN(cached_modifications)
|
||||
var/list/failure_messages = list("Error found when adding+removing fantasy bonuses for [failed_object.type].")
|
||||
failure_messages += "The length of the fantasy_modifications list was [length_of_modifications]."
|
||||
if(length_of_modifications)
|
||||
failure_messages += "The fantasy_modifications list was [cached_modifications.Join(", ")]."
|
||||
|
||||
return failure_messages.Join(" ")
|
||||
|
||||
#undef TEST_SUCCESS
|
||||
|
||||
Reference in New Issue
Block a user