summaryrefslogtreecommitdiff
path: root/adder
diff options
context:
space:
mode:
authorAdam Carpenter <53hornet@gmail.com>2019-03-27 15:32:37 -0400
committerAdam Carpenter <53hornet@gmail.com>2019-03-27 15:32:37 -0400
commit67cdcc2e12118becb823e20a40cc2687f2b8425a (patch)
treeed92c3234b89079e6d4cf36f5e80c5ffa79def48 /adder
parente25482fca375d318a39c3b54db396b0db6e0b263 (diff)
downloadlearning-rust-67cdcc2e12118becb823e20a40cc2687f2b8425a.tar.xz
learning-rust-67cdcc2e12118becb823e20a40cc2687f2b8425a.zip
Started Rust in Action MEAP.
Diffstat (limited to 'adder')
-rw-r--r--adder/Cargo.lock4
-rw-r--r--adder/Cargo.toml7
-rw-r--r--adder/src/lib.rs92
3 files changed, 0 insertions, 103 deletions
diff --git a/adder/Cargo.lock b/adder/Cargo.lock
deleted file mode 100644
index 4fb18f9..0000000
--- a/adder/Cargo.lock
+++ /dev/null
@@ -1,4 +0,0 @@
-[[package]]
-name = "adder"
-version = "0.1.0"
-
diff --git a/adder/Cargo.toml b/adder/Cargo.toml
deleted file mode 100644
index 5224ea1..0000000
--- a/adder/Cargo.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-[package]
-name = "adder"
-version = "0.1.0"
-authors = ["carpenat"]
-edition = "2018"
-
-[dependencies]
diff --git a/adder/src/lib.rs b/adder/src/lib.rs
deleted file mode 100644
index bc79931..0000000
--- a/adder/src/lib.rs
+++ /dev/null
@@ -1,92 +0,0 @@
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn it_works() -> Result<(), String> {
- if 2 + 2 == 4 {
- Ok(())
- }
- else {
- Err(String::from("two plus two does not equal four"))
- }
- }
-
- #[test]
- fn larger_can_hold_smaller() {
- let larger = Rectangle { length: 8, width: 7 };
- let smaller = Rectangle { length: 5, width: 1 };
-
- assert!(larger.can_hold(&smaller));
- }
-
- #[test]
- fn smaller_cannot_hold_larger() {
- let larger = Rectangle { length: 8, width: 7 };
- let smaller = Rectangle { length: 5, width: 1 };
-
- assert!(!smaller.can_hold(&larger));
- }
-
- #[test]
- fn it_adds_two() {
- assert_eq!(4, add_two(2));
- }
-
- #[test]
- fn it_wont_add_two() {
- assert_ne!(4, add_two(3));
- }
-
- #[test]
- fn greeting_contains_name() {
- let result = greeting("adam");
- assert!(result.contains("adam"));
- }
-
- #[test]
- #[should_panic(expected = "must be between 1 and 100")]
- fn greater_than_100() {
- Guess::new(200);
- }
-}
-
-#[derive(Debug)]
-pub struct Rectangle {
- length: u32,
- width: u32,
-}
-
-pub struct Guess {
- value: i32,
-}
-
-impl Guess {
- pub fn new(value: i32) -> Guess {
- if value < 1 || value > 100 {
- panic!("must be between 1 and 100, not {}", value);
- }
- //if value < 1 {
- // panic!("must be greater than 1, not {}", value);
- //}
- //else if value > 100 {
- // panic!("must be less than 100, not {}", value);
- //}
-
- Guess { value }
- }
-}
-
-impl Rectangle {
- pub fn can_hold(&self, other: &Rectangle) -> bool {
- self.length > other.length && self.width > other.width
- }
-}
-
-pub fn add_two(a: i32) -> i32 {
- a + 2
-}
-
-pub fn greeting(name: &str) -> String {
- format!("hello {}", name)
-}