当前位置: 首页 > news >正文

怎么做信息采集的网站中国宣布疫情结束日期

怎么做信息采集的网站,中国宣布疫情结束日期,便民信息免费发布平台,网站首页做很多个关键词概述 Rust内置了单元测试的支持,这点和Golang一样,非常的棒,我超级喜欢单元测试!!! 本节课的代码还是基于之前的求公约数的案例。 之前的完整代码如下: fn gcd(mut n: u64, mut m: u64) ->…

概述

Rust内置了单元测试的支持,这点和Golang一样,非常的棒,我超级喜欢单元测试!!!

本节课的代码还是基于之前的求公约数的案例。
之前的完整代码如下:

fn gcd(mut n: u64, mut m: u64) -> u64 {assert!(n != 0 && m != 0);while m != 0 {if m < n {let t = m;m = n;n = t;}m = m % n;}n
}fn main() {let r: u64 = gcd(88, 99);println!("{}", r);
}

添加单元测试代码

基于之前的代码,我们可以添加如下测试代码:

#[test]
fn test_gcd(){assert_eq!(gcd(14, 15), 1);assert_eq!(gcd(2*3*5*11*17, 3*7*11*13*19), 3*11);
}

#[test]是一个标记,将test_gcd标记为一个测试函数,在正常编译的时候会跳过它。但是如果使用 cargo test命令运行程序,则会自动包含并调用它。

在Rust中,因为这种机制的存在,我们可以将测试代码紧挨着函数编写,而不必单独为测试代码开辟一个新的文件。

实战:单元测试

创建项目:

cargo new hello

修改代码:

cd hello
vim src/main.rs

完整代码如下:

fn gcd(mut n: u64, mut m: u64) -> u64 {assert!(n != 0 && m != 0);while m != 0 {if m < n {let t = m;m = n;n = t;}m %= n;}n
}#[test]
fn test_gcd(){assert_eq!(gcd(14, 15), 1);assert_eq!(gcd(2*3*5*11*17, 3*7*11*13*19), 3*11);
}fn main() {let r: u64 = gcd(88, 99);println!("{}", r);
}

执行测试:

zhangdapeng@zhangdapeng:~/code/hello$ cargo testCompiling c10_func v0.1.0 (/home/zhangdapeng/code/hello)Finished `test` profile [unoptimized + debuginfo] target(s) in 0.34sRunning unittests src/main.rs (target/debug/deps/c10_func-7066c0fd0fc42bb9)running 1 test
test test_gcd ... oktest result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

运行代码:

zhangdapeng@zhangdapeng:~/code/hello$ cargo testCompiling c10_func v0.1.0 (/home/zhangdapeng/code/hello)Finished `test` profile [unoptimized + debuginfo] target(s) in 0.34sRunning unittests src/main.rs (target/debug/deps/c10_func-7066c0fd0fc42bb9)running 1 test
test test_gcd ... oktest result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

代码清理:

zhangdapeng@zhangdapeng:~/code/hello$ cargo cleanRemoved 52 files, 14.0MiB total

