How to check if value is nan in unittest?
I came up with assertTrue(math.isnan(nan_value))
I came up with assertTrue(math.isnan(nan_value))
Yes, it is set by CMake. Grepping through the CMake code reveals, that for a host of compilers it is set. Probably they set it only for these compilers, which accepts this flag. Here one of the lines concerning GCC: Modules/Compiler/GNU.cmake: set(CMAKE_${lang}_FLAGS_RELEASE_INIT “-O3 -DNDEBUG”) But be aware that many projects overwrite release/debug flags without preserving … Read more
Is there a way to express that the condition in the contract has no side effect, so that it is always optimized out? Not likely. It’s known that you cannot take a big collection of assertions, turn them into assumptions (via __builtin_unreachable) and expect good results (e.g. Assertions Are Pessimistic, Assumptions Are Optimistic by John … Read more
The issue with your code is the signature of public bool MethodHasAuthorizeAttribute(Func<int, ActionResult> function). MethodHasAuthorizeAttribute can only be used with arguments matching the signature of the delegate you specified. In this case a method returning an ActionResult with a parameter of type int. When you call this method like MethodHasAuthorizeAttribute(controller.Method3), the Compiler will do a … Read more
Found it: Assert.IsTrue(expected.SequenceEqual(actual));
This question is ancient, but Mockito v2.1.0+ now has a built-in feature for this. verify(mock, description(“This will print on failure”)).someMethod(“some arg”); More examples included from @Lambart’s comment below: verify(mock, times(10).description(“This will print if the method isn’t called 10 times”)).someMethod(“some arg”); verify(mock, never().description(“This will print if someMethod is ever called”)).someMethod(“some arg”); verify(mock, atLeastOnce().description(“This will print if … Read more
Since you didn’t override equals in your class, assertEquals behaves the same as assertSame since the default equals implementation compare references. 150 public boolean equals(Object obj) { 151 return (this == obj); 152 } If you provide a dumb overriding of equals: class SomeClass { @Override public boolean equals(Object o) { return true; } } … Read more
Use Objects.requireNonNull(Object) for that. Checks that the specified object reference is not null. This method is designed primarily for doing parameter validation in methods and constructors, […] In your case that would be: public void useObject(CustomObject customObject) { object = customObject.getObject(); Objects.requireNonNull(object); // throws NPE if object is null // do stuff with object } … Read more
It’s simply a very minimal test, and should be documented as such. It only verifies that it doesn’t explode when run. The worst part about tests like this is that they present a false sense of security. Your code coverage will go up, but it’s illusory. Very bad odor.