How to do table test for certain algorithm?

I have this algorithm, in a pseudocode:

Knowing that n1 gets the value 20.

inicio 
inteiro: n1,n2,n3; 
leia (n1); 
n2<-n1*3; 
n3<-n1-1+n2; 
imprima("O resultado final será n3=",n3); 
fim. 

Exemplifying:

N2 (receives result) of n1 * 3 (20 times 3)

How to do a table test to find the result of this algorithm above?

Author: Maniero, 2016-06-22

2 answers

Each one adopts its own technique of doing the table test. I'll describe more or less how I do it.

I create a table with the declared variables, each in a column. Each row of the column will be used to note the new value of the variable whenever there is a new assignment . Some people like to cross out the previous value to avoid confusion and only leave the last one visible, which is what it is worth.

It is also possible to have columns for subexpressions, which it can help to find mistakes in them.

Then from the third row I start the annotation ma column of n1. I'm going to write down a value that I want to test.

Then I write down the result of calculating the value of n1 (it is always the last available value in the column) times 3.

Then I do the same by taking the last value of n1 minus 1 plus the last value of n2.

Then note separately what should appear on the screen (a page only for screen demonstration), in the case O resultado final será n3= and the last value of n3.

If it were something more complex it would continue. If I had a loop I would keep the notes.

I would test with several values, with 0, positive, negative, some high numbers, I would try for a text, finally I would try to create situations that cause error in the algorithm.

To make an easy table test it is important the algorithm is not too big.

In some cases there may be some specifics of how to proceed.

Some people like to create a row of data for each row or subexpression executed by copying the previous data. I think it's overkill, but it can be useful in some cases. I only do something when the state changes.

Powerful tools debug existing today almost abolished the use of desktop testing on the same desktop:)

 7
Author: Maniero, 2020-01-24 11:50:21

Problem Resolution:

Knowing that n1 gets the value 20, I did the assignment, like this:


inicio               
inteiro: n1,n2,n3;   //Declaração de Variáveis
leia (n1);           //Entrada de Dados
n2 <-20*3            //Processamento    
n3 <-20-1+60         //Processamento 
imprima("O resultado final será n3=",n3); // Saida

The result will be: 79


Table Test

  | Linha | n1 | n2 | n3 | soma | Subtração |    Produto    | 
  |   3   | 20 | ?  | ?  |  ?   |     ?     |       ?       | 
  |   4   | 20 | ?  | ?  |  ?   |     ?     |       60      |   
  |   5   | 20 | 60 | ?  |  79  |     19    |       ?       | 
  |   6   | 20 | 60 | 79 |  ?   |     ?     |       ?       |  

See as the assignment of the values and with the resolution of the algorithm found the result.

I did this table test based on this Link.

 3
Author: , 2016-06-22 02:19:17