Simple Pseudocode: Test Cases for X & Y

  • Thread starter Thread starter Hooke's Law
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around determining the least number of test cases needed to fully test a piece of pseudocode that involves conditional statements based on the values of x and y. The focus is on understanding how to effectively cover the different branches of the code through various test cases.

Discussion Character

  • Homework-related
  • Exploratory
  • Technical explanation

Main Points Raised

  • Some participants suggest specific values for x and y, such as [x = 0; y = 0] and [x = 4; y = 0], to test the pseudocode.
  • One participant simplifies the problem by setting y to 0 and discusses the conditions under which "hello" and "bye" would be returned.
  • Another participant states that "hello" would be returned for any positive number of x, while "bye" would be returned for negative numbers or zero, but questions remain about the range of values.
  • There is a suggestion to use a Venn Diagram to visualize the ranges of x that correspond to each return value.
  • Participants discuss the implications of combining cases and the significance of the condition x < (y + 3) in relation to the other conditions.
  • Clarifications are made regarding what constitutes the "least number of test cases" needed to cover all branches of the code.

Areas of Agreement / Disagreement

Participants express varying interpretations of how to determine the least number of test cases. While some agree on the need to cover different branches, there is no consensus on the specific values or the method to achieve this.

Contextual Notes

There are discussions about the implications of setting y to specific values and how that affects the testing of the pseudocode. Some participants note that certain conditions may not be necessary to consider, leading to potential confusion about the overall testing strategy.

Hooke's Law
Messages
30
Reaction score
0

Homework Statement



Pseudocode:

if ( x is greater than y )
then return "hello"
else if ( x is less than y + 3 )
then return "bye"
What is the least number of different test cases that I would use to test this coude(eg. What would you use as values for x and y to fully test this piece of code?

The Attempt at a Solution


I'm thinking [ x = 0 ; y = 0 ] & [ x = 4 ; y = 0 ] , . But I'm confused with what's the "least number of different test cases".

thanks
 
Physics news on Phys.org
Hooke's Law said:

Homework Statement



Pseudocode:

if ( x is greater than y )
then return "hello"
else if ( x is less than y + 3 )
then return "bye"
What is the least number of different test cases that I would use to test this coude(eg. What would you use as values for x and y to fully test this piece of code?

The Attempt at a Solution


I'm thinking [ x = 0 ; y = 0 ] & [ x = 4 ; y = 0 ] , . But I'm confused with what's the "least number of different test cases".

Let's simplify things a bit, and suppose that y = 0.
Code:
if (x > 0)
  return "hello"
else if (x < 3)
  return "bye"

Under what conditions would "hello" be returned? Under what conditions would "bye" be returned? Are there any conditions in which nothing would be returned?
 
Mark44 said:
Under what conditions would "hello" be returned? Under what conditions would "bye" be returned? Are there any conditions in which nothing would be returned?

"hello" would be returned if x = 1,2,3,4...
"bye" would be returned if x = ...-2,-3,-1,0,1, & 2

There are no conditions when nothing is returned.
 
If x is any positive number, not just integers, "hello" is returned.
If x is any negative number or zero, "bye" is returned.

"bye" is NOT returned if x is any number between 0 and 3.
 
EDIT: Ok. I get why bye is not returned with any number between 0 and 3. So what's next?
 
To find out the least number of test cases you can construct a Venn Diagram of each number range associated with each case. Then just pull a random number from each.
 
Hooke's Law said:
EDIT: Ok. I get why bye is not returned with any number between 0 and 3. So what's next?
If you recall I simplified the problem by setting y to 0. Now that you understand the code with y == 0, can you understand the original code?
 
viscousflow said:
To find out the least number of test cases you can construct a Venn Diagram of each number range associated with each case. Then just pull a random number from each.

What do you mean by "each number range associated with each case"?
 
1) Pick a number, say y = 10

case 1 (explicitly)
x>y
if x = 11, 12,13 or 14...
return 'hello'

case 2 (explicitly)
else if x<(10+3)
i.e. x = 12, 11, 10, 9, 8, 7..
return 'bye'

Now combine cases to get a range(sorta like a Venn Diagram - this is my mental picture)
'hello' is returned for all x == 11, 12,13 or 14...
'bye' is only returned for all x == 10, 9, 8, 7..

As you can see the statement 'elseif x<(10+3)' is only active for all numbers less than 11 since case 1 (x>10) is satisfied first, from 11 onwards no matter what.
 
  • #10
viscousflow said:
Now combine cases to get a range(sorta like a Venn Diagram - this is my mental picture)
'hello' is returned for all x == 11, 12,13 or 14...
'bye' is only returned for all x == 10, 9, 8, 7..

Is that what Mark44 meant by combining cases? But I still can't see how to get the least number of cases.
 
  • #11
Do I need to pick other numbers for x and y? Could someone please explain to me what ""least number of different test cases" means? Is it having various numbers for x and y and finding the similar number in them?
 
  • #12
"Least number of test cases" means the smallest number of values of x and y that are needed to exercise each branch in the code.

Going back to the simplified example I gave, where I set y to 0 -
Code:
if (x > 0)
  return "hello"
else if (x < 3)
  return "bye"
If x is in the interval (0, infinity), the code returns the string "hello". Otherwise (if x is in the interval (-infinity, 0], the code returns the string "bye". There are two test cases here. Two values that can be used are x = .5 and x = -1.
Note that the comparison x < 3 in the else clause is a red herring. If x <= 0 it will automatically be less than 3. If x is positive and less than 3, the first branch is chosen (resulting in "hello" being returned) because x is positive. Being less than 3 or greater than 3 doesn't enter into things.

Now, can you apply this reasoning to your original problem?
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K