I have the following variables:
$start_t = 1;
$start_n = 2;
$end_t = 6;
$end_n = 5;
I want to check all the logical combinations between the $start_t and $start_n AND $end_t and $end_n.
I have the following:
if($start_t >= $start_n && $end_t >= end_n)
{ // Do stuff }
elseif($start_t < $start_n && $end_t >= $end_n)
{ // Do stuff }
elseif($start_t >= $start_n && $end_t < $end_n)
{ // Do stuff }
elseif($start_t < start_n && $end_t < $end_n)
{ // Do stuff }
Is there any other combination that I cannot see? I mean between the $start_t, $start_n And $end_t and $end_n.
Is there any way to calculate all the available combinations?
The equality case ($start_t === $start_n
, similar for $end_*
) is missing. Otherwise, all combinations are there.
if($start_t >= $start_n)
{
if($end_t >= end_n)
//do stuff
else
//do stuff
}
else
{
if($end_t >= end_n)
//do stuff
else
//do stuff
}
Re structuring like this will help you to identify the combinations better. You can later refactor this back to your original format
As you are using a binary operator, you have 2! = 2 permutations of the start variables, and for each one, 2! = 2 permutations of the end variables. So, in total you have 2!*2! = 4 combinations, assuming you don't need to test for equality. This proves that your code tests for every case.