assert

Crashing threads with *(int*)NULL = 1; problematic?

Deadly 提交于 2019-12-06 03:53:42
问题 I found this in a multi-threaded c application. The authors commented that it's used to make a thread crash in a custom assert function. GCC is fine with it, but clang issues the following warning: note: consider using __builtin_trap() or qualifying pointer with 'volatile' and also issues one of those, for each usage of the assert function: warning: indirection of non-volatile null pointer will be deleted, not trap What is going on here? Is __builtin_trap specific to clang? Should I use it?

Assertions in Fortran

无人久伴 提交于 2019-12-06 03:47:27
问题 Does Fortran have a standard function/keyword equivalent for C assert ? I could not find assert mentioned in Fortran2003 standard I have. I have found few ways how to use pre-processor, but in this answer it is suggested to write own assertions. Is it possible to create such user function/subroutine without using pre-processor? I expect that these assertions are disabled for release builds. 回答1: To my knowledge, there is no such statement or function/subroutine in Standard Fortran. But - as

Mysterious malloc: sysmalloc: Assertion failed error

筅森魡賤 提交于 2019-12-06 02:29:50
问题 I am getting a mysterious error and I have no idea why. This code runs several times before failing, and it always fails at the same point. Here is my code: assert(size > 0); int* sorted = malloc(size * sizeof(int)); And here is the error I am getting when I run it: malloc.c:2369: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((_

pytest

倾然丶 夕夏残阳落幕 提交于 2019-12-06 02:17:47
快速入门 pytest是Python的单元测试框架,同自带的unittest框架类似,但pytest框架使用起来更简洁,效率更高。 pytest特点 入门简单易上手,文档支持较好。 支持单元测试和功能测试。 支持参数化。 可以跳过指定用例,或对某些预期失败的case标记成失败。 支持重复执行失败的case。 支持运行由unittest编写的测试用例。 有很多第三方插件,并且可自定义扩展。 方便和支持集成工具进行集成。 安装 pip install pytest 测试 C:\Users\Anthony>pytest --version This is pytest version 5.2.2, imported from c:\python36\lib\site-packages\pytest.py 在测试之前要做的准备 演示脚本处于这样一个的目录中: M:\py_tests\ # 我的是M盘的 py_tests 目录,所有操作都在 py_tests 目录内完成 ├─scripts │ ├─test_case_dir1 │ │ ├─test_case_02.py # 用例脚本文件 │ │ └─__init__.py │ ├─test_allure_case.py # 脚本文件 │ ├─test_case_01.py # 脚本文件 │ └─__init__.py ├─report │

断言(assert)

守給你的承諾、 提交于 2019-12-06 02:02:51
断言是编程术语,表示为一些布尔表达式,程序员相信在程序中的某个特定点该表达式值为真,可以在任何时候启用和禁用断言验证,因此可以在测试时启用断言而在部署时禁用断言。 简单点说,断言指的就是,将结果判断说明,如卖西瓜的老大爷指着他家的西瓜说这个就是一个西瓜,那么这个断言就会成立。但是卖西瓜的老大爷指着他家的西瓜说我卖的西瓜都是世界上NO.1 的甜。那么我们知道这存在很大的不确定性,所以这个断言就不会成立。Java使用断言的关键字是assert。IDEA,JavaSE工程需要开启断言功能  参考地址:https://www.cnblogs.com/noKing/p/7978092.html方式一: private static void test1() { String str = null; /* assert str != null; 等同于: if (str == null) throw new AssertionError(); */ assert str != null; System.out.println("str = " + str); } 运行效果: 方式二: private static void test2() { String str = null; /* 等同于: if (str == null) throw new AssertionError("我是:" +

Difference between java ' assert 'and ' if () {} else exit;'

我们两清 提交于 2019-12-06 01:56:50
问题 what is the difference between java assert and if () {} else exit; ? can i just use if () {} else exit instead of assert ? 回答1: A bit of google maybe ? " The main thing you should keep in mind is that the if-else statement should be used for program flow control and the assert keyword should only be used for testing purposes. You should never use asserts to actually perform any operation required for your application to work properly. According to Sun's official Java documentation: "Each

顺序表

≯℡__Kan透↙ 提交于 2019-12-06 01:16:16
顺序表的1基本操作的代码在下文都有,并且经过初步测试,如果有大佬发现不对的地方,还望多多指正,谢谢。 1.线性表 线性表:n个具有相同特性的数据元素的有限序列。 线性表是一种在实际中广泛使用的数据结 构,常见的线性表:顺序表、链表、栈、队列、字符串... 线性表在逻辑上是线性结构,也就说是连续的一条直线。但是在物理结构上并不一定是连续的,线性表在物 理上存储时,通常以数组和链式结构的形式存储。(画图没弄整齐--^_^--) 顺序表: 基本内容如图: 1概念及结构 顺序表是用一段物理地址连续的存储单元依次存储数据元素的线性结构,一般情况下采用数组存储。在数组 上完成数据的增删查改。 顺序表一般可以分为: 1. 静态顺序表:使用定长数组存储。 2. 动态顺序表:使用动态开辟的数组存储 #define Capacity 100 typedef int DataType; //表中保存的数据类型,在前面用typedef关键字再给类型名,方便一改全改 struct SeqList{ DataType array[Capacity]; //保存顺序表中元素,Capacity是数组总容量 size_t size; //记录有效元素个数 }; 静态顺序表实质就是固定容量的数组加一个有效元素计数。 顺序表的具体操作以动态顺序表来展示: typedef int DataType; //存放的数据类型

关于stm32f10x_conf.h文件

给你一囗甜甜゛ 提交于 2019-12-06 00:56:09
简介 stm32f10x_conf.h文件有2个作用: ①提供对assert_param运行时参数检查宏函数的定义。 ②将开发者用到的标准外设头文件集中在这个文件里面,而stm32f10x_conf.h又被包含到stm32f10x.h中去了,因此方便开发者在写自己的库时,只需一股脑的包含stm32f10x.h就行了。 我本人是强烈不推荐第②功能。一个合格的C开发者应该知道它在写一个模块时,需要包含什么头文件,不需要包含什么头文件。而第②功能的做法就是,不管你用不用,我都全部包含进去。包含不会用到的头文件一般不是什么错误,但是它会影响代码的编译速度,代码的整洁和可读性。而他的第①功能又可有可无,因此我很早就打算将这个文件从工程中删除了。 本文主要介绍,在使用ST提供的标准外设驱动库V3.5.0开发stm32项目时,如何从工程中删除这个头文件,而又不影响正常开发。 关于assert_param ST提供的标准外设库V3.5.0在实现时,为了防止用户传递的参数不合法,大量使用了 运行时断言 。这个断言函数名为assert_param。 例如库中的GPIO_ReadInputData函数: uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx) { /* Check the parameters */ assert_param(IS_GPIO

llt

送分小仙女□ 提交于 2019-12-05 22:11:34
Junit 使用方法 在需要测试的方法上加@Test注解即可 import static org.junit.jupiter.api.Assertions.assertEquals; ​ import org.junit.jupiter.api.Test; ​ class FirstJUnit5Tests { ​ @Test void myFirstTest() { assertEquals(2, 1 + 1); } } 注解 注解 描述 @Test 表示方法是测试方法。与JUnit4的@Test注解不同的是,这个注解没有声明任何属性,因为JUnit Jupiter中的测试扩展是基于他们自己的专用注解来操作的。除非被覆盖,否则这些方法可以继承。 @ParameterizedTest 表示方法是参数化测试。 除非被覆盖,否则这些方法可以继承。 @RepeatedTest 表示方法是用于重复测试的测试模板。除非被覆盖,否则这些方法可以继承。 @TestFactory 表示方法是用于动态测试的测试工厂。除非被覆盖,否则这些方法可以继承。 @TestInstance 用于为被注解的测试类配置测试实例生命周期。 这个注解可以继承。 @TestTemplate 表示方法是测试用例的模板,设计为被调用多次,调用次数取决于自注册的提供者返回的调用上下文。除非被覆盖,否则这些方法可以继承。

NUnit Nested Collection Comparison

瘦欲@ 提交于 2019-12-05 20:27:19
问题 Is there something similar to CollectionAssert.AreEquivalent() that works with nested collections? The following code... CollectionAssert.AreEquivalent ( new Dictionary<int, Dictionary<int, string>> { { 1, new Dictionary < int, string > { { 10, "foo" }, { 11, "bar" }, { 12, "spam" } } }, { 2, new Dictionary < int, string > { { 20, "eggs" }, { 21, "eels" } } }, { 3, new Dictionary < int, string > { { 30, "hovercraft" } } } }, new Dictionary<int, Dictionary<int, string>> { { 1, new Dictionary <