Rust中的测试用例的写法
有点类似
#[derive(Debug)] pub struct Rectangle { length: u32, width: u32, } impl Rectangle { pub fn can_hold(&self, other: &Rectangle) -> bool { self.length > other.length && self.width > other.width } } pub fn add_two(a: i32) -> i32 { a + } pub fn greeting(name: &str) -> String { format!("Hello {}!", name) } pub struct Guess { value: i32, } impl Guess { pub fn new(value: i32) -> Guess { { panic!("Guess value must be great than or equal 1, got {}.", value); } { panic!("Guess value must less than or equal to 100, got {}.", value); } Guess { value } } } #[cfg(test)] mod tests { use super::*; #[test] fn larger_can_hold_smaller() { let larger = Rectangle { length: , width: }; let smaller = Rectangle { length: , width: }; assert!(larger.can_hold(&smaller)); } #[test] fn smaller_cannot_hold_larger() { let larger = Rectangle { length: , width: }; let smaller = Rectangle { length: , width: }; assert!(!smaller.can_hold(&larger)); } #[test] fn it_add_two() { assert_eq!(, add_two()); } #[test] fn greeting_contains_name() { let result = greeting("Carol"); assert!(result.contains("Carol")); } #[test] #[should_panic(expected = "Guess value must be less than or equal to 100")] fn greater_than_100() { Guess::); } /* #[test] fn it_works() -> Result<(), String> { if 2 + 2 == 4 { Ok(()) } else { Err(String::from("two plus two does not equal four")) } } */ }
Rust中的测试用例的写法的更多相关文章
- Rust 中的类型转换
1. as 运算符 as 运算符有点像 C 中的强制类型转换,区别在于,它只能用于原始类型(i32 .i64 .f32 . f64 . u8 . u32 . char 等类型),并且它是安全的. 例 ...
- 刷完欧拉计划中难度系数为5%的所有63道题,我学会了Rust中的哪些知识点?
我为什么学Rust? 2019年6月18日,Facebook发布了数字货币Libra的技术白皮书,我也第一时间体验了一下它的智能合约编程语言MOVE,发现这个MOVE是用Rust编写的,看来想准确理解 ...
- ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法
ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法 语法 第一种: 通过使用Oracle语句块 --指定文档所有部门都能查看 declare cursor TABLE_DEPT and ...
- Rust 中的继承与代码复用
在学习Rust过程中突然想到怎么实现继承,特别是用于代码复用的继承,于是在网上查了查,发现不是那么简单的. C++的继承 首先看看c++中是如何做的. 例如要做一个场景结点的Node类和一个Sprit ...
- web工程中URL地址的写法
在开发中我们不可避免的要碰到许多需要写URL地址的情况,这常常让我们感到头疼.下面笔者推荐一种简单的做法.URL地址分为绝对路径和相对路径两种.相对路径又分为相对资源路径和相对根路径.显然绝对路径在开 ...
- jQuery 1.4.4 中 function( window, undefined ) 写法原因
读 jQuery 1.4.4 版本代码的时候,发现下面的写法: (function( window, undefined ) { ... // code goes here })(window); w ...
- 关于 jQuery中 function( window, undefined ) 写法的原因
今天在读 jQuery 源码的时候,发现下面的写法: (function(window,undefined){ ...// code goes here })(window); window 作为参数 ...
- C++<algorithm>中sort的比较函数写法(转)
转自:http://www.wl566.com/biancheng/98907.html C++<algorithm>中sort的比较函数写法,有需要的朋友可以参考下. 定义排序函数: 方 ...
- QT中.pro文件的写法
QT中.pro文件的写法 qmake 变量 含义 #xxxx 注释, 从“#”开始,到这一行结束 SOURCES 指定源文件 SOURCES = *.cpp 对于多源文件,可用空格分开 SOURC ...
随机推荐
- vue之tab切换
<style> .active{ color: red; } div a{ display: block; } </style> <script src="ht ...
- 2019牛客多校(第一场)F-Random Point in Triangle
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct Point{ ll x, y; Poi ...
- 简述ECMAScript6新增特性
1.变量 var 可以重复声明.只有函数级的作用域.存在变量提升 let 不能重复声明.有块级作用域.没有变量提升.变量 const 不能重复声明.具有块级作用域.常量 2.箭头函数 a.为了方便而存 ...
- 鲜贝7.3--Xshell安装
安装包百度云下载地址:https://blog.csdn.net/yueruitao/article/details/85263968 具体方法请参考: https://blog.csdn.net/q ...
- FT_Get_Var error on comiling
[Julian@julian-linux-t450 gtk]$ gcc `pkg-config --cflags gtk+-.` -o exam00 exam00.c `pkg-config --li ...
- Linux学习笔记-第18天 有点迷茫。。
有点迷茫学的这些知识的实用性..但愿今天可以用得到这些吧
- Python中的赋值、深拷贝与浅拷贝(内存地址)
Python中的赋值.深拷贝与浅拷贝(内存地址) 1.python中的可变对象与不可变对象 (1) 可变对象:dict,list def dict_test(): a = {} b = a print ...
- D3D9.0管线图
详见:pipeline-9.0.png
- Kubernetes DaemonSet(部署守护进程)
Kubernetes DaemonSet(部署守护进程) • 在每一个Node上运行一个Pod• 新加入的Node也同样会自动运行一个Pod 应用场景:Agent 官方文档:https://kuber ...
- springboot只能一个main方法解决办法
pom.xml修改properties,增加这行 <start-class>com.eshore.main.SpringBootStarter</start-class> 或者 ...