assert

JDK核心JAVA源码解析(1) - Object

余生长醉 提交于 2019-12-02 05:24:08
想写这个系列很久了,对自己也是个总结与提高。原来在学JAVA时,那些JAVA入门书籍会告诉你一些规律还有法则,但是用的时候我们一般很难想起来,因为我们用的少并且不知道为什么。知其所以然方能印象深刻并学以致用。 首先我们从所有类的父类Object开始: 1. Object类 (1)hashCode方法和equals方法 public native int hashCode (); public boolean equals (Object obj) { return ( this == obj); } Java内规定,hashCode方法的结果需要与equals方法一致。也就是说,如果两个对象的hashCode相同,那么两个对象调用equals方法的结果需要一致。那么也就是在以后的java程序设计中,你需要同时覆盖这两个方法来保证一致性。 在Object代码中,hashCode是native的,非java代码实现。主要原因是它的实现方法是通过将对象在内存中所处于的位置转换成数字,这个数字就是hashCode。但是这个内存地址实际上java程序并不关心也是不可知的。这个地址是由JVM维护并保存的,所以实现是native的。 如果两个Object的hashCode一样,那么就代表两个Object的内存地址一样,实际上他们就是同一个对象。所以

动态顺序表的基本操作

你离开我真会死。 提交于 2019-12-02 05:15:52
顺序表   顾名思义,就是用一段连续的存储单元依次存储数据元素的线性结构 。 顺序表又分为静态顺序表和动态顺序表。   静态顺序表的基本操作: https://blog.csdn.net/zhao_miao/article/details/81145855 下面我们来分析动态顺序表的基本操作: 我们要完成的基本操作是: 初始化 打印 尾部插入 尾部删除 头部插入 头部删除 查找指定元素 指定位置插入 删除指定位置元素 删除指定元素 删除所有的指定元素 返回顺序表的大小 判断顺序表是否为空 冒泡排序 选择排序 选择排序的优化 二分查找 二分查找递归写法 首先定义一个结构体   与静态顺序表不同,动态顺序表没有最大容量的限制,可以边使用边开辟,节省空间。 # define DataType int typedef struct SeqList { DataType *data; //存放的数据 int sz; //有效元素的个数 int capacity; //容量 }SeqList,*qSeqL   由于顺序表里存放的元素的类型是未知的,所以将int重命名为DataType,若想在顺序表中存储其他类型的数据,只需将int修改为对应的类型即可。 初始化函数   初始化sz,capacity,以及指针data void InitSeqList (qSeqList seq) {

《构建之法现代软件工程》速读笔记

为君一笑 提交于 2019-12-02 05:03:48
问题一 断言assert()函数的使用 assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行。原型定义: #include <assert.h> void assert( int expression ); assert的作用是先计算表达式 expression ,如果其值为假(即为0),那么它先向stderr打印一条出错信息,然后通过调用 abort 来终止程序运行。以下两个例子来理解assert()的使用: FILE *fp; fp = fopen( "test.txt", "w" );//以可写的方式打开一个文件,如果不存在就创建一个同名文件 assert( fp ); //所以这里不会出错 fclose( fp ); fp = fopen( "noexitfile.txt", "r" );//以只读的方式打开一个文件,如果不存在就打开文件失败 assert( fp ); //所以这里出错 fclose( fp ); //程序永远都执行不到这里来 return 0; int resetBufferSize(int nNewSize) { //功能:改变缓冲区大小, //参数:nNewSize 缓冲区新长度 //返回值:缓冲区当前长度 //说明:保持原信息内容不变 nNewSize<=0表示清除缓冲区 assert(nNewSize >

rspec - why does this attribute comparison usng assert_equal fail when they are the same, on ubuntu only?

孤街醉人 提交于 2019-12-02 04:28:34
问题 Two tests are failing - but only on Ubuntu(12) but not on my (new) Mac. The failure two are Active Record object attribute comparisons but in all my effort to compare them, e.g. making hash's at the command line and pasting the attributes in, the comparison says they are the same. A real puzzler as we have an extensive test suite with many hundreds of tests. Rails 3.2.8, rspec 2.11 Failure/Error: assert_equal @iep_service.attributes, IepService.first.attributes MiniTest::Assertion: <{"id"=

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

廉价感情. 提交于 2019-12-02 04:17:19
问题 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

接口测试加解密与多环境测试

