assert

Is it ok to use assertTrue on float and double values in JUnit?

こ雲淡風輕ζ 提交于 2019-12-01 23:03:34
I tried using the assertEquals method on a float and eclipse says that the method was depreciated. Therefore, is the following alternative acceptable? Assert.assertTrue("Total does not match expected total :", receipt.getTotal() == 32.19f); Is there a specific reason why assertEquals must not be used to compare two floats or doubles in a test? In general, what is the best way to assert the equality of two decimal values in JUnit. I am using the 4.10 release of JUnit Matthew Farwell In general you can compare primitive types with ==, but with floating point values, two values can look the same

How to choose a random element in this array only once across all declared objects in main?

▼魔方 西西 提交于 2019-12-01 22:45:29
I would like these objects to print the random names in the array only once across all the objects declared in main. My problem is that it would show the names twice or more. public class Fighters { private static String[] names = { "Terminator", "Slicer","Ninja", "cow", "Robot", "littlegirl" }; private static int id = 0; public Fighters(){ id++; name = names[(int) (Math.random() * names.length)]; } public String toString(){ return String.format(id+" Name:%-5s, name); } } In main() I have these objects Fighters a1 = new Fighters(); System.out.println(a1.toString()); Fighters a2 = new Fighters(

堆内内存与堆外内存

纵然是瞬间 提交于 2019-12-01 22:09:38
最近看Spark的 StorageLevel(存储级别) 源码的时候 看到有 useOffHeap 这个标签, 觉得有必要挖掘一下 堆内内存(on-heap memory) 堆内内存是java程序员在日常工作中解除比较多的, 可以在jvm参数中使用-Xms, -Xmx 等参数来设置堆的大小和最大值 堆内内存 = 年轻代 + 老年代 + 持久代 年轻代 (Young Generation) 存放的是新生成的对象 年轻代的目标是尽可能快速的收集掉那些生命周期短的对象 Eden 大部分对象在Eden区中生成 当Eden区满时, 依然存活的对象将被复制到Survivor区, 当一个Survivor 区满时, 此区的存活对象将被复制到另外一个Survivor区 Survivor(通常2个) 当两个 Survivor 区 都满时, 从第一个Survivor 区 被复制过来 且 依旧存活的 对象会被复制到 老年区(Tenured) Survivor 的两个区是对称的, 没有先后关系, 所有同一个区中可能同时存在从Eden复制过来的对象 和 从前一个 Survivor 复制过来的对象。 Survivor 区可以根据需要配置多个, 从而增加对象在年轻代的存在时间, 减少被放到老年代的可能。 老年代 (Old Generation) 存放了在年轻代中经历了N次垃圾回收后仍存活的对象,

How to write a c++ assert macro with a varying number of informational arguments?

本秂侑毒 提交于 2019-12-01 21:00:49
I am trying to write a macro dbgassert similar to the standard assert . In addition to what assert does, I want to dbgassert print an arbitrary number of additional parameters (containing debugging information). What I have so far is listed below, which is adapted from this SO answer . But I am having issue in my code with either variadic templates or macros. If I use at least one additional argument (the OK line), then dbgassert works as expected. But if I give no additional argument, then compilation fails (the problem line). I have some experience with variadic template programming (like

关于socket应用:一个不断监听一个进程的服务器以及发送信息的客户端 TCP的三次握手和四次挥手

帅比萌擦擦* 提交于 2019-12-01 19:40:14
大端节序:高位节放在低地址 小端节序:高位节放在高地址 PC多采用小端节序,而手机多采用大端节序,在网络传播过程中一律转换成大端节序,所以大端节序也称为网络字节序。 主要头文件#include <sys/socket.h> linux提供了四个函数来完成主机字节序和网络字节序的转换,我常用的是 #include <netinet/in.h> unsigned short int htons(unsigned short int hostshort); TCP/IP有sockaddr_in和sockaddr_in6两个专用socket地质结构体,用于IPv4和IPv6,个人常用sockaddr_in struct sockaddr_in { sa_family_t sin_family;//地址族 u_int16_t sin_port; //端口号 struct in_addr sin_addr; //IPv4地址结构体 } ; struct in_addr { u_int32_t s_addr; //IPv4地址,要用网络字节序表示 }; ||||||||||特别注意的是所有的专用socket地址类型的变量在使用的时候都需要转化为通用socket地址类型sockaddr,因为所有socket编程接口使用的地址参数的类型都是sockaddr. IP地址转换函数 对于IPv4

[TLPI] C30 Threads: Thread Synchronization

旧城冷巷雨未停 提交于 2019-12-01 19:18:41
目录 THREADS: THREAD SYNCHRONIZATION Protecting Accesses to Shared Variables: Mutexes Statically Allocated Mutexes Locking and Unlocking a Mutex Performance of Mutexes Mutex Deadlocks Dynamically Initializing a Mutex Mutex Attributes Mutex Types Signaling Changes of State: Condition Variables Statically Allocated Condition Variables Singaling and Waiting on Condition Variables Testing a Condition Variable's Predicate THREADS: THREAD SYNCHRONIZATION Protecting Accesses to Shared Variables: Mutexes The term critical section is used to refer to a section of code that accesses a shared resource and

How to see C++ stack trace for assert failure in Visual Studio 2012?

走远了吗. 提交于 2019-12-01 18:42:19
How can I see the stacktrace when my assert fails in visual studio 2012? If I am attahed to a process, it works as expected, but when I just build using F5 (debug), my assert happens, giving me the "Abort, Retry, Ignore" prompt, but I don't see my callstack in the debugger. Is there any way to enable it during debug builds, or will I always have to build and then attach to the process? My assert is just a simple assert(1 == 2) to get it to fail and see the callstack. (Reposting from comment) Pressing the Retry button will activate the debugger, allowing you to see your callstack, locals, etc.

SystemVerilog Assertion 设计、调试、测试总结(2)

谁都会走 提交于 2019-12-01 18:37:20
上一篇博客主要写了SVA的基本语法(详细),这一篇主要写SVA语法总结,以及如何查看SVA波形等。 断言assertion被放在verilog设计中,方便在仿真时查看异常情况。当异常出现时,断言会报警。一般在数字电路设计中都要加入断言,断言占整个设计的比例应不少于30%。以下是断言的语法: 1. 断言的位置 SVA的插入位置:在一个.v文件或者.sv的文件中: module ABC (); rtl 代码 SVA断言 endmodule 如: module inline( input logic clk , input logic a , input logic b , input logic [7:0] d1 , input logic [7:0] d2 , output logic [7:0] d ); always @(posedge clk) begin if(a) d <= d1; if(b) d <= d2; end property p_mutex; @(posedge clk) not (a && b); endproperty a_mutex: assert property (p_mutex); endmodule 注意:不要将SVA写在endmodule外面。 2. 断言格式 断言编写的一般格式是: 【例】断言名称1: assert property (事件1)

7可测性

女生的网名这么多〃 提交于 2019-12-01 18:32:45
1.在同一项目组或产品组内,要有一套统一的为集成测试与系统联调准备的调测开关及相 应打印函数,并且要有详细的说明。 说明:本规则是针对项目组或产品组的。 2.在同一组或产品组内,调测打印处的信息串的格式要有统一的形式。信息串中至少要有所在模块名(或源文件名)及行号。 说明:统一的调测信息格式便于集成测试。 3.编程的同时要为单元测试选择恰当的测试点,并仔细构造测试代码、测试用例,同时给出明确的注释。测试代码部分应作为(模块中的)一个子模块,以方便测试代码在模块中的安装与卸载(通过测试开关)。 说明:为单元测试而准备。 4. 在进行集成测试/系统联调之前,要构造好测试环境、测试项目及测试用例,同时仔细 分析并优化测试用例,以提高测试效率。 说明:好的测试用例应尽可能模拟出程序所遇到的边界值、各种复杂环境及一些极端情况等。 5.使用断言类发现软件问题,提高代码可测性。 说明:断言是对某种假设条件进行检查(可理解为若条件成立则无动作,否则应报告),它可以快速发现并定位软件问题,同时对系统错误进行自动报警。断言可以对在系统中隐藏很深,用其它手段极难发现的问题进行定位,从而缩短软件问题定位时间,提高系统的可测性。实际应用时,可根据具体情况灵活地设计断言。 示例:下面是 C 语言中的一个断言,用宏来设计的。(其中 NULL 为 0L) #ifdef _EXAM_ASSERT_TEST_ //

Unit Test Assert.AreEqual failed

醉酒当歌 提交于 2019-12-01 16:43:46
I have a unit test for a method which gets an object from a collection. This keeps failing and I cannot see why, so I have created a very simple test below to create 2 supplier object and test they are equal to see if I can spot the problem in my test of my code. But this test again is failing. Can anyone see or explain why? [TestMethod()] public void GetSupplierTest2() { Supplier expected = new Supplier(); expected.SupplierID = 32532; expected.SupplierName = "Test 1" Supplier actual = new Supplier(); actual.SupplierID = 32532; actual.SupplierName = "Test 1" Assert.AreEqual(expected, actual);