How to do Table Test for a particular algorithm?

Asked

Viewed 4,751 times

4

I have this algorithm, in a pseudocode:

Knowing that n1 receives 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) from n1*3(20 times 3)

How to do a Table Test to find the result of this algorithm above?

  • 6

    en.slideshare.net/mobile/henriquecarmona/aula-4-teste-de-mesa

2 answers

8

Each adopts its own technique of doing the table test. I will describe more or less how I do.

I create a table with the declared variables, each in a column. Each row in the column will serve to annotate the new variable value whenever there is a reassignment. Some people like to scratch the previous value to avoid confusion and only make visible the same last, which is what counts.

It is also possible to have columns for sub-expressions, which can help find errors in them.

Then from the third line I start the annotation in a column of n1. I’ll write down a number I wish to test.

I then note the result of the calculation of the n1 (is always the last value available in the column) times 3.

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

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

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

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

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

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

Some people like to create a data line for each line or sub-expression executed by copying the previous data. I think exaggeration, but it can be useful in some cases. I only do something when the state changes.

Tools of debug existing powerful today have almost abolished the use of table test on the same table :)

  • @bigown and we must remember, if my algorithm were more complex, I would make use of precedence in mathematical operations, just as the division takes precedence over the sum.

  • 4

    I thought about talking about it, but I thought it would be too much, maybe I’ll write something later, now I’ll go back to my baseball :D

3

Problem solving:

Knowing that n1 receives the amount 20, I did the assignment, that way:


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

Row n1 N2 N3 summing up Subtraction Product
3 20 ? ? ? ? ?
4 20 ? ? ? ? 60
5 20 60 ? 79 19 ?
6 20 60 79 ? ? ?

See according to the values assignment and with the algorithm resolution I found the result.

I did this Table Test based on this link.

  • In column (Subtraction) line 5, the correct would not be to inform -1, since 19 would be part of the result of line 5? I imagine that the form that was placed may generate doubt.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.