summaryrefslogtreecommitdiffstats
path: root/libs/adder
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libs/adder/Cargo.toml6
-rw-r--r--libs/adder/src/lib.rs64
-rw-r--r--libs/adder/tests/common/mod.rs2
-rw-r--r--libs/adder/tests/integration_test.rs11
4 files changed, 83 insertions, 0 deletions
diff --git a/libs/adder/Cargo.toml b/libs/adder/Cargo.toml
new file mode 100644
index 0000000..9a5826a
--- /dev/null
+++ b/libs/adder/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "adder"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/libs/adder/src/lib.rs b/libs/adder/src/lib.rs
new file mode 100644
index 0000000..62f625c
--- /dev/null
+++ b/libs/adder/src/lib.rs
@@ -0,0 +1,64 @@
+#[derive(Debug)]
+struct Rectangle {
+ width: u32,
+ height: u32,
+}
+
+impl Rectangle {
+ fn can_hold(&self, other: &Rectangle) -> bool {
+ self.width > other.width && self.height > other.height
+ }
+}
+
+pub fn add(left: u64, right: u64) -> u64 {
+ left + right
+}
+
+pub fn add_two(a: u64) -> u64 {
+ a + 2
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn exploration() {
+ let result = add(2, 2);
+ assert_eq!(result, 4);
+ }
+
+ #[test]
+ fn larger_can_hold_smaller() {
+ let larger = Rectangle {
+ width: 8,
+ height: 7,
+ };
+ let smaller = Rectangle {
+ width: 5,
+ height: 1,
+ };
+
+ assert!(larger.can_hold(&smaller));
+ }
+
+ #[test]
+ fn smaller_cannot_hold_larger() {
+ let larger = Rectangle {
+ width: 8,
+ height: 7,
+ };
+ let smaller = Rectangle {
+ width: 5,
+ height: 1,
+ };
+
+ assert!(!smaller.can_hold(&larger));
+ }
+
+ #[test]
+ fn it_adds_two() {
+ let result = add_two(2);
+ assert_eq!(result, 4)
+ }
+}
diff --git a/libs/adder/tests/common/mod.rs b/libs/adder/tests/common/mod.rs
new file mode 100644
index 0000000..71a3f5a
--- /dev/null
+++ b/libs/adder/tests/common/mod.rs
@@ -0,0 +1,2 @@
+pub fn setup() {
+}
diff --git a/libs/adder/tests/integration_test.rs b/libs/adder/tests/integration_test.rs
new file mode 100644
index 0000000..d18b5b6
--- /dev/null
+++ b/libs/adder/tests/integration_test.rs
@@ -0,0 +1,11 @@
+use adder::add_two;
+
+mod common;
+
+#[test]
+fn it_adds_two() {
+ common::setup();
+
+ let result = add_two(2);
+ assert_eq!(result, 4);
+}