Control flow graph example

De Software testing
Ir para: navegação, pesquisa

Example 0

public boolean validateIdentifier(String s) {
		char achar;
/ 1 /		boolean validId = false;
/ 1 /		if (s.length() > 0) {
/ 2 /			achar = s.charAt(0);
/ 2 /			validId = validS(achar);
/ 2 /			if (s.length() > 1) {
/ 3 /				achar = s.charAt(1);
/ 3 /				int i = 1;
/ 4 /				while (i < s.length()  1) {
/ 5 /					achar = s.charAt(i);
/ 5 /					if (! validF(achar))
/ 6 /						validId = false ;
/ 7 /					i++;
				}
			}
		}
/ 8, 9, 10 /	if (validId && (s.length() >= 1) && (s.length() < 6))
/ 11 /		return true;
		else
/ 12 /		return false ;
}

ControlFlowGraph-Identifier-validateIdentifier.png


Example 1

Source code

q = 1;
b = 2;
c = 3;
if (a ==2) {
   x = x + 2;
}  else {
   x = x / 2;
}
p = q / r;
if (b/c>3) {
   z = x + y;
}


Control flow graph

Control flow graph - Example 1.svg


References

  • <bib>copeland:2004</bib>