FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What's wrong with this?

 
Post new topic   Reply to topic     Forum Index -> General
View previous topic :: View next topic  
Author Message
garth



Joined: 14 Feb 2007
Posts: 2

PostPosted: Sat Feb 24, 2007 8:04 pm    Post subject: What's wrong with this? Reply with quote

Hi all,

x and y are random Values (rand()%8). I want to assert that y is always x+/-3.
However, assert seems to be executed before switch, because it throws me an Assertion-Error. When I comment the assert function and check the output of the debug then y is exactly what I wanted to assert...

Why can't I use the assert function here??

Code:
   
void swapVertical(int x, int y) {
      switch(x) {
         case 0:    y = x +3; break;
         case 1:    y = x +3; break;
         case 2:    y = x +3; break;
         case 6:    y = x -3; break;
         case 7:    y = x -3; break;
         case 8:    y = x -3; break;
         default:   if(y >= 3 && y <= 5){
                     y = x + 3; break;
                  }
                  else if(y <= 8 && y >= 4){
                     y = x - 3;break;}
      }
      debug writefln("X=%d,Y=%d", x,y);
   assert(y == x + 3 || y == x -3);
}



Hope I could explain what I meant Confused

Thanks alot, Garth
Back to top
View user's profile Send private message
Bradley Smith



Joined: 20 Jun 2006
Posts: 60

PostPosted: Sat Feb 24, 2007 11:42 pm    Post subject: Reply with quote

Works fine for me using Windows DMD 1.006.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> General All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group