mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-22 14:13:28 +08:00
Initial commit.
This commit is contained in:
8
adder/Cargo.toml
Normal file
8
adder/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "adder"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
17
adder/src/lib.rs
Normal file
17
adder/src/lib.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
pub fn add_two(a: i32) -> i32 {
|
||||
internal_add(a, 2)
|
||||
}
|
||||
|
||||
fn internal_add(a: i32, b: i32) -> i32 {
|
||||
a + b
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn internal() {
|
||||
assert_eq! (4, internal_add(2, 2));
|
||||
}
|
||||
}
|
||||
3
adder/tests/common/mod.rs
Normal file
3
adder/tests/common/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub fn setup() {
|
||||
println! ("特定于库测试的一些设置代码,将放在这里");
|
||||
}
|
||||
9
adder/tests/integration_test.rs
Normal file
9
adder/tests/integration_test.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use adder;
|
||||
|
||||
mod common;
|
||||
|
||||
#[test]
|
||||
fn it_adds_two() {
|
||||
common::setup();
|
||||
assert_eq! (6, adder::add_two(4));
|
||||
}
|
||||
Reference in New Issue
Block a user