以下の内容はhttps://shuzo-kino.hateblo.jp/entry/2024/11/19/233845より取得しました。


Rustのテスト機能をためす その2:色々やる

実際のところ

// lib.rs
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_add_positive_numbers() {
        assert_eq!(add(2, 3), 5);
    }

    #[test]
    fn test_add_negative_numbers() {
        assert_eq!(add(-2, -3), -5);
    }

    #[test]
    fn test_add_zero() {
        assert_eq!(add(0, 5), 5);
    }

    #[test]
    fn test_add_negative_and_positive() {
        assert_eq!(add(-2, 3), 1);
    }

    #[test]
    fn test_add_large_numbers() {
        assert_eq!(add(1000000, 2000000), 3000000);
    }
}

テスト実行

$ cargo test



以上の内容はhttps://shuzo-kino.hateblo.jp/entry/2024/11/19/233845より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14