The 6-Sided die must conform to a standard dice protocol. In other words, it must be able to be tossed (to cause a new face value to appear at the top of the die). It must be able to report the current top face value. It must also be able to report the number of sides (even though our Die object will always have 6 sides, we must exist in a world where multi-sided dice are available).
To exercise our Die object, we will be using a second object, a DieCounter. DieCounters work with a Die object and toss it a number of times, tracking the number of times each face appears on top. A DieCounter will be able to report the number of time each face appears. Note that even though a DieCounter has no special knowledge of our specialize 6 sided die, it is able to use it through the standard Die inteface of top/toss/sides.
Not all languages require an explicit interface (e.g. Python and SmallTalk). Some languages treat interfaces differently than classes (e.g. Java). Others treat interfaces as normal classes, except that all methods are abstract (e.g. C++ and Eiffel).
(see also: Eiffel short form)
- int top ()
- Return the current top face of the die object. Valid face values are between 1 and sides() inclusive.
- int sides ()
- Return the number of sides for this die object. Must be greater than 1.
- void toss ()
- Toss the die, causing a (potentially) new face value to appear on the top of the die. New face values should be randomly chosen (although a particular random distribution is not required).
(see also: Eiffel short form)
- int top ()
- Return the current top face of the die object. Valid face values are between 1 and sides() inclusive.
- int sides ()
- Return the number of sides for this die object. In our case, we always return 6.
- void toss ()
- Toss the die, causing a (potentially) new face value to appear on the top of the die. New face values will be uniformly distributed between 1 and the number of sides (inclusive).
(see also: Eiffel short form)
- Die CountedDie ()
- Return the Die object under test.
- int maxFace ()
- Return the maximum number of faces used by the Die object under test.
- int countFor (int faceValue)
- Return the number of times faceValue appeared in the test.
- int[] counts ()
- Return an array describing the number of counts for each face value.
- int throws ()
- Return the number of times the die under test has been thrown in the current sequence of tests.
- void setDie (Die d)
- Use die d in running the face counting tests. A reset is automatically performed when changing dice.
- void reset ()
- Reset all count statistics in the current DieCounter. Start a new sequence of tests.
- void run (int times)
- Toss the die times times and record the result of each throw. throws() will be incremented by times.
|