ralgo-test-util
競プロでランダムテストするのに便利そうな関数たち.
assert_cmd とかを使うほうが正しいと思います.
[!IMPORTANT]
cargo test -- --nocaptureのように--nocaptureを渡すか, nightly を使う必要があります
なぜ
- ランダムテストを書く為に解答ファイルを書き換えるのは面倒
- できれば同じプロセス内で実行したい
proptest と共に使う例
WA なコードとナイーブなコードを比較して WA になる入力ケースを探すには, 次のような感じのテストを書けばよい.
// 中身は
// pub fn main() {
// proconio::input! { a: i32, b: i32 }
// println!("{}", a.wrapping_add(b));
// }
// . `main` の `pub` に注意.
proptest!
RE なコードから RE する入力ケースを探すには, 次のような感じ.
// 中身は
// pub fn main() {
// proconio::input! { a: i32, b: i32 }
// println!("{}", a + b);
// }
// . `main` の `pub` に注意.
proptest!
proptest を使わない例
代わりに prop_ prefix の無いマクロを使う.