Moved tests inside the designated tests module for every problem
This commit is contained in:
parent
e4dbd39192
commit
0819e90e80
26 changed files with 431 additions and 275 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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), "");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<Vec<i32>>::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::<Vec<i32>>::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test3() {
|
||||
assert_eq!(Solution::three_sum(vec![0,0,0]), vec![vec![0,0,0]]);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<String>::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::<String>::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test3() {
|
||||
assert_eq!(Solution::letter_combinations("2".to_string()), vec!["a","b","c"]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<Vec<i32>>::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::<Vec<i32>>::new());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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!["()"]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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![]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
24
src/p25_reverse_nodes_in_k_group.rs
Normal file
24
src/p25_reverse_nodes_in_k_group.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use crate::linked_list::ListNode;
|
||||
|
||||
pub struct Solution;
|
||||
impl Solution {
|
||||
pub fn reverse_k_group(mut head: Option<Box<ListNode>>, k: i32) -> Option<Box<ListNode>> {
|
||||
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]);
|
||||
}
|
||||
}
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue