Skip to content

Commit

Permalink
Merge pull request #45 from friendbear/develop
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
friendbear authored Aug 26, 2023
2 parents c374253 + 9414107 commit 36195e1
Show file tree
Hide file tree
Showing 34 changed files with 552 additions and 24 deletions.
96 changes: 86 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[workspace]
members = [
"examples/*",
"practice-collection/*",
"practice_collection/*",
"iriam-profile/"
]

Expand Down
2 changes: 1 addition & 1 deletion examples/l04_basic_data_type/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod test_slice {

#[test]
fn methods_2() {
let vec = vec!["abc", "def", "hij", "rst", "uvw", "xyz"];
let vec = ["abc", "def", "hij", "rst", "uvw", "xyz"];
let range = Range { start: 0, end: 6 };
let slice = &vec[range];
for chunk in slice.chunks(3) {
Expand Down
2 changes: 1 addition & 1 deletion examples/l05_control_formula/src/branch_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod test_branch_if {
} else if num == 2 {
println!("num is 2")
} else {

println!("num not 2")
}
}

Expand Down
2 changes: 0 additions & 2 deletions examples/l06_library_data_type/src/hash_set_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ mod test_hash_set_type {
}
if set_a.remove(&100) {
unreachable!();
} else {
}

set_a.retain(|&k| k.is_negative());
assert!(set_a.is_empty());
}
Expand Down
10 changes: 6 additions & 4 deletions examples/l07_function/src/result_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ mod test_result_type {
}
#[test]
fn method_get() {
assert_eq!(Ok::<&str, ()>("Ok").unwrap(), "Ok");
assert_eq!(Ok::<&str, ()>("Ok").unwrap_or("Err"), "Ok");
assert_eq!(Err::<&str, &str>("Err").unwrap_or("Err"), "Err");
assert_eq!(Err::<(), &str>("Err").unwrap_err(), "Err");
// clippy error
// https://rust-lang.github.io/rust-clippy/master/index.html#/unnecessary_literal_unwrap
//assert_eq!(Some("Some").unwrap(), "Some");
//assert_eq!(Some("Ok").unwrap_or("Err"), "Ok");
//assert_eq!(None.unwrap_or("Err"), "Err");
//assert_eq!(None.unwrap_err("Err"), "Err");

let div_value = div(10, 0);
let r = div_value.unwrap_or_else(|e| {
Expand Down
1 change: 1 addition & 0 deletions examples/l10_trait/src/generics/traits_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct CsvReaderImpl<T> {
pub phantom: PhantomData<T>,
}
impl<T> CsvReaderImpl<T> {
#[allow(dead_code)]
pub fn new() -> Self {
Self {
phantom: PhantomData,
Expand Down
2 changes: 0 additions & 2 deletions practice-collection/thread_and_async/src/lib.rs

This file was deleted.

3 changes: 0 additions & 3 deletions practice-collection/thread_and_async/src/main.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions practice_collection/testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "testing"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
[dev-dependencies]
simple_test_case = "1.2.0"
20 changes: 20 additions & 0 deletions practice_collection/testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# テスト

## testsディレクトリ

- test_module.rs を配置
- testから始まる関数が必要

> Tips:
>
> testsディレクトリからsrcディレクトリのテストターゲットをモジュールとして読み込む
```rust
mod my_module {
include!("../../src/target.rs"); // テスト対象のソース
}
#[cfg(test)]
mod simple_test {
use super::my_module::{Guest,SampleError};
}
```
13 changes: 13 additions & 0 deletions practice_collection/testing/src/document_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::target::Guest;

/// ドキュメントテスト
/// 年齢が10歳でヤンペーンでなければ500を返すことを検証する
/// ```
/// use crate::testing::document_test::calc_fee_case_01;
/// let actual = calc_fee_case_01();
/// assert_eq!(500, actual);
/// ```
pub fn calc_fee_case_01() -> u32 {
let guest = Guest::new(10, false);
guest.calc_fee().unwrap()
}
2 changes: 2 additions & 0 deletions practice_collection/testing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod target;
pub mod document_test;
Loading

0 comments on commit 36195e1

Please sign in to comment.