initial commit
This commit is contained in:
4
exercises/04_traits/03_operator_overloading/Cargo.toml
Normal file
4
exercises/04_traits/03_operator_overloading/Cargo.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "overloading"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
85
exercises/04_traits/03_operator_overloading/src/lib.rs
Normal file
85
exercises/04_traits/03_operator_overloading/src/lib.rs
Normal file
@@ -0,0 +1,85 @@
|
||||
use std::cmp::PartialEq;
|
||||
|
||||
struct Ticket {
|
||||
title: String,
|
||||
description: String,
|
||||
status: String,
|
||||
}
|
||||
|
||||
// TODO: Implement the `PartialEq` trait for `Ticket`.
|
||||
|
||||
impl PartialEq for Ticket {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_partial_eq() {
|
||||
let title = "title";
|
||||
let description = "description";
|
||||
let status = "To-Do";
|
||||
let ticket1 = Ticket {
|
||||
title: title.to_string(),
|
||||
description: description.to_string(),
|
||||
status: status.to_string(),
|
||||
};
|
||||
let ticket2 = Ticket {
|
||||
title: title.to_string(),
|
||||
description: description.to_string(),
|
||||
status: status.to_string(),
|
||||
};
|
||||
assert!(ticket1 == ticket2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_description_not_matching() {
|
||||
let title = "title";
|
||||
let status = "To-Do";
|
||||
let ticket1 = Ticket {
|
||||
title: title.to_string(),
|
||||
description: "description".to_string(),
|
||||
status: status.to_string(),
|
||||
};
|
||||
let ticket2 = Ticket {
|
||||
title: title.to_string(),
|
||||
description: "description2".to_string(),
|
||||
status: status.to_string(),
|
||||
};
|
||||
assert!(ticket1 != ticket2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_title_not_matching() {
|
||||
let status = "To-Do";
|
||||
let description = "description";
|
||||
let ticket1 = Ticket {
|
||||
title: "title".to_string(),
|
||||
description: description.to_string(),
|
||||
status: status.to_string(),
|
||||
};
|
||||
let ticket2 = Ticket {
|
||||
title: "title2".to_string(),
|
||||
description: description.to_string(),
|
||||
status: status.to_string(),
|
||||
};
|
||||
assert!(ticket1 != ticket2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_status_not_matching() {
|
||||
let title = "title";
|
||||
let description = "description";
|
||||
let ticket1 = Ticket {
|
||||
title: title.to_string(),
|
||||
description: description.to_string(),
|
||||
status: "status".to_string(),
|
||||
};
|
||||
let ticket2 = Ticket {
|
||||
title: title.to_string(),
|
||||
description: description.to_string(),
|
||||
status: "status2".to_string(),
|
||||
};
|
||||
assert!(ticket1 != ticket2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user