Back

Punto Banco testing - 7

There are many different paths through this program. Although it runs, does it run correctly through every possible set of cards that are dealt? We could set the program off to run 10000 games and then check each one. That would probably do the trick but isn't very practical. What we need to do is to try to think of a test that tests each possible path through the code. This is known as 'white box testing' or 'glass box testing' because you are designing tests based on the fact that you can examine the code when designing what tests to do. 

We should set up a table and then look at our code, trying to work out the typical different paths through it. We should say what we are testing, predict the outcome and only then, run the test. When we pick values to use, we should pick a typical value that produces a TRUE result, one that produces a FALSE result and one on the border of the test. for example, if we had a test (VALUE < 8) in our program, we might pick VALUE = 4, as this will result in TRUE, VALUE = 15 as this will result in FALSE and VALUE = 8 as this is a borderline value and in this case will also result in FALSE.

Q1. Look at the code. Plan out as many tests as you think you need, so that all the paths through the code are tested.

Test Description Prediction

Actual

1 playertotal = 3, should get a card. Player gets card  
2 playertotal = 9, should not get a card. No card  
3 playertotal = 6, should not get a card. No card  
4 banktotal = 2, playerTotal = 8, bank should get a card. Bank gets card  
5 bankTotal = 3, playerTotal = 8, bank should not get a card. No card  
6 bankTotal = 3, playerTotal = 3, bank should get a card. Bank gets card  
7      
8      
9      
10      
11      
12      
13      
14      
15      

Once we have a plan, the next job is to run the tests. To do this, we are going to 'comment out' parts of our code and insert the value that we actually want. In Python's Idle, you can comment out code by highlighting in and then going to the Format menu, or use ALT + 3 (and ALT + 4 to remove the commenting out). Commenting out code is a really useful too in programming. You can disable code temporarily while you do some testing or investigate a problem, and then put it back in again when you are ready. This technique is widely used to find errors as you can start to isolate where a problem is happening. Before you start making any changes to your code, however, ALWAYS BACK-UP YOUR PROGRAM before you start. Should you make too many changes, or make a mistake, you must always be able to go back to the original program.

Q2. Look at the code below. You can see that the program no longer works out the total from the cards dealt to the player. I added an extra line to force the playerTotal to be 3. Modify part of your program as shown below. Then carry out the tests for the playerTotal in your table. Record your results.

punto7
Q3. When you have completed the playerTotal tests, you need to test whether the bank has to have a third card. You need to comment out a little bit more code and force bankTotal to be what you want. Make the necessary changes and then run the tests for bankTotal. When you have finished, make sure you put the program back as it was before.

Back