assert

Suggestions for python assert function

流过昼夜 提交于 2019-12-08 04:07:05
问题 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' %(expected, actual, message) elif type == '!=': assert expected != actual, 'Expected: %s, Actual: %s, %s' %(expected, actual, message) elif type == '<=': assert expected <=

Appropriate use of assert

那年仲夏 提交于 2019-12-08 00:29:27
问题 Can you please help me better understand, what is an appropriate use of “assert” vs “throwing an exception? When is each scenario appropriate? Scenario 1 CODE public Context(Algorythm algo) { if (algo == null) { throw new IllegalArgumentException("Failed to initialize Context"); } this.algo = algo; } TEST public void testContext_null() { try { context = new Context(null); fail(); } catch (IllegalArgumentException e) { assertNotNull(e); } } Scenario 2 CODE public Context(Algorythm algo) {

Using RhinoMocks, how can I assert that one of several methods was called?

谁说胖子不能爱 提交于 2019-12-07 22:38:06
问题 Consider the following service interfaces: public interface IServiceA { void DoSomething(string s); void DoSomething(string s, bool b); } public interface IServiceB { void DoSomething(); } The implementation of IServiceB depends on IServiceA like this: public class ServiceB : IServiceB { private IServiceA _serviceA; public ServiceB(IServiceA serviceA) { _serviceA = serviceA; } public void DoSomething() { _serviceA.DoSomething("Hello", true); } } Ie. the dependency is injected in the

Trace.Assert not breaking, neither showing the message box

…衆ロ難τιáo~ 提交于 2019-12-07 16:47:17
问题 I have a WPF application in which I'm moving data around on a Canvas. The problem started when I tried moving the data with the mouse like a freak. Here's the sequence of the actions: The MouseMove on the Canvas is triggered In the MouseMove, I change some data A Trace.Assert FAILS. The debugger does not break, neither is the message box Another MouseMove is triggered The data is changed again An exception is thrown because of a reentrancy check in a collection. The debugger breaks there. The

In Eclipse, how do I see the input to Assert.assertEquals when it fails?

[亡魂溺海] 提交于 2019-12-07 12:21:05
问题 I'm not much of an Eclipse guru, so please forgive my clumsiness. In Eclipse, when I call Assert.assertEquals(obj1,obj2) and that fails, how do I get the IDE to show me obj1 and obj2? I'm using JExample, but I guess that shouldn't make a difference. Edit : Here's what I see: (source: yfrog.com) . 回答1: If the information in the JUnit view is not enough for you, you can always set a exception breakpoint on, for example, java.lang.AssertionError. When running the test, the debugger will stop

Why does my Haskell assertion only happen in IHaskell?

白昼怎懂夜的黑 提交于 2019-12-07 11:12:44
问题 If I define import Control.Exception (assert) import Data.Char (ord) f :: String -> String f s = assert (all (`elem` letters) s) $ (letters!!) <$> (ix <$> s) where ix ch = (ord ch - ord 'A') letters = ['A'..'Z'] then if I execute f "AB.CD" in IHaskell, I get :10:7-12: Assertion failed as I would expect. But in all other settings, the assertion seems to be ignored. For example in GHCi (7.10.2) I get ghci>f "AB.CD" "AB*** Exception: Prelude.!!: negative index and if I put the expression in a

Is there any reason not to wrap assert() in a macro that resolves to __builtin_unreachable() in gcc?

若如初见. 提交于 2019-12-07 11:00:51
问题 Context: In this answer, I learned that gcc's __builtin_unreachable() can have some surprisingly impactful performance implications, as it seems that the following: if(condition) __builtin_unreachable(); is being entirely stripped, and used as an optimization hint as long as condition can be guaranteed to not have any side effect. So my immediate reaction to this is that I should create the following macro, and use it absolutely everywhere I would normally use assert() , since side-effect

How to get a declaration for DebugBreak without including Windows.h?

懵懂的女人 提交于 2019-12-07 10:27:59
问题 We have a C++ library. We are providing a custom assert and abandoning Posix NDEBUG and assert (back story below). The assert looks like so under Windows: # define CRYPTOPP_ASSERT(exp) { \ if (!(exp)) { \ std::ostringstream oss; \ oss << "Assertion failed: " << (char*)(__FILE__) << "(" \ << (int)(__LINE__) << "): " << (char*)(__FUNCTION__) \ << std::endl; \ std::cerr << oss.str(); \ DebugBreak(); \ } \ } The problem we are having is, we have to include <windows.h> , and it brings in a lot of

C语言中memset-memcpy(memmove memccpy)-strcpy函数源代码

主宰稳场 提交于 2019-12-07 09:18:46
一、概述 1、memset 原型:extern void *memset(void *buffer, char c, int count); 用法:#include <string.h> 功能:把buffer所指内存区域的前count个字节设置成字符c 说明:返回指向buffer的指针 2、 memcpy 原型:extern void *memcpy(void *dest, void *src, unsigned int count); 用法:#inclue <string.h> 功能:由src所指内存区域复制count个字节到dest所指内存区域 说明:src和dest所指内存区域不能重叠,函数返回指向dest的指针 memccpy 原型:extern void *memccpy(void *dest, void *src, unsigned char ch, unsigned int count); 用法:#include <string.h> 功能:由src所指内存区域复制不多于count个字节到dest所指内存区域,如果遇到字符ch则停止复制 说明:返回指向字符ch后的第一个字符的指针,如果src前count个字节中不存在ch则返回NULL。 memmove 原型:extern void *memmove(void *dest, const void *src,

c语言| |memcpy函数与memmove函数

会有一股神秘感。 提交于 2019-12-07 09:18:16
memcpy和memmove函数 memcpy函数 1.源函数 void * memcpy ( void * dest , const void * src , size_t n ) 2.作用 (小编自己的理解)内存拷贝。从src内存空间移动n个元素,将其赋值给dest的内存中,从内存中第一个地址所指向的数据开始赋值,直到赋值n个数据,该函数调用结束,同时返回dest,即返回被赋值的内存的起始位置。返回dest的意义是可是增加链接属性。 memcpy函数实现 : (my_memcpy) 原谅小编没有找到源代码 #include <assert.h> //包含assert函数的头文件 #define my_type int //自己定义要进行内存赋值的数据类型 ​ my_type * my_memcpy ( my_table * dest , const my_type * src , size_t n ) { my_type * start = dest ; //用于返回dest的初始地址,使该函数具有链接属性 assert ( dest != NULL ); //断言dest与src不是空地址 assert ( src != NULL ); while ( n -- ) { * dest ++ = * src ++ ; } return start ; }