assert

Debug.Assert(false) does not trigger in win8 Metro apps

走远了吗. 提交于 2019-12-22 04:02:16
问题 I notice Debug.Assert does not trigger in Metro apps, however, if the project is a traditional one like Console or WinForm, it does trigger. And yes, I am in Debug mode. Is it a setting not properly set in Visual Studio (11 Beta)? Or Debug.Assert is intended to be disabled in metro apps? I know many exceptions are swallowed during the execution of Metro apps, but Debug.Assert is so handy that I can't think of a reason why it should be disabled. 回答1: It does trigger, look in the Output window.

Does CMAKE_BUILD_TYPE=Release imply -DNDEBUG?

不问归期 提交于 2019-12-22 01:37:58
问题 Does CMAKE_BUILD_TYPE=Release implicitly imply -DNDEBUG? If not: isn't it reasonable to expect that this implication takes place? I want to know if following CMake code is redundant in my CMakeLists.txt : if (NOT CMAKE_BUILD_TYPE MATCHES Debug) add_definitions(-DNDEBUG) endif() 回答1: 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

How to use a C assert to make the code more secure?

梦想的初衷 提交于 2019-12-21 17:32:41
问题 Reading misc. tutorials related to SDL development I've found two different examples, doing the same thing, but in a different manner. I was wondering which of the two are you considering to be correct, judging from the perspective of code "security" and maintainability . In the first example the programmer isn't using assert at all, but the code looks OK (at least for my eye): int main(){ SDL_Surface *screen; /** Initialize SDL */ if(SDL_Init(SDL_INIT_VIDEO)!=0){ fprintf(stderr,"Unable to

Test assertions for tuples with floats

痞子三分冷 提交于 2019-12-21 13:08:40
问题 I have a function that returns a tuple that, among others, contains a float value. Usually I use assertAlmostEquals to compare those, but this does not work with tuples. Also, the tuple contains other data-types as well. Currently I am asserting every element of the tuple individually, but that gets too much for a list of such tuples. Is there any good way to write assertions for such cases? Consider this function: def f(a): return [(1.0/x, x * 2) for x in a] Now I want to write a test for it

Test assertions for tuples with floats

自古美人都是妖i 提交于 2019-12-21 13:07:45
问题 I have a function that returns a tuple that, among others, contains a float value. Usually I use assertAlmostEquals to compare those, but this does not work with tuples. Also, the tuple contains other data-types as well. Currently I am asserting every element of the tuple individually, but that gets too much for a list of such tuples. Is there any good way to write assertions for such cases? Consider this function: def f(a): return [(1.0/x, x * 2) for x in a] Now I want to write a test for it

When to use assert in client & common GWT code

陌路散爱 提交于 2019-12-21 04:13:34
问题 There are several questions on StackOverflow discussing the question of when one should use an assert statement versus throwing some exception. (Examples here, here, here, here, and here. However, I have come to suspect that the conventional wisdom of assert-versus-throw is based upon the assumption that you are running within a JVM. In the GWT universe, where your Java gets transliterated to JavaScript and runs in the context of a browser, the set of tradeoffs feels different: asserts are

When to use assert in client & common GWT code

∥☆過路亽.° 提交于 2019-12-21 04:13:32
问题 There are several questions on StackOverflow discussing the question of when one should use an assert statement versus throwing some exception. (Examples here, here, here, here, and here. However, I have come to suspect that the conventional wisdom of assert-versus-throw is based upon the assumption that you are running within a JVM. In the GWT universe, where your Java gets transliterated to JavaScript and runs in the context of a browser, the set of tradeoffs feels different: asserts are

xUnit Equivelant of MSTest's Assert.Inconclusive

元气小坏坏 提交于 2019-12-21 03:14:12
问题 What is the xUnit equivalent of the following MSTest code: Assert.Inconclusive("Reason"); This gives a yellow test result instead of the usual green or red. I want to assert that the test could not be run due to certain conditions and that the test should be re-run after those conditions have been met. 回答1: One way is to use the Skip parameter within the Fact or Theory attributes. [Fact(Skip = "It's not ready yet")] public void ReplaceTokensUnfinished() { var original = ""; var expected = "";

Asserting column(s) data type in Pandas

ε祈祈猫儿з 提交于 2019-12-20 20:21:03
问题 I'm trying to find a better way to assert the column data type in Python/Pandas of a given dataframe. For example: import pandas as pd t = pd.DataFrame({'a':[1,2,3], 'b':[2,6,0.75], 'c':['foo','bar','beer']}) I would like to assert that specific columns in the data frame are numeric. Here's what I have: numeric_cols = ['a', 'b'] # These will be given assert [x in ['int64','float'] for x in [t[y].dtype for y in numeric_cols]] This last assert line doesn't feel very pythonic. Maybe it is and I

单元测试之道(使用NUnit)

旧时模样 提交于 2019-12-20 20:12:27
首先来看下面几个场景你是否熟悉 1、你正在开发一个系统,你不断地编码-编译-调试-编码-编译-调试……终于,你负责的功能模块从上到下全部完成且编译通过!你长出一口气,怀着激动而又忐忑的心情点击界面上的按钮,顿时你刚刚的轻松感烟消云散:系统无法正常工作,你想读的数据显示不出来,你想存的东西也送不到数据库……于是,你再次回到IDE里,设断点、调试、一层一层跟踪,当你精疲力尽终于将数据送到数据库里,你又发现了其它问题,于是你继续设断点、调试、编译、调试…… 2、你狂躁地敲击着键盘和鼠标,咒骂着不断出现的bug:啊?这里怎么没返回值啊!哎?这里不该是0啊!不对啊,这里怎么没数据……你永远不知道还有多少bug,你也永远不知道你的改动会不会引入其它bug——这里有几十个甚至上百个类,几百几千个方法!我不能都照顾到啊!你感觉bugs像敲击鼹鼠游戏中的鼹鼠:打下了这个,另一个又从其它洞口露出头来…… 3、也许是毕业答辩的演示,也许是客户的审查,你小心地打开自己要演示的系统,进行着预定的操作,忽然,有个功能不能正常运行,你大汗淋漓,在答辩老师或者客户质疑且不满的目光下你试了又试,但还是于事无补……于是,答辩老师可能扭头便走,客户可能愤然离去,然后离去的还有你的学位证和项目奖金。当后来你检查代码时,发现这一切竟然只是因为一个底层工具类中一个方法输出结果为空。