最后都变了- 提交于 2019-12-02 03:45:36
加密方法 请求加密:摘要加密 把原文或者原始请求中的部分字段做摘要算法的加密,把加密后的结果也放到原始请求中发送。 响应加密:返回的整个响应或者响应中的部分字段被加密,我们需要找到解密办法,还有一个名字叫摘要算法。 加密与签名的区别 加密通常代表是对称加密,这种加密是可以解密的。比如base64,主要用于的数据传输。 签名通常代表是非对称加密,这种加密不可逆不可解密。比如rsa、md5。通常用于认证内容未被篡改。 解密方式 自己解决通用解密算法 需要研发提供加解密的lib 需要加密方提供远程解析服务,这样算法仍然是保密的 import base64 import json import requests class TestEnCode: origin_url = 'http://0.0.0.0:8000/json_1.txt' url = "http://0.0.0.0:8000/base64_1.txt" def test_get(self): r = requests.get(url=self.url) print(r.content) data = self.decode(r.content) j = json.loads(data) print(j) assert len(j['topics']) == 2 def test_encode(self): r =

rspec - why does this attribute comparison usng assert_equal fail when they are the same, on ubuntu only?

為{幸葍}努か 提交于 2019-12-02 02:13:22
Two tests are failing - but only on Ubuntu(12) but not on my (new) Mac. The failure two are Active Record object attribute comparisons but in all my effort to compare them, e.g. making hash's at the command line and pasting the attributes in, the comparison says they are the same. A real puzzler as we have an extensive test suite with many hundreds of tests. Rails 3.2.8, rspec 2.11 Failure/Error: assert_equal @iep_service.attributes, IepService.first.attributes MiniTest::Assertion: <{"id"=>414, "duration"=>30, "frequency"=>3, "period"=>"week", "group_size"=>"group", "location"=>nil, "service"=

python 异常处理

巧了我就是萌 提交于 2019-12-02 00:55:04
一、错误和异常 程序中难免出现错误,而错误分为两种 1、语法错误(这种错误,根本不了python解释器的语法检测,必须在程序执行前就改正) print(aaaaaa) print("aaaaaa" 2、逻辑错误(逻辑错误) if 1==1 print("sb") res = 1/0 1、什么是异常 异常就是程序运行时发生错误的信号,在python中,错误触发的异常如下: 2、python中的异常种类 在python中不同的异常可以用不同的类型(python中统一了类与类型,类型即类)去标识,不同的类对象标识不同的异常,一个异常标识一种错误 """ AttributeError 试图访问一个对象没有的树形,比如Aoo.x,但是Aoo没有属性x IoError 输入/输出异常;基本上是无法打开文件 ImportError 无法引入模块或包,基本上是路径问题或名称错误 IndentationError 语法错误,代码没有正确对齐 IndexError 下标索引超出序列边界,比如当x只有三个元素,却试图访问x[5] KeyError 试图访问字典不存在的键 KeyboardInterrupt ctrl+c被按下 NameError 使用一个还未被赋予对象的变量 SyntaxError python代码非法,代码不能编译(个人认为这是语法错误,写错了) TypeError

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

青春壹個敷衍的年華 提交于 2019-12-02 00:53: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

java bean 属性验证框架 valid

不打扰是莪最后的温柔 提交于 2019-12-02 00:09:08
项目介绍 java 开发中,参数校验是非常常见的需求。 但是 hibernate-validator 在使用过程中,依然会存在一些问题。 特性 支持 fluent-validation 支持 jsr-303 注解 支持 i18n 支持用户自定义策略 支持用户自定义注解 开源地址 valid 创作目的 hibernate-validator 无法满足的场景 如今 java 最流行的 hibernate-validator 框架,但是有些场景是无法满足的。 比如: 验证新密码和确认密码是否相同。(同一对象下的不同属性之间关系) 当一个属性值满足某个条件时,才进行其他值的参数校验。 多个属性值,至少有一个不能为 null 其实,在对于多个字段的关联关系处理时,hibernate-validator 就会比较弱。 本项目结合原有的优点,进行这一点的功能强化。 validation-api 过于复杂 validation-api 提供了丰富的特性定义,也同时带来了一个问题。 实现起来,特别复杂。 然而我们实际使用中,常常不需要这么复杂的实现。 valid-api 提供了一套简化很多的 api,便于用户自行实现。 自定义缺乏灵活性 hibernate-validator 在使用中,自定义约束实现是基于注解的,针对单个属性校验不够灵活。 本项目中,将属性校验约束和注解约束区分开,便于复用和拓展。