From 0819e90e800de340c80546fb50029449e9ee6634 Mon Sep 17 00:00:00 2001 From: erius Date: Sun, 5 May 2024 18:31:04 +0300 Subject: [PATCH] Moved tests inside the designated tests module for every problem --- src/lib.rs | 1 + src/p10_regular_expression_matching.rs | 27 ++++---- src/p11_container_with_most_water.rs | 19 ++++-- src/p12_integer_to_roman.rs | 27 ++++---- src/p13_roman_to_integer.rs | 27 ++++---- src/p14_longest_common_prefix.rs | 23 ++++--- src/p15_3sum.rs | 27 ++++---- src/p16_3sum_closest.rs | 19 ++++-- ...7_letter_combinations_of_a_phone_number.rs | 31 +++++---- src/p18_4sum.rs | 35 +++++----- src/p19_remove_nth_node_from_end_of_list.rs | 36 ++++++----- src/p1_two_sum.rs | 34 +++++----- src/p20_valid_parentheses.rs | 27 ++++---- src/p21_merge_two_sorted_lists.rs | 28 ++++---- src/p22_generate_parentheses.rs | 23 ++++--- src/p23_merge_k_sorted_lists.rs | 64 +++++++++++-------- src/p24_swap_nodes_in_pairs.rs | 28 ++++---- src/p25_reverse_nodes_in_k_group.rs | 24 +++++++ src/p2_add_two_numbers.rs | 31 +++++---- ..._substring_without_repeating_characters.rs | 27 ++++---- src/p4_median_of_two_sorted_arrays.rs | 19 ++++-- src/p5_longest_palindrome_substring.rs | 21 +++--- src/p6_zigzag_conversion.rs | 27 ++++---- src/p7_reverse_integer.rs | 27 ++++---- src/p8_string_to_integer.rs | 27 ++++---- src/p9_palindrome_number.rs | 27 ++++---- 26 files changed, 431 insertions(+), 275 deletions(-) create mode 100644 src/p25_reverse_nodes_in_k_group.rs diff --git a/src/lib.rs b/src/lib.rs index 0431c52..2369b42 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,3 +24,4 @@ pub mod p21_merge_two_sorted_lists; pub mod p22_generate_parentheses; pub mod p23_merge_k_sorted_lists; pub mod p24_swap_nodes_in_pairs; +pub mod p25_reverse_nodes_in_k_group; diff --git a/src/p10_regular_expression_matching.rs b/src/p10_regular_expression_matching.rs index 15a54d7..acd3d9a 100644 --- a/src/p10_regular_expression_matching.rs +++ b/src/p10_regular_expression_matching.rs @@ -18,17 +18,22 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::is_match("aa".to_string(), "a".to_string()), false); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::is_match("aa".to_string(), "a*".to_string()), true); -} + #[test] + fn test1() { + assert_eq!(Solution::is_match("aa".to_string(), "a".to_string()), false); + } -#[test] -fn test3() { - assert_eq!(Solution::is_match("ab".to_string(), ".*".to_string()), true); + #[test] + fn test2() { + assert_eq!(Solution::is_match("aa".to_string(), "a*".to_string()), true); + } + + #[test] + fn test3() { + assert_eq!(Solution::is_match("ab".to_string(), ".*".to_string()), true); + } } diff --git a/src/p11_container_with_most_water.rs b/src/p11_container_with_most_water.rs index 8d0a4d8..6412404 100644 --- a/src/p11_container_with_most_water.rs +++ b/src/p11_container_with_most_water.rs @@ -18,12 +18,17 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::max_area(vec![1,8,6,2,5,4,8,3,7]), 49); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::max_area(vec![1,1]), 1); + #[test] + fn test1() { + assert_eq!(Solution::max_area(vec![1,8,6,2,5,4,8,3,7]), 49); + } + + #[test] + fn test2() { + assert_eq!(Solution::max_area(vec![1,1]), 1); + } } diff --git a/src/p12_integer_to_roman.rs b/src/p12_integer_to_roman.rs index 7db55c3..4d6de0d 100644 --- a/src/p12_integer_to_roman.rs +++ b/src/p12_integer_to_roman.rs @@ -33,17 +33,22 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::int_to_roman(3), "III"); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::int_to_roman(58), "LVIII"); -} + #[test] + fn test1() { + assert_eq!(Solution::int_to_roman(3), "III"); + } -#[test] -fn test3() { - assert_eq!(Solution::int_to_roman(1994), "MCMXCIV"); + #[test] + fn test2() { + assert_eq!(Solution::int_to_roman(58), "LVIII"); + } + + #[test] + fn test3() { + assert_eq!(Solution::int_to_roman(1994), "MCMXCIV"); + } } diff --git a/src/p13_roman_to_integer.rs b/src/p13_roman_to_integer.rs index 2553427..96a21b1 100644 --- a/src/p13_roman_to_integer.rs +++ b/src/p13_roman_to_integer.rs @@ -11,17 +11,22 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::roman_to_int("III".to_string()), 3); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::roman_to_int("LVIII".to_string()), 58); -} + #[test] + fn test1() { + assert_eq!(Solution::roman_to_int("III".to_string()), 3); + } -#[test] -fn test3() { - assert_eq!(Solution::roman_to_int("MCMXCIV".to_string()), 1994); + #[test] + fn test2() { + assert_eq!(Solution::roman_to_int("LVIII".to_string()), 58); + } + + #[test] + fn test3() { + assert_eq!(Solution::roman_to_int("MCMXCIV".to_string()), 1994); + } } diff --git a/src/p14_longest_common_prefix.rs b/src/p14_longest_common_prefix.rs index 4346b90..3fe03d8 100644 --- a/src/p14_longest_common_prefix.rs +++ b/src/p14_longest_common_prefix.rs @@ -17,14 +17,19 @@ impl Solution { } } -#[test] -fn test1() { - let strs = vec!["flower".to_string(),"flow".to_string(),"flight".to_string()]; - assert_eq!(Solution::longest_common_prefix(strs), "fl"); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - let strs = vec!["dog".to_string(),"racecar".to_string(),"car".to_string()]; - assert_eq!(Solution::longest_common_prefix(strs), ""); + #[test] + fn test1() { + let strs = vec!["flower".to_string(),"flow".to_string(),"flight".to_string()]; + assert_eq!(Solution::longest_common_prefix(strs), "fl"); + } + + #[test] + fn test2() { + let strs = vec!["dog".to_string(),"racecar".to_string(),"car".to_string()]; + assert_eq!(Solution::longest_common_prefix(strs), ""); + } } diff --git a/src/p15_3sum.rs b/src/p15_3sum.rs index b3e30ab..c8adb3e 100644 --- a/src/p15_3sum.rs +++ b/src/p15_3sum.rs @@ -28,17 +28,22 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::three_sum(vec![-1,0,1,2,-1,-4]), vec![vec![-1,-1,2], vec![-1,0,1]]); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::three_sum(vec![0,1,1]), Vec::>::new()); -} + #[test] + fn test1() { + assert_eq!(Solution::three_sum(vec![-1,0,1,2,-1,-4]), vec![vec![-1,-1,2], vec![-1,0,1]]); + } -#[test] -fn test3() { - assert_eq!(Solution::three_sum(vec![0,0,0]), vec![vec![0,0,0]]); + #[test] + fn test2() { + assert_eq!(Solution::three_sum(vec![0,1,1]), Vec::>::new()); + } + + #[test] + fn test3() { + assert_eq!(Solution::three_sum(vec![0,0,0]), vec![vec![0,0,0]]); + } } \ No newline at end of file diff --git a/src/p16_3sum_closest.rs b/src/p16_3sum_closest.rs index 1d89769..f556e8c 100644 --- a/src/p16_3sum_closest.rs +++ b/src/p16_3sum_closest.rs @@ -22,12 +22,17 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::three_sum_closest(vec![-1,2,1,-4], 1), 2); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::three_sum_closest(vec![0,0,0], 1), 0); + #[test] + fn test1() { + assert_eq!(Solution::three_sum_closest(vec![-1,2,1,-4], 1), 2); + } + + #[test] + fn test2() { + assert_eq!(Solution::three_sum_closest(vec![0,0,0], 1), 0); + } } diff --git a/src/p17_letter_combinations_of_a_phone_number.rs b/src/p17_letter_combinations_of_a_phone_number.rs index 6e99723..38b24c3 100644 --- a/src/p17_letter_combinations_of_a_phone_number.rs +++ b/src/p17_letter_combinations_of_a_phone_number.rs @@ -23,19 +23,24 @@ impl Solution { } } -#[test] -fn test1() { - let mut actual = Solution::letter_combinations("23".to_string()); - actual.sort(); - assert_eq!(actual, vec!["ad","ae","af","bd","be","bf","cd","ce","cf"]); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::letter_combinations(String::new()), Vec::::new()); -} + #[test] + fn test1() { + let mut actual = Solution::letter_combinations("23".to_string()); + actual.sort(); + assert_eq!(actual, vec!["ad","ae","af","bd","be","bf","cd","ce","cf"]); + } -#[test] -fn test3() { - assert_eq!(Solution::letter_combinations("2".to_string()), vec!["a","b","c"]); + #[test] + fn test2() { + assert_eq!(Solution::letter_combinations(String::new()), Vec::::new()); + } + + #[test] + fn test3() { + assert_eq!(Solution::letter_combinations("2".to_string()), vec!["a","b","c"]); + } } diff --git a/src/p18_4sum.rs b/src/p18_4sum.rs index 67fe639..7846f17 100644 --- a/src/p18_4sum.rs +++ b/src/p18_4sum.rs @@ -35,21 +35,26 @@ impl Solution { } } -#[test] -fn test1() { - let mut actual = Solution::four_sum(vec![1,0,-1,0,-2,2], 0); - actual.iter_mut().for_each(|v| v.sort()); - assert_eq!(actual, vec![ - vec![-2,-1,1,2], vec![-2,0,0,2], vec![-1,0,0,1] - ]); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::four_sum(vec![2,2,2,2,2], 8), vec![vec![2,2,2,2]]); -} + #[test] + fn test1() { + let mut actual = Solution::four_sum(vec![1,0,-1,0,-2,2], 0); + actual.iter_mut().for_each(|v| v.sort()); + assert_eq!(actual, vec![ + vec![-2,-1,1,2], vec![-2,0,0,2], vec![-1,0,0,1] + ]); + } -#[test] -fn test3() { - assert_eq!(Solution::four_sum(vec![1000000000,1000000000,1000000000,1000000000], -294967296), Vec::>::new()); + #[test] + fn test2() { + assert_eq!(Solution::four_sum(vec![2,2,2,2,2], 8), vec![vec![2,2,2,2]]); + } + + #[test] + fn test3() { + assert_eq!(Solution::four_sum(vec![1000000000,1000000000,1000000000,1000000000], -294967296), Vec::>::new()); + } } diff --git a/src/p19_remove_nth_node_from_end_of_list.rs b/src/p19_remove_nth_node_from_end_of_list.rs index 9d8ba5d..4da02bb 100644 --- a/src/p19_remove_nth_node_from_end_of_list.rs +++ b/src/p19_remove_nth_node_from_end_of_list.rs @@ -22,22 +22,28 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::remove_nth_from_end(list![1,2,3,4,5], 2), list![1,2,3,5]); -} +#[cfg(test)] +mod tests { + use crate::linked_list::ListNode; + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::remove_nth_from_end(list![1], 1), list![]); -} + #[test] + fn test1() { + assert_eq!(Solution::remove_nth_from_end(list![1,2,3,4,5], 2), list![1,2,3,5]); + } -#[test] -fn test3() { - assert_eq!(Solution::remove_nth_from_end(list![1,2], 1), list![1]); -} + #[test] + fn test2() { + assert_eq!(Solution::remove_nth_from_end(list![1], 1), list![]); + } -#[test] -fn test4() { - assert_eq!(Solution::remove_nth_from_end(list![1,2], 2), list![2]); + #[test] + fn test3() { + assert_eq!(Solution::remove_nth_from_end(list![1,2], 1), list![1]); + } + + #[test] + fn test4() { + assert_eq!(Solution::remove_nth_from_end(list![1,2], 2), list![2]); + } } diff --git a/src/p1_two_sum.rs b/src/p1_two_sum.rs index 2b3d484..9504b15 100644 --- a/src/p1_two_sum.rs +++ b/src/p1_two_sum.rs @@ -15,21 +15,25 @@ impl Solution { } } -#[test] -fn test1() { - let actual = Solution::two_sum(vec![2,7,11,15], 9); - assert!(actual == vec![1,0] || actual == vec![0,1]); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - let actual = Solution::two_sum(vec![3,2,4], 6); - assert!(actual == vec![1,2] || actual == vec![2,1]); -} + #[test] + fn test1() { + let actual = Solution::two_sum(vec![2,7,11,15], 9); + assert!(actual == vec![1,0] || actual == vec![0,1]); + } -#[test] -fn test3() { - let actual = Solution::two_sum(vec![3,3], 6); - assert!(actual == vec![1,0] || actual == vec![0,1]); + #[test] + fn test2() { + let actual = Solution::two_sum(vec![3,2,4], 6); + assert!(actual == vec![1,2] || actual == vec![2,1]); + } + + #[test] + fn test3() { + let actual = Solution::two_sum(vec![3,3], 6); + assert!(actual == vec![1,0] || actual == vec![0,1]); + } } - \ No newline at end of file diff --git a/src/p20_valid_parentheses.rs b/src/p20_valid_parentheses.rs index 228265c..1286244 100644 --- a/src/p20_valid_parentheses.rs +++ b/src/p20_valid_parentheses.rs @@ -20,17 +20,22 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::is_valid("()".to_string()), true); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::is_valid("()[]{}".to_string()), true); -} + #[test] + fn test1() { + assert_eq!(Solution::is_valid("()".to_string()), true); + } -#[test] -fn test3() { - assert_eq!(Solution::is_valid("(]".to_string()), false); + #[test] + fn test2() { + assert_eq!(Solution::is_valid("()[]{}".to_string()), true); + } + + #[test] + fn test3() { + assert_eq!(Solution::is_valid("(]".to_string()), false); + } } diff --git a/src/p21_merge_two_sorted_lists.rs b/src/p21_merge_two_sorted_lists.rs index 55cd7cf..297f9b7 100644 --- a/src/p21_merge_two_sorted_lists.rs +++ b/src/p21_merge_two_sorted_lists.rs @@ -27,17 +27,23 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::merge_two_lists(list![1,2,4], list![1,3,4]), list![1,1,2,3,4,4]); -} +#[cfg(test)] +mod tests { + use crate::linked_list::ListNode; + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::merge_two_lists(list![], list![]), list![]); -} + #[test] + fn test1() { + assert_eq!(Solution::merge_two_lists(list![1,2,4], list![1,3,4]), list![1,1,2,3,4,4]); + } -#[test] -fn test3() { - assert_eq!(Solution::merge_two_lists(list![], list![0]), list![0]); + #[test] + fn test2() { + assert_eq!(Solution::merge_two_lists(list![], list![]), list![]); + } + + #[test] + fn test3() { + assert_eq!(Solution::merge_two_lists(list![], list![0]), list![0]); + } } diff --git a/src/p22_generate_parentheses.rs b/src/p22_generate_parentheses.rs index 2918f4a..7abf682 100644 --- a/src/p22_generate_parentheses.rs +++ b/src/p22_generate_parentheses.rs @@ -15,14 +15,19 @@ impl Solution { } } -#[test] -fn test1() { - let mut actual = Solution::generate_parenthesis(3); - actual.sort(); - assert_eq!(actual, vec!["((()))","(()())","(())()","()(())","()()()"]); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::generate_parenthesis(1), vec!["()"]); + #[test] + fn test1() { + let mut actual = Solution::generate_parenthesis(3); + actual.sort(); + assert_eq!(actual, vec!["((()))","(()())","(())()","()(())","()()()"]); + } + + #[test] + fn test2() { + assert_eq!(Solution::generate_parenthesis(1), vec!["()"]); + } } diff --git a/src/p23_merge_k_sorted_lists.rs b/src/p23_merge_k_sorted_lists.rs index 30d0728..c62c420 100644 --- a/src/p23_merge_k_sorted_lists.rs +++ b/src/p23_merge_k_sorted_lists.rs @@ -22,21 +22,27 @@ pub mod sorted_vec { } } - #[test] - fn test1() { - assert_eq!(Solution::merge_k_lists(vec![ - list![1,4,5], list![1,3,4], list![2,6] - ]), list![1,1,2,3,4,4,5,6]); - } + #[cfg(test)] + mod tests { + use crate::linked_list::ListNode; + use super::Solution; - #[test] - fn test2() { - assert_eq!(Solution::merge_k_lists(vec![]), list![]); - } + #[test] + fn test1() { + assert_eq!(Solution::merge_k_lists(vec![ + list![1,4,5], list![1,3,4], list![2,6] + ]), list![1,1,2,3,4,4,5,6]); + } - #[test] - fn test3() { - assert_eq!(Solution::merge_k_lists(vec![list![]]), list![]); + #[test] + fn test2() { + assert_eq!(Solution::merge_k_lists(vec![]), list![]); + } + + #[test] + fn test3() { + assert_eq!(Solution::merge_k_lists(vec![list![]]), list![]); + } } } @@ -71,20 +77,26 @@ pub mod binary_heap { fn cmp(&self, other: &Self) -> Ordering { self.val.cmp(&other.val) } } - #[test] - fn test1() { - assert_eq!(Solution::merge_k_lists(vec![ - list![1,4,5], list![1,3,4], list![2,6] - ]), list![1,1,2,3,4,4,5,6]); - } + #[cfg(test)] + mod tests { + use crate::linked_list::ListNode; + use super::Solution; - #[test] - fn test2() { - assert_eq!(Solution::merge_k_lists(vec![]), list![]); - } + #[test] + fn test1() { + assert_eq!(Solution::merge_k_lists(vec![ + list![1,4,5], list![1,3,4], list![2,6] + ]), list![1,1,2,3,4,4,5,6]); + } - #[test] - fn test3() { - assert_eq!(Solution::merge_k_lists(vec![list![]]), list![]); + #[test] + fn test2() { + assert_eq!(Solution::merge_k_lists(vec![]), list![]); + } + + #[test] + fn test3() { + assert_eq!(Solution::merge_k_lists(vec![list![]]), list![]); + } } } diff --git a/src/p24_swap_nodes_in_pairs.rs b/src/p24_swap_nodes_in_pairs.rs index 2cdc6b3..56811fa 100644 --- a/src/p24_swap_nodes_in_pairs.rs +++ b/src/p24_swap_nodes_in_pairs.rs @@ -18,17 +18,23 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::swap_pairs(list![1,2,3,4]), list![2,1,4,3]); -} +#[cfg(test)] +mod tests { + use crate::linked_list::ListNode; + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::swap_pairs(list![]), list![]); -} + #[test] + fn test1() { + assert_eq!(Solution::swap_pairs(list![1,2,3,4]), list![2,1,4,3]); + } -#[test] -fn test3() { - assert_eq!(Solution::swap_pairs(list![1]), list![1]); + #[test] + fn test2() { + assert_eq!(Solution::swap_pairs(list![]), list![]); + } + + #[test] + fn test3() { + assert_eq!(Solution::swap_pairs(list![1]), list![1]); + } } diff --git a/src/p25_reverse_nodes_in_k_group.rs b/src/p25_reverse_nodes_in_k_group.rs new file mode 100644 index 0000000..b3b9aa3 --- /dev/null +++ b/src/p25_reverse_nodes_in_k_group.rs @@ -0,0 +1,24 @@ +use crate::linked_list::ListNode; + +pub struct Solution; +impl Solution { + pub fn reverse_k_group(mut head: Option>, k: i32) -> Option> { + unimplemented!() + } +} + +#[cfg(test)] +mod tests { + use crate::linked_list::ListNode; + use super::Solution; + + #[test] + fn test1() { + assert_eq!(Solution::reverse_k_group(list![1,2,3,4,5], 2), list![2,1,4,3,5]); + } + + #[test] + fn test2() { + assert_eq!(Solution::reverse_k_group(list![1,2,3,4,5], 3), list![3,2,1,4,5]); + } +} diff --git a/src/p2_add_two_numbers.rs b/src/p2_add_two_numbers.rs index ce656d7..7578b2c 100644 --- a/src/p2_add_two_numbers.rs +++ b/src/p2_add_two_numbers.rs @@ -29,17 +29,24 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::add_two_numbers(list![2,4,3], list![5,6,4]), list![7,0,8]); +#[cfg(test)] +mod tests { + use crate::linked_list::ListNode; + use super::Solution; + + #[test] + fn test1() { + assert_eq!(Solution::add_two_numbers(list![2,4,3], list![5,6,4]), list![7,0,8]); + } + + #[test] + fn test2() { + assert_eq!(Solution::add_two_numbers(list![0], list![0]), list![0]); + } + + #[test] + fn test3() { + assert_eq!(Solution::add_two_numbers(list![9,9,9,9,9,9,9], list![9,9,9,9]), list![8,9,9,9,0,0,0,1]); + } } -#[test] -fn test2() { - assert_eq!(Solution::add_two_numbers(list![0], list![0]), list![0]); -} - -#[test] -fn test3() { - assert_eq!(Solution::add_two_numbers(list![9,9,9,9,9,9,9], list![9,9,9,9]), list![8,9,9,9,0,0,0,1]); -} diff --git a/src/p3_longest_substring_without_repeating_characters.rs b/src/p3_longest_substring_without_repeating_characters.rs index 3c48887..73e9f46 100644 --- a/src/p3_longest_substring_without_repeating_characters.rs +++ b/src/p3_longest_substring_without_repeating_characters.rs @@ -18,17 +18,22 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::length_of_longest_substring("abcabcbb".to_string()), 3); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::length_of_longest_substring("bbbbb".to_string()), 1); -} + #[test] + fn test1() { + assert_eq!(Solution::length_of_longest_substring("abcabcbb".to_string()), 3); + } -#[test] -fn test3() { - assert_eq!(Solution::length_of_longest_substring("pwwkew".to_string()), 3); + #[test] + fn test2() { + assert_eq!(Solution::length_of_longest_substring("bbbbb".to_string()), 1); + } + + #[test] + fn test3() { + assert_eq!(Solution::length_of_longest_substring("pwwkew".to_string()), 3); + } } diff --git a/src/p4_median_of_two_sorted_arrays.rs b/src/p4_median_of_two_sorted_arrays.rs index 4a7189f..c097cbe 100644 --- a/src/p4_median_of_two_sorted_arrays.rs +++ b/src/p4_median_of_two_sorted_arrays.rs @@ -20,12 +20,17 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::find_median_sorted_arrays(vec![1,3], vec![2]), 2.0); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::find_median_sorted_arrays(vec![1,2], vec![3,4]), 2.5); + #[test] + fn test1() { + assert_eq!(Solution::find_median_sorted_arrays(vec![1,3], vec![2]), 2.0); + } + + #[test] + fn test2() { + assert_eq!(Solution::find_median_sorted_arrays(vec![1,2], vec![3,4]), 2.5); + } } diff --git a/src/p5_longest_palindrome_substring.rs b/src/p5_longest_palindrome_substring.rs index e170242..0f48dd3 100644 --- a/src/p5_longest_palindrome_substring.rs +++ b/src/p5_longest_palindrome_substring.rs @@ -15,13 +15,18 @@ impl Solution { } } -#[test] -fn test1() { - let actual = Solution::longest_palindrome("babad".to_string()); - assert!(actual == "bab" || actual == "aba"); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::longest_palindrome("cbbd".to_string()), "bb"); + #[test] + fn test1() { + let actual = Solution::longest_palindrome("babad".to_string()); + assert!(actual == "bab" || actual == "aba"); + } + + #[test] + fn test2() { + assert_eq!(Solution::longest_palindrome("cbbd".to_string()), "bb"); + } } diff --git a/src/p6_zigzag_conversion.rs b/src/p6_zigzag_conversion.rs index f45bbbf..f178752 100644 --- a/src/p6_zigzag_conversion.rs +++ b/src/p6_zigzag_conversion.rs @@ -18,17 +18,22 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::convert("PAYPALISHIRING".to_string(), 3), "PAHNAPLSIIGYIR"); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::convert("PAYPALISHIRING".to_string(), 4), "PINALSIGYAHRPI"); -} + #[test] + fn test1() { + assert_eq!(Solution::convert("PAYPALISHIRING".to_string(), 3), "PAHNAPLSIIGYIR"); + } -#[test] -fn test3() { - assert_eq!(Solution::convert("A".to_string(), 1), "A"); + #[test] + fn test2() { + assert_eq!(Solution::convert("PAYPALISHIRING".to_string(), 4), "PINALSIGYAHRPI"); + } + + #[test] + fn test3() { + assert_eq!(Solution::convert("A".to_string(), 1), "A"); + } } diff --git a/src/p7_reverse_integer.rs b/src/p7_reverse_integer.rs index e4d752b..1acf6a2 100644 --- a/src/p7_reverse_integer.rs +++ b/src/p7_reverse_integer.rs @@ -17,17 +17,22 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::reverse(123), 321); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::reverse(-123), -321); -} + #[test] + fn test1() { + assert_eq!(Solution::reverse(123), 321); + } -#[test] -fn test3() { - assert_eq!(Solution::reverse(120), 21); + #[test] + fn test2() { + assert_eq!(Solution::reverse(-123), -321); + } + + #[test] + fn test3() { + assert_eq!(Solution::reverse(120), 21); + } } diff --git a/src/p8_string_to_integer.rs b/src/p8_string_to_integer.rs index 9b0f433..e4138bc 100644 --- a/src/p8_string_to_integer.rs +++ b/src/p8_string_to_integer.rs @@ -19,17 +19,22 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::my_atoi("42".to_string()), 42); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::my_atoi(" -42".to_string()), -42); -} + #[test] + fn test1() { + assert_eq!(Solution::my_atoi("42".to_string()), 42); + } -#[test] -fn test3() { - assert_eq!(Solution::my_atoi("4193 with words".to_string()), 4193); + #[test] + fn test2() { + assert_eq!(Solution::my_atoi(" -42".to_string()), -42); + } + + #[test] + fn test3() { + assert_eq!(Solution::my_atoi("4193 with words".to_string()), 4193); + } } diff --git a/src/p9_palindrome_number.rs b/src/p9_palindrome_number.rs index b95e9ca..14b954b 100644 --- a/src/p9_palindrome_number.rs +++ b/src/p9_palindrome_number.rs @@ -12,17 +12,22 @@ impl Solution { } } -#[test] -fn test1() { - assert_eq!(Solution::is_palindrome(121), true); -} +#[cfg(test)] +mod tests { + use super::Solution; -#[test] -fn test2() { - assert_eq!(Solution::is_palindrome(-121), false); -} + #[test] + fn test1() { + assert_eq!(Solution::is_palindrome(121), true); + } -#[test] -fn test3() { - assert_eq!(Solution::is_palindrome(10), false); + #[test] + fn test2() { + assert_eq!(Solution::is_palindrome(-121), false); + } + + #[test] + fn test3() { + assert_eq!(Solution::is_palindrome(10), false); + } }