[ogs-changes] dist/c++/test CreatureTest.cpp,NONE,1.1 AbilitiesTest.cpp,1.2,1.3 DieTest.cpp,1.1,1.2
Status: Alpha
Brought to you by:
elemings
From: <ele...@us...> - 2003-04-15 16:59:29
|
Update of /cvsroot/ogs/dist/c++/test In directory sc8-pr-cvs1:/tmp/cvs-serv20206/c++/test Modified Files: AbilitiesTest.cpp DieTest.cpp Makefile.am ModifiersTest.cpp SupportTest.cpp Added Files: CreatureTest.cpp Log Message: See C++ ChangeLog (Apr 15) for details. --- NEW FILE: CreatureTest.cpp --- /* * CreatureTest.cpp -- test driver for creatures * Copyright (C) 2003 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA * * RCS: $Id: CreatureTest.cpp,v 1.1 2003/04/15 16:58:52 elemings Exp $ */ // Need to add configure checks before using <mcheck.h> and mtrace(). //#include <mcheck.h> #include <cassert> #include <cstdlib> #include <ctime> #include <iostream> #include <sstream> #include <ogs/Core.h> #include <ogs/Creatures.h> #include <ogs/Skills.h> using std::cout; using std::endl; using namespace ogs::core; using namespace ogs::core::details; using namespace ogs::creatures; using namespace ogs::skills; #define TEST_DRIVER "CreatureTest" // NOTE: Some of the following functions should be considered for // integration into the library (after a few minor changes). /** * Format a string using conventional die notation for this die. The * conventional die notation is "NdT+M" where N is the roll count, * T is the die sides, and M is the total modifier. The total modifier * may be omitted if it is zero (0). * * @return Formatted die notation string. */ std::string formatDieNotation (const Die& die) { std::ostringstream ostr; ostr << die.getCount (); ostr << "d" << die.getSides (); if (die.getModifier () != 0) { ostr << std::showpos << die.getModifier (); } return (ostr.str ()); } const char* getAbilityAbbreviation (Ability::Type abilityType) { switch (abilityType) { case Ability::STR: return ("Str"); case Ability::DEX: return ("Dex"); case Ability::CON: return ("Con"); case Ability::INT: return ("Int"); case Ability::WIS: return ("Wis"); case Ability::CHA: return ("Cha"); default: return (""); } } void printAbilities (Abilities& abilities) { Abilities::Iterator itor = abilities.getBegin (); cout << "Abilities: "; while (itor != abilities.getEnd ()) { Abilities::Value& value = *itor++; cout << getAbilityAbbreviation (value.first) << " " << (value.second)->getCurrentScore () << " (" << ((value.second)->getModifier ()).getValue () << ")"; if (itor != abilities.getEnd ()) { cout << ", "; } } cout << endl; } /** * Determine the name of a skill type. This function returns an empty * string if the type of skill is unknown. (This is really just a big * map and should be implemented as such.) * * @param skillType A type of common skill. * @return Name of the skill type or an empty string. */ const char* getSkillName (Skill::Type skillType) { switch (skillType) { case CommonSkills::APPRAISE: return ("Appraise"); case CommonSkills::BLUFF: return ("Bluff"); case CommonSkills::CLIMB: return ("Climb"); case CommonSkills::CRAFT: return ("Craft"); case CommonSkills::DIPLOMACY: return ("Diplomacy"); case CommonSkills::DISABLE_DEVICE: return ("Disable Device"); case CommonSkills::DISGUISE: return ("Disguise"); case CommonSkills::ESCAPE_ARTIST: return ("Escape Artist"); case CommonSkills::FORGERY: return ("Forgery"); case CommonSkills::GATHER_INFORMATION: return ("Gather Information"); case CommonSkills::HANDLE_ANIMAL: return ("Handle Animal"); case CommonSkills::HIDE: return ("Hide"); case CommonSkills::INTIMIDATE: return ("Intimidate"); case CommonSkills::JUMP: return ("Jump"); case CommonSkills::KNOWLEDGE: return ("Knowledge"); case CommonSkills::LISTEN: return ("Listen"); case CommonSkills::MOVE_SILENTLY: return ("Move Silently"); case CommonSkills::PROFESSION: return ("Profession"); case CommonSkills::RIDE: return ("Ride"); case CommonSkills::SEARCH: return ("Search"); case CommonSkills::SENSE_MOTIVE: return ("Sense Motive"); case CommonSkills::SPEAK_LANGUAGE: return ("Speak Language"); case CommonSkills::SPOT: return ("Spot"); case CommonSkills::SWIM: return ("Swim"); case CommonSkills::TUMBLE: return ("Tumble"); default: return (""); } } void printSkills (Skills& skills) { Skills::iterator itor = skills.begin (); cout << "Skills: "; while (itor != skills.end ()) { SkillPtr skillPtr = *itor++; cout << getSkillName (skillPtr->getType ()) << " (" << (skillPtr->getModifiers ()).getValue () << ")"; if (itor != skills.end ()) { cout << ", "; } } cout << endl; } const char* getAlignmentName (const Alignment& alignment) { switch (alignment.getValue ()) { case Alignment::LAWFUL_GOOD: return ("Lawful Good"); case Alignment::NEUTRAL_GOOD: return ("Neutral Good"); case Alignment::CHAOTIC_GOOD: return ("Chaotic Good"); case Alignment::LAWFUL_NEUTRAL: return ("Lawful Neutral"); case Alignment::TRUE_NEUTRAL: return ("Neutral Neutral"); case Alignment::CHAOTIC_NEUTRAL: return ("Chaotic Neutral"); case Alignment::LAWFUL_EVIL: return ("Lawful Evil"); case Alignment::NEUTRAL_EVIL: return ("Neutral Evil"); case Alignment::CHAOTIC_EVIL: return ("Chaotic Evil"); default: return ("Unknown"); } } void printFeatures (Features& features) { Features::iterator itor = features.begin (); while (itor != features.end ()) { FeaturePtr featurePtr = *itor++; Alignment* alignment = dynamic_cast<Alignment*> (featurePtr.get ()); if (alignment != NULL) { cout << "Alignment: " << getAlignmentName (*alignment) << endl;; } Gender* gender= dynamic_cast<Gender*> (featurePtr.get ()); if (gender != NULL) { cout << "Gender: " << gender->getName () << endl; } } } void testCreature (Creature& creature) { cout << "Size: " << char ((creature.getSize ()).getType ()) << endl; cout << "Hit Dice: " << formatDieNotation (creature.getHitDice ()) << endl; cout << "Initiative: " << (creature.getInitiative ()).getValue () << endl; cout << "Defense: " << (creature.getDefense ()).getValue () << endl; const Saves& saves = creature.getSaves (); cout << "Saves: Fort " << saves.fort.getValue () << ", " << "Ref " << saves.ref.getValue () << ", " << "Will " << saves.will.getValue () << endl; printAbilities (creature.getAbilities ()); Skills skills (creature.getSkills ()); printSkills (skills); cout << "Feats: " << endl; Features features = creature.getFeatures (); printFeatures (features); cout << endl; } int main (void) { //mtrace (); cout << "BEGIN: " TEST_DRIVER "\n\n"; // Seed random number generator with current time. std::srand (std::time (NULL)); using namespace ogs::creatures::humanoids; Human human; cout << "sizeof (Human) = " << sizeof (Human) << endl; cout << "&human = " << &human << endl; human.addFeature (* (new Gender (Gender::FEMALE))); testCreature (human); //testHuman (human); using namespace ogs::creatures::undeads; Wraith wraith; cout << "sizeof (Wraith) = " << sizeof (Wraith) << endl; cout << "&wraith = " << &wraith << endl; testCreature (wraith); //testWraith (wraith); cout << "END: " TEST_DRIVER "\n"; //muntrace (); return (0); } Index: AbilitiesTest.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/test/AbilitiesTest.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AbilitiesTest.cpp 13 Apr 2003 05:31:13 -0000 1.2 --- AbilitiesTest.cpp 15 Apr 2003 16:58:51 -0000 1.3 *************** *** 1,5 **** /* * AbilitiesTest.cpp -- test driver for ability scores ! * Copyright (C) 2002 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or --- 1,5 ---- /* * AbilitiesTest.cpp -- test driver for ability scores ! * Copyright (C) 2003 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or Index: DieTest.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/test/DieTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DieTest.cpp 8 Apr 2003 21:43:17 -0000 1.1 --- DieTest.cpp 15 Apr 2003 16:58:53 -0000 1.2 *************** *** 1,5 **** /* * DieTest.cpp -- test driver for polyhedral dice ! * Copyright (C) 2002 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or --- 1,5 ---- /* * DieTest.cpp -- test driver for polyhedral dice ! * Copyright (C) 2003 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or Index: Makefile.am =================================================================== RCS file: /cvsroot/ogs/dist/c++/test/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile.am 8 Apr 2003 21:43:18 -0000 1.4 --- Makefile.am 15 Apr 2003 16:58:54 -0000 1.5 *************** *** 37,40 **** --- 37,41 ---- DieTest \ AbilitiesTest \ + CreatureTest \ CombatTest01 *************** *** 47,50 **** --- 48,53 ---- AbilitiesTest_SOURCES = \ AbilitiesTest.cpp + CreatureTest_SOURCES = \ + CreatureTest.cpp CombatTest01_SOURCES = \ CombatTest01.cpp Index: ModifiersTest.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/test/ModifiersTest.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ModifiersTest.cpp 13 Apr 2003 05:31:14 -0000 1.2 --- ModifiersTest.cpp 15 Apr 2003 16:58:54 -0000 1.3 *************** *** 1,5 **** /* * ModifiersTest.cpp -- test driver for modifiers ! * Copyright (C) 2002 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or --- 1,5 ---- /* * ModifiersTest.cpp -- test driver for modifiers ! * Copyright (C) 2003 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or Index: SupportTest.cpp =================================================================== RCS file: /cvsroot/ogs/dist/c++/test/SupportTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SupportTest.cpp 8 Apr 2003 21:43:19 -0000 1.1 --- SupportTest.cpp 15 Apr 2003 16:58:54 -0000 1.2 *************** *** 1,5 **** /* * SupportTest.cpp -- test driver for library support ! * Copyright (C) 2002 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or --- 1,5 ---- /* * SupportTest.cpp -- test driver for library support ! * Copyright (C) 2003 Eric Lemings <ele...@us...> * * This software is free software; you can redistribute it and/or *************** *** 153,171 **** */ void testEventObserver () { ! Foo foo; ! cout << "&foo = " << &foo << endl; Bar obs1; cout << "&obs1 = " << &obs1 << endl; ! foo.addObserver (obs1); Bar obs2; cout << "&obs2 = " << &obs2 << endl; ! foo.addObserver (obs2); // Trigger event. ! foo.setName ("first name"); ! foo.removeObserver (obs1); ! foo.setName ("second name"); cout << endl; --- 153,182 ---- */ void testEventObserver () { ! Foo foo1; ! cout << "&foo1 = " << &foo1 << endl; Bar obs1; cout << "&obs1 = " << &obs1 << endl; ! foo1.addObserver (obs1); Bar obs2; cout << "&obs2 = " << &obs2 << endl; ! foo1.addObserver (obs2); // Trigger event. ! foo1.setName ("first name"); ! foo1.removeObserver (obs1); ! foo1.setName ("second name"); ! ! // Check copy/assign semantics of observers. ! foo1.addObserver (obs2); ! Foo foo2 (foo1); ! cout << "&foo2 = " << &foo2 << endl; ! foo2.setName ("default copy constructor"); ! ! Foo foo3; ! cout << "&foo3 = " << &foo3 << endl; ! foo3 = foo1; ! foo3.setName ("default assignment operator"); cout << endl; |