Beginning C# Programming with MonoGame by Chamillard A.T

Beginning C# Programming with MonoGame by Chamillard A.T

Author:Chamillard, A.T. [Chamillard, A.T.]
Language: eng
Format: mobi
Publisher: Burning Teddy
Published: 2015-11-15T16:00:00+00:00


Figure 12.5. Die UML Diagram

Since we've now finished our UML diagram, we're ready to move on to our test plan.

Write Test Cases

We need to make sure our test plan covers both constructors, the TopSide and NumSides properties, and the Roll method. We don't have any selection or iteration constructs in any of this, so we could do all the testing in a single test case, but let's do one test case for the default six-sided die and another for a 256-sided die. For each of the test cases, we'll get the top side and the number of sides right after creating the die, then roll the die 3 times and print the resulting top side of the die after each roll. These test cases are really unit test cases since we’re testing a single class rather than functional test cases.

Test Case 1

Checking 6-Sided Die

Step 1. Input: None. Hard-coded steps in the test case code

Expected Result:

Top Side: 1

Num Sides: 6

Top Side: appropriate

Top Side: appropriate

Top Side: appropriate

Notice that we have a new problem here because we’re trying to test a program that uses random numbers. How are we going to tell whether or not the top side is correct after each roll? This is actually a really hard problem to solve. At this point, we’ll just confirm that the rolls “look random”, though we recognize this is an imperfect approach. We’ll discuss this further at the end of the chapter.

Here's the other test case:

Test Case 2

Checking 256-Sided Die

Step 1. Input: None. Hard-coded steps in the test case code

Expected Result:

Top Side: 1

Num Sides: 256

Top Side: appropriate

Top Side: appropriate

Top Side: appropriate

Write the Code

Let's write the constructor that doesn't have any parameters and the TopSide and NumSides properties and test those out before writing the Roll method. Our initial code is in Figure 12.6.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.