Jump to content

Simple fault finding

- - - - -

  • Please log in to reply
10 replies to this topic

#1
Kenneth77

Kenneth77

    Newbie

  • Members
  • Pip
  • 5 posts
Hey all,

i am not a programmer!! but the course i do involves abit of programming (java). any help on below questions (highlighted in Yellow) will be appearcaited...

For Q1 - is the answer "Y" is the biggest???

For Q2 - apart from missing the "else statment" i can't spot any other faults - Please help!!!

For Q3 - Is MCDC (Multiple condition and decision coverage) most adequate?? it requires to illurstate the anware with some coding explanation

Many many thanks in advance

Q1 - Consider the following code (in Java) which accepts 3 integers x, y and z as input and output whether x, y, or z is the biggest.


if (x>y){
if (x>z){
System.out.println("x is the greatest");
}
else {
System.out.println("z is the greatest");
}
}
else{
if (y>z){
System.out.println("y is the greatest");
}
}



Q2- What is the fault?
ii)Q3 - Which white box coverage criterion will you adopt to reveal this type of fault? You should define the criterion and explain your choice. (note: you should choose a coverage criterion which can always generate a test set to detect the fault but requires the fewest number of test cases)

#2
Metalhead

Metalhead

    Newbie

  • Members
  • PipPip
  • 27 posts
The first is not a question, it is only information, whatever the code prints depends on the input-values z, y and z.

2. y can be smaller than z
so the last if shoul have an else with
System.out.println("z is the greatest")

3. I don't know what 'white box coverage cirterion' means.
you could write a test which would try all possibilities, something like;
for (x = 0; x < 3; x++) {
  for (y = 0; y < 3; y++) {
    for (z = 0; z < 3; z++) {
      System.out.println("x=" + x + ",y=" + y + ",z=" + z + ", result = " + yourcode(x, y, z));
    }
  }
}
}

#3
Vladimir

Vladimir

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
IMHO, exercise is very very bad and it is very hard to guess what your teacher expects as an answer, because there is no real application for this code. Metalhead said that z > y is not covered, but there is also situation where x == y == z. I guess you need

Quote

Condition coverage (or predicate coverage) - Has each Boolean sub-expression evaluated both to true and false? This does not necessarily imply decision coverage.
You have this boolean expression in your code:
1. x > y. Evaluate to true: 1, 0, 0; evaluate to false: 0, 1, 0
2. x > z. Evaluate to true: 1, 0, 0; evaluate to false: 0, 0, 1
3. y > z: Evaluate to true: 0, 1, 0; evaluate to false: 0, 0, 1
So your test suite will look like:
x, y, z
1, 0, 0
0, 1, 0
0, 0, 1
Code will look like:
package net.codecall;

public class Test {

	public static String test(int x, int y, int z) {
		if (x > y) {
			if (x > z) {
				System.out.println("x is the greatest");
			} else {
				System.out.println("z is the greatest");
			}
		} else {
			if (y > z){
				System.out.println("y is the greatest");
			}
		}
		return null;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		test(1, 0, 0);
		test(0, 1, 0);
		test(0, 0, 1); // reveals the error
	}
}


#4
Kenneth77

Kenneth77

    Newbie

  • Members
  • Pip
  • 5 posts
Thanks Vladimir,

Sorry I am not a programmer and abit struggling with this kind of question.

This is my stupid interpretation of the code!!

If X is biggher that Y (assume input is Z)
Then if should go to the second “else”, right
As the initial input “Z” is bigger than Y
Shouldn’t it print out be “Y”

As for where is the fault, could you explain abit more, please

#5
Vladimir

Vladimir

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
assume input is Z
Input are x, y and z.

	public static void main(String[] args) {

		test(1, 0, 0); // x = 1, y = 0, z = 0; output is: x is the greatest, it is the right answer

		test(0, 1, 0); // x = 0, y = 1, z = 0; output is: y is the greatest, it is the right answer

		test(0, 0, 1); // x = 0, y = 0, z = 1; output is: null, but right answer is: y is the greatest, it means that we found the fault

	}

Check also Metalhead for explanation why this happens:

Quote

2. y can be smaller than z
so the last if shoul have an else with
System.out.println("z is the greatest")
Hope this will help.

#6
Kenneth77

Kenneth77

    Newbie

  • Members
  • Pip
  • 5 posts
Thanks Vladimir

Great help!! Although I still need some time to be able to fully understand it all!!

