-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...pshots/cargo_leet__tool__core__generate__tests__extract_solutions_from_description-2.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
source: src/tool/core/generate.rs | ||
expression: code_generated | ||
--- | ||
//! Solution for https://leetcode.com/problems/add-two-numbers | ||
//! 2. Add Two Numbers | ||
|
||
// Definition for singly-linked list. | ||
// #[derive(PartialEq, Eq, Clone, Debug)] | ||
// pub struct ListNode { | ||
// pub val: i32, | ||
// pub next: Option<Box<ListNode>> | ||
// } | ||
// | ||
// impl ListNode { | ||
// #[inline] | ||
// fn new(val: i32) -> Self { | ||
// ListNode { | ||
// next: None, | ||
// val | ||
// } | ||
// } | ||
// } | ||
impl Solution { | ||
pub fn add_two_numbers(l1: Option<Box<ListNode>>, l2: Option<Box<ListNode>>) -> Option<Box<ListNode>> { todo!("Fill in body") } | ||
} | ||
|
||
// << ---------------- Code below here is only for local use ---------------- >> | ||
|
||
pub struct Solution; | ||
use cargo_leet::ListNode; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use cargo_leet::ListHead; | ||
|
||
|
||
use rstest::rstest; | ||
|
||
#[rstest] | ||
#[case(ListHead::from(vec![2,4,3]).into(), ListHead::from(vec![5,6,4]).into(), ListHead::from(vec![7,0,8]).into())] | ||
#[case(ListHead::from(vec![0]).into(), ListHead::from(vec![0]).into(), ListHead::from(vec![0]).into())] | ||
#[case(ListHead::from(vec![9,9,9,9,9,9,9]).into(), ListHead::from(vec![9,9,9,9]).into(), ListHead::from(vec![8,9,9,9,0,0,0,1]).into())] | ||
fn case(#[case] l1: Option<Box<ListNode>>, #[case] l2: Option<Box<ListNode>>, #[case] expected: Option<Box<ListNode>>) { | ||
let actual = Solution::add_two_numbers(l1, l2); | ||
assert_eq!(actual, expected); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...pshots/cargo_leet__tool__core__generate__tests__extract_solutions_from_description-3.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
source: src/tool/core/generate.rs | ||
expression: code_generated | ||
--- | ||
//! Solution for https://leetcode.com/problems/validate-binary-search-tree | ||
//! 98. Validate Binary Search Tree | ||
|
||
// Definition for a binary tree node. | ||
// #[derive(Debug, PartialEq, Eq)] | ||
// pub struct TreeNode { | ||
// pub val: i32, | ||
// pub left: Option<Rc<RefCell<TreeNode>>>, | ||
// pub right: Option<Rc<RefCell<TreeNode>>>, | ||
// } | ||
// | ||
// impl TreeNode { | ||
// #[inline] | ||
// pub fn new(val: i32) -> Self { | ||
// TreeNode { | ||
// val, | ||
// left: None, | ||
// right: None | ||
// } | ||
// } | ||
// } | ||
use std::rc::Rc; | ||
use std::cell::RefCell; | ||
impl Solution { | ||
pub fn is_valid_bst(root: Option<Rc<RefCell<TreeNode>>>) -> bool { todo!("Fill in body") } | ||
} | ||
|
||
// << ---------------- Code below here is only for local use ---------------- >> | ||
|
||
pub struct Solution; | ||
use cargo_leet::TreeNode; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use cargo_leet::TreeRoot; | ||
|
||
|
||
use rstest::rstest; | ||
|
||
#[rstest] | ||
#[case(TreeRoot::from("[2,1,3]").into(), true)] | ||
#[case(TreeRoot::from("[5,1,4,null,null,3,6]").into(), false)] | ||
fn case(#[case] root: Option<Rc<RefCell<TreeNode>>>, #[case] expected: bool) { | ||
let actual = Solution::is_valid_bst(root); | ||
assert_eq!(actual, expected); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...napshots/cargo_leet__tool__core__generate__tests__extract_solutions_from_description.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
source: src/tool/core/generate.rs | ||
expression: code_generated | ||
--- | ||
//! Solution for https://leetcode.com/problems/two-sum | ||
//! 1. Two Sum | ||
|
||
impl Solution { | ||
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> { todo!("Fill in body") } | ||
} | ||
|
||
// << ---------------- Code below here is only for local use ---------------- >> | ||
|
||
pub struct Solution; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
|
||
use rstest::rstest; | ||
|
||
#[rstest] | ||
#[case(vec![2,7,11,15], 9, vec![0,1])] | ||
#[case(vec![3,2,4], 6, vec![1,2])] | ||
#[case(vec![3,3], 6, vec![0,1])] | ||
fn case(#[case] nums: Vec<i32>, #[case] target: i32, #[case] expected: Vec<i32>) { | ||
let actual = Solution::two_sum(nums, target); | ||
assert_eq!(actual, expected); | ||
} | ||
} |