补上测试

This commit is contained in:
游由 2022-02-18 10:36:39 +08:00
parent c00d1781a5
commit bf65cb603f
3 changed files with 56 additions and 7 deletions

View File

@ -54,7 +54,7 @@ mod q0258;
mod q0263;
mod q0264;
mod q0268;
mod q0278;
mod q0278; //交互 没有测试
mod q0283;
mod q0289;
mod q0299;

View File

@ -4,9 +4,7 @@ use std::rc::Rc;
use std::cell::RefCell;
impl Solution {
/// 897.递增顺序搜索树
///
/// [原题链接](https://leetcode-cn.com/problems/increasing-order-search-tree/)
/// [897.递增顺序搜索树](https://leetcode-cn.com/problems/increasing-order-search-tree/)
///
/// 2021-04-25 09:47:45
///
@ -44,3 +42,30 @@ impl Solution {
make_tree(&res, 0)
}
}
#[cfg(test)]
mod test {
use crate::Solution;
use crate::structure::TreeNode;
use std::rc::Rc;
use std::cell::RefCell;
#[test]
fn test_q0897() {
let root = Some(Rc::new(RefCell::new(TreeNode{
val:5,
left:Some(Rc::new(RefCell::new(TreeNode::new(1)))),
right:Some(Rc::new(RefCell::new(TreeNode::new(7))))
})));
let ans = Some(Rc::new(RefCell::new(TreeNode{
val:1,
left:None,
right:Some(Rc::new(RefCell::new(TreeNode{
val:5,
left:None,
right:Some(Rc::new(RefCell::new(TreeNode::new(7))))
}))),
})));
assert_eq!(Solution::increasing_bst(root), ans);
}
}

View File

@ -4,9 +4,7 @@ use std::rc::Rc;
use std::cell::RefCell;
impl Solution {
/// 938.二叉搜索树的范围和
///
/// [原题链接](https://leetcode-cn.com/problems/range-sum-of-bst/)
/// [938.二叉搜索树的范围和](https://leetcode-cn.com/problems/range-sum-of-bst/)
///
/// 2021-04-27 08:29:20
///
@ -42,3 +40,29 @@ impl Solution {
}
}
}
#[cfg(test)]
mod test {
use crate::Solution;
use crate::structure::TreeNode;
use std::rc::Rc;
use std::cell::RefCell;
#[test]
fn test_q0938() {
let root = Some(Rc::new(RefCell::new(TreeNode{
val:10,
left:Some(Rc::new(RefCell::new(TreeNode{
val:5,
left:Some(Rc::new(RefCell::new(TreeNode::new(3)))),
right:Some(Rc::new(RefCell::new(TreeNode::new(7))))
}))),
right:Some(Rc::new(RefCell::new(TreeNode{
val:15,
left:None,
right:Some(Rc::new(RefCell::new(TreeNode::new(18))))
})))
})));
assert_eq!(Solution::range_sum_bst(root, 7, 15), 32);
}
}