assertions

Debug Assertion Failed! Expression: _BLOCK_TYPE_IS_VALID [closed]

时间秒杀一切 提交于 2019-11-27 14:29:23
I am getting this error message: Debug Assertion Failed! Expression:_BLOCK_TYPE_US_VALID(pHead->nBlockUse) while trying to do the following #include <vector> #include <algorithm> using namespace std; class NN { public: NN(const int numLayers,const int *lSz,const int AFT,const int OAF,const double initWtMag,const int UEW,const double *extInitWt); double sse; bool operator < (const NN &net) const {return sse < net.sse;} }; class Pop { int popSize; double a; public: Pop(const int numLayers,const int *lSz,const int AFT,const int OAF,const double initWtMag,const int numNets,const double alpha);

Debug.Assert vs Exceptions

断了今生、忘了曾经 提交于 2019-11-27 11:41:26
问题 Surprisingly I was only able to find one previous question on SO about this subject, and I'd just like to get the community "Vote of Confidence" (or not!) on my approach. The way I see it is thus: use Debug.Assert to state things you EXPECT would be true. This would be used when we are in complete control over our environment, for example in a method to verify some pre and post-conditions. use Exceptions when exceptional circumstances arise. Dealing with external resources, i.e. files,

How do I use Assert.Throws to assert the type of the exception?

不打扰是莪最后的温柔 提交于 2019-11-27 10:21:37
How do I use Assert.Throws to assert the type of the exception and the actual message wording. Something like this: Assert.Throws<Exception>( ()=>user.MakeUserActive()).WithMessage("Actual exception message") The method I am testing throws multiple messages of the same type, with different messages, and I need a way to test that the correct message is thrown depending on the context. Patrik Hägne Assert.Throws returns the exception that's thrown which lets you assert on the exception. var ex = Assert.Throws<Exception>(() => user.MakeUserActive()); Assert.That(ex.Message, Is.EqualTo("Actual

Why should I use asserts?

强颜欢笑 提交于 2019-11-27 09:23:44
问题 I never got the idea of asserts -- why should you ever use them? I mean, let's say I were a formula driver and all the asserts were things like security belt, helmet, etc. The tests (in debug) were all okay, but now we want to do racing (release)! Should we drop all security, because there were no issues while testing? I will never ever remove them. I think most of the guys that claim that removing something comparable to asserts never profiled their code or the asserts were absolute

Detecting whether on UI thread in WPF and Winforms

天大地大妈咪最大 提交于 2019-11-27 07:45:27
I've written an assertion method Ensure.CurrentlyOnUiThread() , below, that checks that the current thread is a UI thread. Is this going to be reliable in detecting the Winforms UI thread? Our app is mixed WPF and Winforms, how best to detect a valid WPF UI thread? Is there a better way to do this? Perhaps code contracts? Ensure.cs using System.Diagnostics; using System.Windows.Forms; public static class Ensure { [Conditional("DEBUG")] public static void CurrentlyOnUiThread() { if (!Application.MessageLoop) { throw new ThreadStateException("Assertion failed: not on the UI thread"); } } } Don't

When should I use Debug.Assert()?

廉价感情. 提交于 2019-11-27 05:48:22
I've been a professional software engineer for about a year now, having graduated with a CS degree. I've known about assertions for a while in C++ and C, but had no idea they existed in C# and .NET at all until recently. Our production code contains no asserts whatsoever and my question is this... Should I begin using Asserts in our production code? And if so, When is its use most appropriate? Would it make more sense to do Debug.Assert(val != null); or if ( val == null ) throw new exception(); In Debugging Microsoft .NET 2.0 Applications John Robbins has a big section on assertions. His main

assert vs. JUnit Assertions

♀尐吖头ヾ 提交于 2019-11-27 01:05:25
Today I saw a JUnit test case with a java assertion instead of the JUnit assertions—Are there significant advantages or disadvantages to prefer one over the other? Yishai In JUnit4 the exception (actually Error) thrown by a JUnit assert is the same as the error thrown by the java assert keyword (AssertionError), so it is exactly the same as assertTrue and other than the stack trace you couldn't tell the difference. That being said, asserts have to run with a special flag in the JVM, causing many tests to appear to pass just because someone forgot to configure the system with that flag when the

Enabling assertions in Netbeans

こ雲淡風輕ζ 提交于 2019-11-26 23:34:16
问题 I wanna do something like java -enableassertions com.geeksanonymous.TestClass How do I do this? 回答1: The easiest way is to use the Run properties. The property is labeled 'VM Options'. This tutorial has more detailed info and screen shots from NetBeans 5.5. The dialog is very similar in the most recent release of NetBeans; 6.8, which is available today. 回答2: With a Maven project in netbeans 7.0, choose "File" -> "Project Properties ()". In the window that appears, choose "Run", and add

How to change the message in a Python AssertionError?

社会主义新天地 提交于 2019-11-26 22:41:05
问题 I'm writing per the following, in which I try to produce a decent error message when comparing two multiline blocks of Unicode text. The interior method that does the comparison raises an assertion, but the default explanation is useless to me I need to add something to code such as this below: def assert_long_strings_equal(one, other): lines_one = one.splitlines() lines_other = other.splitlines() for line1, line2 in zip(lines_one, lines_other): try: my_assert_equal(line1, line2) except

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

青春壹個敷衍的年華 提交于 2019-11-26 20:54:16
问题 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 practice? Asserting the equality of the objects through overriden equals method or Asserting the equality of all the properties 回答1: I for one use custom assertions.