Basically, I have a project which I need create a output format of DD/MM/YYYY - Which I used in a toString, it works fine.
I then used a switch case for all the days in a month, and of course I took into consideration the leap year.

When I try and run the test folder for the class, i get this error:

(The toString passes as successful)
However, the Day/Month/Year test don't

java.lang.AssertionError: expected:<1> but was:<32>


and under this line reads:

...... DateOfBirthTest.testValidateYear(DateOfBirth.java:284)

And help will be very much appreciated.

Edited 6 Years Ago by iraqi4life: n/a

What compiler is telling you is that it expected value in interval 1 to 31 but received something outside this limit. Guess that failing scenario is on days of month.
Without specific code is difficult to say more

private boolean validateDateOfBirth ()
{
result = false ;

{
	switch (month)
	{
case 1: 
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
    day = 31;
    break;
case 4:
case 6:
case 9:
case 11:
    day  = 30;
    break;
case 2:
    if ( ((year % 4 == 0) && !(year % 100 == 0))
         || (year % 400 == 0) )
        day = 29;
    else
        day = 28;
    break;
	}
result = true;
return result;
}
}

That's it.
anything wrong with that?

I think there were an extra { and } on your code

try this maybe it will work.

private boolean validateDateOfBirth (){
 
result = false ;
   
   
switch (month){
   
     case 1:
   
     case 3:
  
     case 5:
  
     case 7:
  
     case 8:
  
     case 10:
  
     case 12:

             day = 31;
  
             break;
  
     case 4:

     case 6:

     case 9:
  
     case 11:
  
             day = 30;
  
             break;

     case 2:
  
            if ( ((year % 4 == 0) && !(year % 100 == 0))
  
            || (year % 400 == 0) )
  
               day = 29;
  
           else
  
              day = 28;
  
              break;
  }
  
result = true;
  
return result;
  

}

Edited 6 Years Ago by islam-morad: n/a

This article has been dead for over six months. Start a new discussion instead.