assert

C/C++ an int value that isn't a number ?!

Can this ever happen ? 3 asserts, where one should activate. int nr = perform_calc(); assert( nr == 0); assert( nr > 0); assert( nr < 0); Can there be a case when the program doesn't activate the asserts on g++ 3.4.4. And no I don't have the possibility to change the code in order to print the number out in case the asserts don't act...

Breaking into the debugger on iPhone

Hi everyone, For assert macros in my iPhone project, I'm looking for a way to programmatically break into the debugger. On Windows (MSVC++), I can use __debugbreak() for this purpose. Invoking this function will stop my program, launch the debugger, and display a callstack of the line that called __debugbreak(). Is there anything simil...

Suggestions for python assert function

I'm using assert multiple times throughout multiple scripts, I was wondering if anyone has any suggestions on a better way to achieve this instead of the functions I have created below. def assert_validation(expected, actual, type='', message=''): if type == '==': assert expected == actual, 'Expected: %s, Actual: %s, %s' %...

Should one override equals method for asserting the object equality in a unit test?

Let's say we are testing the result of a method by asserting the equality of all the properties of the result object with properties of an expected result object. Should we implement equals method and use Assert.AreEqual(expectedResult, actualResult)... But equals may mean something different in production code. Which is the best prac...

Do you use assertions?

This is not really a "question" so I'm making it CW. The assert Keyword is great! It should make, feel your self more confident with the code you wrote, but, until today when I was creating a small test class ( < 20 lines ) I realize a never use it since it was introduced. Heck! I barely use logger which is very useful indeed, ...

Usage of Assert.Inconclusive

Hi, Im wondering how someone should use Assert.Inconclusive(). I'm using it if my Unit test would be about to fail for a reason other than what it is for. E.g. i have a method on a class that calculates the sum of an array of ints. On the same class there is also a method to calculate the average of the element. It is implemented by ca...

Python : Assert that variable is instance method?

How can one check if a variable is an instance method or not? I'm using python 2.5. Something like this: class Test: def method(self): pass assert is_instance_method(Test().method) ...

Disable assertions in Python

How do I disable assertions in Python? That is - if it fails, I don't want it to throw an AssertionError, but to keep going. ...

Exception Vs Assertion

What is difference between java Exception handling and assert any condition? its know that assert is of two type.but when should we use assert keyword? ...

Python test framework with support of non-fatal failures

I'm evaluating "test frameworks" for automated system tests; so far I'm looking for a python framework. In py.test or nose I can't see something like the EXPECT macros I know from google testing framework. I'd like to make several assertions in one test while not aborting the test at the first failure. Am I missing something in these fra...

Python assert -- improved introspection of failure?

This is a rather useless assertion error; it does not tell the values of the expression involved (assume constants used are actually variable names): $ python -c "assert 6-(3*2)" [...] AssertionError Is there a better assert implementation in Python that is more fancy? It must not introduce additional overhead over execution (except ...

Why does Assert.AreEqual(T obj1, Tobj2) fail with identical byte arrays

I have two identical byte arrays in the following segment of code: /// <summary> ///A test for Bytes ///</summary> [TestMethod()] public void BytesTest() { byte[] bytes = Encoding.UTF8.GetBytes(Properties.Resources.ExpectedPacketData); TransferEventArgs target = new TransferEventArgs(bytes); ...

How to write a macro that can take a parameter?

I want to use some NSAssert stuff and other things to enable better debugging in my app. NSAssert wants a string which it prints if the assertion fails. Nice, but useless unless you type a whole bunch of information in that string, which can become a big mess when done all over the place. So I want to make a macro that will do the NSAss...

Exception vs. error-code vs. assert

I'm working on a library that generates reports of devices. The generate_report (const std::string& no) member function can fail due to various reasons: invalid report no. invalid state (the report_generator is a FSM) no device is active error during report generation Which error-handling mechanism is best for these errors? just re...

MFC Application Crashes while closing

I had a working MFC application (a dialog application), I deleted some of its button and added a new button, but now when it closes the application crashes. It fails in one of ASSERT() macro. The debug assertions fails on these lines File: afxtempl.h Line: 558 When I view that code it was something like this template<class TYPE, class...

Convenient strategies for assertion checks.

Some asserts are costly, some are better turned off at production code. At least it is not clear that assertions should be always enabled. In my application I would like to be able to turn on/off part of assertions on per-file or per-class basis. How to do it in C++? ...

Waiting with a crash for a debugger?

When an assert fails or there is a segmentation fault, it would be very convenient that one of the following happens: Program ask whether to run a debugger. Program waits with crashing until debugger is attached. Program leaves something (core dump?) that we can resume execution from this point and investigate. The question is quite ...

Folding away assertions in C++ class?

So, in a non-class type of situation, I can do something like this: int val_to_check = 0; int some_func(int param) { assert(val_to_check == 0); return param*param+param; } int main() { printf("Val: %i\n", some_func(rand())); return 0; } If val_to_check is declared const instead, the assertion can be folded away by the compil...

Making Python's `assert` throw an exception that I choose

Can I make assert throw an exception that I choose instead of AssertionError? UPDATE: I'll explain my motivation: Up to now, I've had assertion-style tests that raised my own exceptions; For example, when you created a Node object with certain arguments, it would check if the arguments were good for creating a node, and if not it would...

what is the assert function

hi i ve been studying on openCV tutorials and came across with the "assert" function what does it do thanks ...