ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

assert
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Flat
View previous topic :: View next topic  
Author Message
Lucas Braesch



Joined: 31 May 2010
Posts: 2918

PostPost subject: Re: assert    Posted: Tue Nov 14, 2017 6:23 am Reply to topic Reply with quote

Harald wrote:
If you want to test only parts of your code then you can do things like this:

In an header like basics.h
Code:

// Which tests should be performed
#ifdef _DEBUG
#define ASSERT_BASICS(c,t)              { if ( !(c) )  throw (t); }
#define ASSERT_PRINCIPAL_VARIATION(c,t) { if ( !(c) )  throw (t); }
#define ASSERT_MOVE(c,t)                { if ( !(c) )  throw (t); }
...
#else
#define ASSERT_BASICS(c,t)
#define ASSERT_PRINCIPAL_VARIATION(c,t)
#define ASSERT_MOVE(c,t)
...
#endif

And in a file like move.cpp
Code:

void Move::set( ColorType color, SquareType from, SquareType to,
                PieceType piece, PieceType capture,
                PromotionType promotion
              )
{
    ASSERT_MOVE( color == White || color == Black, "Error: bad color in Move::set()" )
    ASSERT_MOVE( from >= 0 && from < 64, "Error: bad from in Move::set()" )
    ASSERT_MOVE( to   >= 0 && to   < 64, "Error: bad to in Move::set()" )
    ASSERT_MOVE( piece >= Pawn && piece < 8, "Error: bad piece in Move::set()" )
    ASSERT_MOVE( capture >= NoPiece && capture != King && capture < 8, "Error: bad capture in Move::set()" )
    ASSERT_MOVE( promotion <= PromoteToKnight, "Error: bad promotion in Move::set()" )
    move_ = from | (to << 6) | (promotion << 12) | (piece << 14) | (capture << 17) | (color << 20);
}

This is pointless. Just clutters the code for no reason.

Assert already prints the source file name and line when it fires.
_________________
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Subject Author Date/Time
assert Folkert van Heusden Mon Nov 13, 2017 9:09 am
      Re: assert Marco Belli Mon Nov 13, 2017 9:47 am
      Re: assert Lucas Braesch Mon Nov 13, 2017 9:49 am
            Re: assert Henk van den Belt Mon Nov 13, 2017 10:44 am
            Re: assert Martin Sedlak Mon Nov 13, 2017 11:05 am
                  Re: assert Rasmus Althoff Mon Nov 13, 2017 11:49 pm
      Re: assert Henk van den Belt Mon Nov 13, 2017 10:26 am
      Re: assert Folkert van Heusden Mon Nov 13, 2017 10:50 am
            Re: assert Henk van den Belt Mon Nov 13, 2017 10:59 am
            Re: assert Marco Belli Mon Nov 13, 2017 11:24 am
      Re: assert Harald Lüßen Mon Nov 13, 2017 12:53 pm
            Re: assert Lucas Braesch Tue Nov 14, 2017 6:23 am
                  Re: assert Álvaro Begué Tue Nov 14, 2017 12:26 pm
                  Re: assert Harald Lüßen Tue Nov 14, 2017 7:45 pm
      Re: assert F. Bluemers Mon Nov 13, 2017 1:08 pm
      Re: assert H.G.Muller Mon Nov 13, 2017 3:14 pm
      Re: assert Jon Dart Mon Nov 13, 2017 5:59 pm
      Re: assert Henk van den Belt Tue Nov 14, 2017 8:17 pm
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions

 
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
Enhanced with Moby Threads