Compare commits
2 Commits
ec8aefc4b9
...
3db6c0baf4
Author | SHA1 | Date |
---|---|---|
David E. Perez Negron R. | 3db6c0baf4 | |
David E. Perez Negron R. | 1e91ec6f03 |
|
@ -8,9 +8,8 @@
|
||||||
// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn longest(x: &str, y: &str) -> &str {
|
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
|
||||||
if x.len() > y.len() {
|
if x.len() > y.len() {
|
||||||
x
|
x
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
// Execute `rustlings hint lifetimes2` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint lifetimes2` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
|
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
|
||||||
if x.len() > y.len() {
|
if x.len() > y.len() {
|
||||||
|
@ -22,6 +21,6 @@ fn main() {
|
||||||
{
|
{
|
||||||
let string2 = String::from("xyz");
|
let string2 = String::from("xyz");
|
||||||
result = longest(string1.as_str(), string2.as_str());
|
result = longest(string1.as_str(), string2.as_str());
|
||||||
}
|
|
||||||
println!("The longest string is '{}'", result);
|
println!("The longest string is '{}'", result);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,11 +5,10 @@
|
||||||
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
struct Book {
|
struct Book<'a> {
|
||||||
author: &str,
|
author: &'a str,
|
||||||
title: &str,
|
title: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -10,12 +10,11 @@
|
||||||
// Execute `rustlings hint tests1` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint tests1` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn you_can_assert() {
|
fn you_can_assert() {
|
||||||
assert!();
|
assert!(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,11 @@
|
||||||
// Execute `rustlings hint tests2` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint tests2` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn you_can_assert_eq() {
|
fn you_can_assert_eq() {
|
||||||
assert_eq!();
|
assert_eq!(1,1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
// Execute `rustlings hint tests3` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint tests3` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
pub fn is_even(num: i32) -> bool {
|
pub fn is_even(num: i32) -> bool {
|
||||||
num % 2 == 0
|
num % 2 == 0
|
||||||
|
@ -19,11 +18,11 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_true_when_even() {
|
fn is_true_when_even() {
|
||||||
assert!();
|
assert!(is_even(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_false_when_odd() {
|
fn is_false_when_odd() {
|
||||||
assert!();
|
assert!(!is_even(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
// Execute `rustlings hint tests4` or use the `hint` watch subcommand for a
|
// Execute `rustlings hint tests4` or use the `hint` watch subcommand for a
|
||||||
// hint.
|
// hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
struct Rectangle {
|
struct Rectangle {
|
||||||
width: i32,
|
width: i32,
|
||||||
|
@ -30,17 +29,19 @@ mod tests {
|
||||||
fn correct_width_and_height() {
|
fn correct_width_and_height() {
|
||||||
// This test should check if the rectangle is the size that we pass into its constructor
|
// This test should check if the rectangle is the size that we pass into its constructor
|
||||||
let rect = Rectangle::new(10, 20);
|
let rect = Rectangle::new(10, 20);
|
||||||
assert_eq!(???, 10); // check width
|
assert_eq!(rect.width, 10); // check width
|
||||||
assert_eq!(???, 20); // check height
|
assert_eq!(rect.height, 20); // check height
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
fn negative_width() {
|
fn negative_width() {
|
||||||
// This test should check if program panics when we try to create rectangle with negative width
|
// This test should check if program panics when we try to create rectangle with negative width
|
||||||
let _rect = Rectangle::new(-10, 10);
|
let _rect = Rectangle::new(-10, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
fn negative_height() {
|
fn negative_height() {
|
||||||
// This test should check if program panics when we try to create rectangle with negative height
|
// This test should check if program panics when we try to create rectangle with negative height
|
||||||
let _rect = Rectangle::new(10, -10);
|
let _rect = Rectangle::new(10, -10);
|
||||||
|
|
Loading…
Reference in New Issue