From db8b151977f7defd6c8814cd904522b7e1661a74 Mon Sep 17 00:00:00 2001 From: Xu Shaohua Date: Tue, 14 Nov 2023 20:53:22 +0800 Subject: [PATCH] lc: Add unittest to two sum --- leetcode/001.two_sum/src/main.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/leetcode/001.two_sum/src/main.rs b/leetcode/001.two_sum/src/main.rs index 390a8b12..a3677943 100644 --- a/leetcode/001.two_sum/src/main.rs +++ b/leetcode/001.two_sum/src/main.rs @@ -28,3 +28,19 @@ fn main() { let target = 6; assert_eq!(solution1(nums, target), Some((0, 1))); } + +#[cfg(test)] +mod tests { + use super::solution1; + + #[test] + fn test_solution1() { + let nums = &[0, 4, 3, 0]; + let target = 0; + assert_eq!(solution1(nums, target), Some((0, 3))); + + let nums = &[-3, 4, 3, 90]; + let target = 0; + assert_eq!(solution1(nums, target), Some((0, 2))); + } +}