summaryrefslogtreecommitdiff
path: root/learn_13/src/main.rs
diff options
context:
space:
mode:
authorBrad Clawsie <brad@b7j0c.org>2026-11-16 15:31:56 -0600
committerBrad Clawsie <brad@b7j0c.org>2026-11-16 15:31:56 -0600
commit2546c16602f2f5df9848a7aa4ef1804fe4a9e7bc (patch)
tree0f8fabe574ab0842752ea53eb271a9d6481a6a24 /learn_13/src/main.rs
parent8458a3cf35ca3b8ae2dd88d744767213c17dac41 (diff)
fix: lazy copy/paste fixes
Diffstat (limited to 'learn_13/src/main.rs')
-rw-r--r--learn_13/src/main.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/learn_13/src/main.rs b/learn_13/src/main.rs
index 635aec5..eb930c6 100644
--- a/learn_13/src/main.rs
+++ b/learn_13/src/main.rs
@@ -41,7 +41,7 @@ impl Expr {
return 1 + lhs.node_count() + rhs.node_count();
},
Expr::Negate(i) => {
- return 1 + i.depth();
+ return 1 + i.node_count();
},
}
}
@@ -55,6 +55,7 @@ fn main() {
mod tests {
use crate::*;
+ #[test]
fn test_evaluate() {
assert_eq!(Expr::Number(1).evaluate(), 1);
assert_eq!(Expr::Add(
@@ -82,6 +83,7 @@ mod tests {
assert_eq!(expr.evaluate(), -20);
}
+ #[test]
fn test_depth() {
assert_eq!(Expr::Number(1).depth(), 1);
assert_eq!(Expr::Add(
@@ -108,6 +110,7 @@ mod tests {
assert_eq!(expr.depth(), 3);
}
+ #[test]
fn test_node_count() {
assert_eq!(Expr::Number(1).node_count(), 1);
assert_eq!(Expr::Add(
@@ -120,7 +123,7 @@ mod tests {
Box::new(Expr::Number(2))).node_count(),
3);
assert_eq!(Expr::Negate(
- Box::new(Expr::Number(1))).depth(),
+ Box::new(Expr::Number(1))).node_count(),
2);
let expr = Expr::Multiply(
Box::new(Expr::Add(