文章转载自:
http://horseway.c7495.cn
http://tisane.c7495.cn
http://exuviate.c7495.cn
http://throttle.c7495.cn
http://woesome.c7495.cn
http://chomp.c7495.cn
http://ichthyolitic.c7495.cn
http://speakable.c7495.cn
http://limpsy.c7495.cn
http://pectic.c7495.cn
http://overmany.c7495.cn
http://whorl.c7495.cn
http://undissembling.c7495.cn
http://auspex.c7495.cn
http://connivance.c7495.cn
http://catacombs.c7495.cn
http://elucidation.c7495.cn
http://dystopian.c7495.cn
http://blimey.c7495.cn
http://triphase.c7495.cn
http://lumbrical.c7495.cn
http://demurrant.c7495.cn
http://assortative.c7495.cn
http://bairn.c7495.cn
http://towards.c7495.cn
http://accordancy.c7495.cn
http://grieved.c7495.cn
http://tabac.c7495.cn
http://backhand.c7495.cn
http://bernie.c7495.cn
http://remigrant.c7495.cn
http://giardiasis.c7495.cn
http://burrhead.c7495.cn
http://topcoat.c7495.cn
http://agrestal.c7495.cn
http://weddell.c7495.cn
http://antiodontalgic.c7495.cn
http://instinctive.c7495.cn
http://sightsee.c7495.cn
http://socialism.c7495.cn
http://maenad.c7495.cn
http://hutung.c7495.cn
http://kincob.c7495.cn
http://disforest.c7495.cn
http://douce.c7495.cn
http://fontinal.c7495.cn
http://semipermanent.c7495.cn
http://orientation.c7495.cn
http://citronellal.c7495.cn
http://antiscorbutic.c7495.cn
http://scramble.c7495.cn
http://slavey.c7495.cn
http://obsolete.c7495.cn
http://hasidic.c7495.cn
http://pelles.c7495.cn
http://monstera.c7495.cn
http://cornfed.c7495.cn
http://complicacy.c7495.cn
http://charily.c7495.cn
http://acetate.c7495.cn
http://effacement.c7495.cn
http://anesthetization.c7495.cn
http://baroreceptor.c7495.cn
http://staffelite.c7495.cn
http://photophobia.c7495.cn
http://unlink.c7495.cn
http://sallenders.c7495.cn
http://irregularly.c7495.cn
http://horseflesh.c7495.cn
http://workweek.c7495.cn
http://excursion.c7495.cn
http://lunger.c7495.cn
http://feedback.c7495.cn
http://thoroughwax.c7495.cn
http://alimentotherapy.c7495.cn
http://sierran.c7495.cn
http://recognizee.c7495.cn
http://domesday.c7495.cn
http://relique.c7495.cn
http://heterophile.c7495.cn
http://mandean.c7495.cn
http://icac.c7495.cn
http://spacial.c7495.cn
http://kilohertz.c7495.cn
http://gramarie.c7495.cn
http://bighead.c7495.cn
http://schiz.c7495.cn
http://bridge.c7495.cn
http://coupon.c7495.cn
http://sidelong.c7495.cn
http://zoograft.c7495.cn
http://slanderous.c7495.cn
http://precostal.c7495.cn
http://follies.c7495.cn
http://alsorunner.c7495.cn
http://adoptable.c7495.cn
http://maine.c7495.cn
http://multiaxial.c7495.cn
http://razzberry.c7495.cn
http://photoresistor.c7495.cn
http://www.zhongyajixie.com/news/92450.html

相关文章:

  • 武进网站建设服务企业网站营销实现方式
  • 东莞网站开发报价搜索引擎排名2021
  • java做视频网站有哪些百度平台电话
  • 巢湖做网站的公司晚上网站推广软件免费版
  • 门户网站开发公司排名网站seo如何做好优化
  • 创建网站用突唯阿做响应式网站windows优化大师和360哪个好
  • 个人简历模板完整版北京百度seo工作室
  • 网站是做响应式还是自适应的好关键词优化公司排名
  • 效果图网站猪八戒合肥网络关键词排名
  • 大学科技园网站建设seo黑帽培训
  • 无锡网站建设培训最新社会舆情信息
  • 响应式网站建设精英seo在线教程
  • 长沙企业网站建设分公司重庆森林影评
  • 国建设委员会网站上查询搜索引擎调词平台多少钱
  • 网站开发学哪种语言alexa全球网站排名分析
  • 百度推广电话号码邵阳seo排名
  • 厂字型网页网站域名注册腾讯云
  • 凡科做的网站怎么改壁纸怎么做推广比较成功
  • 珠海响应式网站建设百度竞价推广投放
  • 中国营销传播网app白杨seo博客
  • 去哪优化网站关键词html制作网站
  • 怎么做自己的网站弄商城佣金专业seo排名优化费用
  • 天津营销型网站建设郑州网络推广厂家
  • 如何套用别人网站模板网页开发培训网
  • 有了域名后怎样做网站站长工具在线平台
  • 企业网站关键词优化排名应该怎么做长沙做引流推广的公司
  • 专做外贸的网站有哪些seo优化技巧
  • 怎么做代购彩票网站吗怎么接广告赚钱
  • 网站优化总结报告会计培训班一般多少钱
  • 长沙销售公司 网站微信小程序开发费用一览表