Skip to content

Commit faf695e

Browse files
committed
addition unit tests
1 parent a58c3dd commit faf695e

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/environment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Environment {
8888
// clojure.std functions
8989
let thread_sleep_fn = clojure_std::thread::SleepFn {};
9090
let nanotime_fn = clojure_std::time::NanoTimeFn {};
91-
91+
9292
// Hardcoded fns
9393
let lexical_eval_fn = Value::LexicalEvalFn {};
9494
// Hardcoded macros

src/rust_core/_plus_.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,37 @@ impl IFn for AddFn {
3636
)),
3737
})
3838
}
39-
}
39+
}
40+
41+
42+
#[cfg(test)]
43+
mod tests {
44+
mod plus_tests {
45+
use crate::ifn::IFn;
46+
use crate::value::Value;
47+
use std::rc::Rc;
48+
use crate::rust_core::AddFn;
49+
50+
#[test]
51+
fn plus_without_arguments_returns_zero() {
52+
let addition = AddFn {};
53+
let args = vec![];
54+
assert_eq!(Value::I32(0), addition.invoke(args));
55+
}
56+
57+
#[test]
58+
fn plus_with_one_argument_returns_identity() {
59+
let addition = AddFn {};
60+
let args = vec![Rc::new(Value::I32(5))];
61+
assert_eq!(Value::I32(5), addition.invoke(args));
62+
}
63+
64+
#[test]
65+
fn plus_with_two_argument_returns_product() {
66+
let addition = AddFn {};
67+
let args = vec![Rc::new(Value::I32(5)), Rc::new(Value::I32(6))];
68+
assert_eq!(Value::I32(11), addition.invoke(args));
69+
}
70+
71+
}
72+
}

0 commit comments

Comments
 (0)