Your first test is a good start. Maybe think about error checking: is there a return code from add, to tell that it did work or not ? Or is it supposed to throw an exception if something goes wrong ?
Preferred approach
Knowing that you'll need a method has_component() for the Entity class, just add it to the class definition, with a stub implementation that always return false (and a big comment // TO DO !!).
Your next test would then be:
assert(! e.has_component(c) );
e.add(c);
assert(e.has_component(c)); // or return FAIL to your test framework.
The principleprinciple is that your test will fail until both functions are correct.
What are the alternatives
- use a simpler member, such as
number_of_components()to check that you're on the right track (i.e. number increases when adding a new component; number remains same when adding same component twice). - let the test code inspect the internals of your
Entity. I don't like this approach, because it breaks the rules of encapsulation. - make a a test double that provides emulated/simulated answer for
has_component(). Would it be a very complex feature, this would be the way to go. But for simple features like here, this might be overkill. - if you'd have a dispatching function that forwards calls from
EntitytoComponentsyou could use it to check if c reacts.