1 #include <random> 2 3 #include "catch.hpp" 4 5 #include "AppHdr.h" 6 7 #include "randbook.h" 8 #include "spl-book.h" 9 #include "spl-util.h" 10 11 TEST_CASE( "When setting book spell list", "[single-file]" ) { 12 13 item_def book; 14 15 SECTION("spells will be padded with SPELL_NO_SPELL") { 16 init_spell_descs(); 17 vector<spell_type> spells = {SPELL_MAGIC_DART, SPELL_CAUSE_FEAR}; 18 19 _set_book_spell_list(book, spells); 20 21 const auto& book_spells = book.props[SPELL_LIST_KEY].get_vector(); 22 REQUIRE(book_spells.size() == RANDBOOK_SIZE); 23 for (auto i = 2; i < RANDBOOK_SIZE; i++ ) 24 REQUIRE(book_spells[i].get_int() == SPELL_NO_SPELL); 25 } 26 27 SECTION("the spell list will be truncated to RANDBOOK_SIZE entries") { 28 init_spell_descs(); 29 vector<spell_type> spells = { 30 SPELL_FREEZE, 31 SPELL_ANIMATE_SKELETON, 32 SPELL_APPORTATION, 33 SPELL_SUMMON_SMALL_MAMMAL, 34 SPELL_MAGIC_DART, 35 SPELL_SHOCK, 36 SPELL_SANDBLAST, 37 SPELL_FOXFIRE, 38 SPELL_CORONA, 39 SPELL_BEASTLY_APPENDAGE, 40 SPELL_PAIN, 41 SPELL_STING, 42 }; 43 44 _set_book_spell_list(book, spells); 45 46 const auto& book_spells = book.props[SPELL_LIST_KEY].get_vector(); 47 REQUIRE(book_spells.size() == RANDBOOK_SIZE); 48 } 49 } 50