TIMESTAMP complex_assert::commit(TIMESTAMP t1, TIMESTAMP t2) { // handle once mode if ( once==ONCE_TRUE) { once_value = value; once = ONCE_DONE; } else if ( once==ONCE_DONE) { if ( once_value.Re()==value.Re() && once_value.Im()==value.Im() ) { gl_verbose("Assert skipped with ONCE logic"); return TS_NEVER; } else { once_value = value; } } // get the target property gld_property target_prop(get_parent(),get_target()); if ( !target_prop.is_valid() || target_prop.get_type()!=PT_complex ) { gl_error("Specified target %s for %s is not valid.",get_target(),get_parent()->get_name()); /* TROUBLESHOOT Check to make sure the target you are specifying is a published variable for the object that you are pointing to. Refer to the documentation of the command flag --modhelp, or check the wiki page to determine which variables can be published within the object you are pointing to with the assert function. */ return 0; } // test the target value complex x; target_prop.getp(x); if ( status==ASSERT_TRUE ) { if ( operation==FULL || operation==REAL || operation==IMAGINARY ) { complex error = x - value; double real_error = error.Re(); double imag_error = error.Im(); if ( ( _isnan(real_error) || fabs(real_error)>within ) && ( operation==FULL || operation==REAL ) ) { gl_error("Assert failed on %s: real part of %s %g not within %f of given value %g", get_parent()->get_name(), get_target(), x.Re(), within, value.Re()); return 0; } if ( ( _isnan(imag_error) || fabs(imag_error)>within ) && ( operation==FULL || operation==IMAGINARY ) ) { gl_error("Assert failed on %s: imaginary part of %s %+gi not within %f of given value %+gi", get_parent()->get_name(), get_target(), x.Im(), within, value.Im()); return 0; } } else if ( operation==MAGNITUDE ) { double magnitude_error = x.Mag() - value.Mag(); if ( _isnan(magnitude_error) || fabs(magnitude_error)>within ) { gl_error("Assert failed on %s: Magnitude of %s (%g) not within %f of given value %g", get_parent()->get_name(), get_target(), x.Mag(), within, value.Mag()); return 0; } } else if (get_operation() == ANGLE) { double angle_error = x.Arg() - value.Arg(); if ( _isnan(angle_error) || fabs(angle_error)>within ) { gl_error("Assert failed on %s: Angle of %s (%g) not within %f of given value %g", get_parent()->get_name(), get_target(), x.Arg(), within, value.Arg()); return 0; } } } else if (get_status() == ASSERT_FALSE) { complex error = x - value; double real_error = error.Re(); double imag_error = error.Im(); if ( ( _isnan(real_error) || fabs(real_error)<within ) || ( _isnan(imag_error) || fabs(imag_error)<within ) ) { if ( _isnan(real_error) || fabs(real_error)<within ) { gl_error("Assert failed on %s: real part of %s %g is within %f of %g", get_parent()->get_name(), get_target(), x.Re(), within, value.Re()); } if ( _isnan(imag_error) || fabs(imag_error)<within ) { gl_error("Assert failed on %s: imaginary part of %s %+gi is within %f of %gi", get_parent()->get_name(), get_target(), x.Im(), within, value.Im()); } return 0; } } else { gl_verbose("Assert test is not being run on %s", get_parent()->get_name()); return TS_NEVER; } gl_verbose("Assert passed on %s",get_parent()->get_name()); return TS_NEVER; }
TIMESTAMP double_assert::commit(TIMESTAMP t1, TIMESTAMP t2) { // handle once mode if ( once==ONCE_TRUE ) { once_value = value; once = ONCE_DONE; } else if ( once == ONCE_DONE ) { if ( once_value==value ) { gl_verbose("Assert skipped with ONCE logic"); return TS_NEVER; } else { once_value = value; } } // get the target property gld_property target_prop(get_parent(),get_target()); if ( !target_prop.is_valid() || target_prop.get_type()!=PT_double ) { gl_error("Specified target %s for %s is not valid.",get_target(),get_parent()->get_name()); /* TROUBLESHOOT Check to make sure the target you are specifying is a published variable for the object that you are pointing to. Refer to the documentation of the command flag --modhelp, or check the wiki page to determine which variables can be published within the object you are pointing to with the assert function. */ return 0; } // get the within range double range = 0.0; if ( within_mode == IN_RATIO ) { range = value * within; if ( range<0.001 ) { // minimum bounds range = 0.001; } } else if ( within_mode== IN_ABS ) { range = within; } // test the target value double x; target_prop.getp(x); if ( status == ASSERT_TRUE ) { double m = fabs(x-value); if ( _isnan(m) || m>range ) { gl_error("Assert failed on %s: %s %g not within %f of given value %g", get_parent()->get_name(), get_target(), x, range, value); return 0; } gl_verbose("Assert passed on %s", get_parent()->get_name()); return TS_NEVER; } else if ( status == ASSERT_FALSE ) { double m = fabs(x-value); if ( _isnan(m) || m<range ) { gl_error("Assert failed on %s: %s %g is within %f of given value %g", get_parent()->get_name(), get_target(), x, range, value); return 0; } gl_verbose("Assert passed on %s", get_parent()->get_name()); return TS_NEVER; } else { gl_verbose("Assert test is not being run on %s", get_parent()->get_name()); return TS_NEVER; } }