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)
10 replies to this topic
#1
Posted 19 November 2010 - 10:19 PM
|
|
|
#2
Posted 20 November 2010 - 01:03 AM
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;
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
Posted 20 November 2010 - 04:04 AM
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
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:
Quote
Condition coverage (or predicate coverage) - Has each Boolean sub-expression evaluated both to true and false? This does not necessarily imply decision coverage.
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, 1Code 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
Posted 21 November 2010 - 11:52 PM
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
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
Posted 22 November 2010 - 02:49 AM
assume input is ZInput 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")
so the last if shoul have an else with
System.out.println("z is the greatest")
#6
Posted 22 November 2010 - 03:59 PM
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…..
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
Posted 23 November 2010 - 01:18 AM
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.
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
Posted 23 November 2010 - 04:17 PM
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
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
Posted 24 November 2010 - 12:27 AM
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").
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").
For the MCDC I can't say for sure, but it looks like "Condition Coverage" is enough in your case.
#10
Posted 24 November 2010 - 07:24 PM
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!
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
Posted 27 November 2010 - 08:29 AM
Your test suite should be minimal. Mine is:
x, y, z 1, 0, 0 0, 1, 0 0, 0, 1and 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


Sign In
Create Account

Back to top