As for Q2 “Where is the FAULT”??


Metalhead were say that “ z > y is not covered” and you added “but there is also situation where x == y == z”
X, Y, Z are also not covered, How???

It would be good if you could drop a few word instead of programming code, please. Cos I am not so familiar with the Boolean thing…..

Sorry for these stupid questions…..

#7
Vladimir

Vladimir

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
I prefer code, because English is not my native language :)
To be honest I do not know what to do with situation where x == y == z (for example x = 1, y = 1, z = 1), because test suite will depend on how your code will be fixed for fault we have already found. It can be fixed in such way that you will need another coverage method to find fault. I think you can mention this situation somewhere in your paper or ask teacher for advice.

#8
Kenneth77

Kenneth77

    Newbie

  • Members
  • Pip
  • 5 posts
Thanks as ever...

here is the answer I've come with!! (of cos, with your help)

Do you think that it has properly addressed the questions???

4.b) Consider the following code (in Java) which accepts 3 integers x, y and z as input and output whether x, y, or z is the biggest.

 Disregard the fault the biggest output would be “Y”

1. Test case – (X= 1, Y= 0 and Z = 0) output is X is the greatest”
2. Test case – (X=0, Y=1 and Z = 0) output is Y is the greatest”
3. Test Case – (X=0, Y=0 and Z=1) output is null; nevertheless the expected output should be “Y is the greatest” - this is also one of the faults!!

i) What is the fault?

 The fault is where X== Y, X == Z and Y == Z
 Refer to above 3. Test case - with value in X = 0, Y = 0 and Z = 1. the expected output should be “Y is the greatest”. Not “null”.
 Another faults is “missing an else” - Assuming input is a “Z”, as Y can be smaller than Z, so the last “IF” should have an “Else” with System.out.println("z is the greatest").

many many thank

P.S - do you think MCDC is an appropriate white box coverage criterion for revealing this kind of fault?? cos in the previous post you suggested "condition coverage" - is condition coverage good ensures whether all the Boolean expressions have been evaluated to both TRUE and FALSE. (Y && N)

whereas MCDC is determine each condition should be evaluated at least once which affects the decision outcome independently.


Thanks again

#9
Vladimir

Vladimir

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts

Quote

 The fault is where X== Y, X == Z and Y == Z
 Refer to above 3. Test case - with value in X = 0, Y = 0 and Z = 1. the expected output should be “Y is the greatest”. Not “null”.
 Another faults is “missing an else” - Assuming input is a “Z”, as Y can be smaller than Z, so the last “IF” should have an “Else” with System.out.println("z is the greatest").
The fault is “missing an else” as Y can be smaller than Z, so the last “IF” should have an “Else” with System.out.println("z is the greatest"). Refer to above 3 Test case - with value in X = 0, Y = 0 and Z = 1 the expected output should be “Y is the greatest”. Not “null”. Possibly test case for X == Y == Z should be added to the test suite, but this depends on how previous fault will be fixed and what output is expected in this situation.

For the MCDC I can't say for sure, but it looks like "Condition Coverage" is enough in your case.

#10
Kenneth77

Kenneth77

    Newbie

  • Members
  • Pip
  • 5 posts
Many many Thanks indeed.

i have one final final request!!

As for the questionii) - Which white box coverage criterion will you adopt to reveal this type of fault? You should define the criterion and explain your choice. (note: you should choose a coverage criterion which can always generate a test set to detect the fault but requires the fewest number of test cases)

i have come up with these test cases - not sure am i doing the right things!!!

Using Condition coverage and test cases as follow;


The First condition where (X>Y)
Test case 1 - X=1 > Y=1
Test case 2 – X=0 >Y=1
Test case 3 – X=1 >Y=0

The Second condition where (X>Z)
Test case 1 – X=1 > Y=1
Test case 2 – X=0 > Y=1
Test case 3 – X=1 > Y=0

The Third condition where (Y>Z)
Test case 1 – Y=1 > Z=1
Test case 2 – Y=0 > Z=1
Test case 3 – Y=1 > Z =0

i know you use Boolean to illustrate the faults, but in the question asked that i have use some test case. Do the above test cases make sense to you??

Again thanks so much!

#11
Vladimir

Vladimir

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
Your test suite should be minimal. Mine is:
x, y, z
1, 0, 0
0, 1, 0
0, 0, 1
and this test suite is able to find fault. Your is able too, but it is much larger.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users