mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-18 02:24:11 +01:00
Add unit-tests for card decks (#24791)
* Add unit-tests for card decks * Fix linter CI comments * Rename unit-test file due to duplicate filename * Fix review comments * Fix unit-test broken after review comment fixing * Remove blank unit-tests for card-decks * Use TRUE instead of magic-value 1 in cardshuffle sound call Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com> --------- Co-authored-by: Burzah <116982774+Burzah@users.noreply.github.com>
This commit is contained in:
@@ -50,10 +50,16 @@
|
||||
|
||||
/obj/item/deck/Initialize(mapload)
|
||||
. = ..()
|
||||
build_decks()
|
||||
update_icon(UPDATE_ICON_STATE)
|
||||
|
||||
/obj/item/deck/proc/build_decks()
|
||||
if(length(cards))
|
||||
// prevent building decks more than once
|
||||
return
|
||||
for(var/deck in 1 to deck_size)
|
||||
build_deck()
|
||||
deck_total = length(cards)
|
||||
update_icon(UPDATE_ICON_STATE)
|
||||
|
||||
/obj/item/deck/proc/build_deck()
|
||||
return
|
||||
@@ -227,8 +233,10 @@
|
||||
var/mob/living/user = usr
|
||||
if(cooldown < world.time - 1 SECONDS)
|
||||
cards = shuffle(cards)
|
||||
user.visible_message("<span class='notice'>[user] shuffles [src].</span>")
|
||||
playsound(user, 'sound/items/cardshuffle.ogg', 50, 1)
|
||||
|
||||
if(user)
|
||||
user.visible_message("<span class='notice'>[user] shuffles [src].</span>")
|
||||
playsound(user, 'sound/items/cardshuffle.ogg', 50, TRUE)
|
||||
cooldown = world.time
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//Keep this sorted alphabetically
|
||||
|
||||
#ifdef UNIT_TESTS
|
||||
#include "games\test_cards.dm"
|
||||
#include "jobs\test_job_globals.dm"
|
||||
#include "aicard_icons.dm"
|
||||
#include "announcements.dm"
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/datum/unit_test/card_deck/proc/validate_deck(obj/item/deck/deck)
|
||||
var/list/card_count = list()
|
||||
for(var/datum/playingcard/card in deck.cards)
|
||||
if(card_count[card.name] == null)
|
||||
card_count[card.name] = 1
|
||||
else if(card.name == "Joker")
|
||||
card_count[card.name]++
|
||||
else
|
||||
// duplicate card in deck
|
||||
return FALSE
|
||||
|
||||
if(length(card_count) != 53) // 2 Jokers, so 53 unique cards
|
||||
return FALSE
|
||||
return TRUE
|
||||
|
||||
|
||||
/datum/unit_test/card_deck/Run()
|
||||
// setup
|
||||
var/loc = pick(block(run_loc_bottom_left, run_loc_top_right))
|
||||
var/obj/item/deck/cards/cards = new /obj/item/deck/cards(loc)
|
||||
cards.build_decks()
|
||||
|
||||
// is deck proper upon spawning
|
||||
if(!validate_deck(cards))
|
||||
Fail("52 card deck not initialized correctly.")
|
||||
|
||||
// is deck proper after shuffling
|
||||
cards.deckshuffle()
|
||||
if(!validate_deck(cards))
|
||||
Fail("52 card deck broken after shuffling.")
|
||||
Reference in New Issue
Block a user