summaryrefslogtreecommitdiffstats
path: root/src/timetype.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-09-02 15:54:48 +0200
committerMatthias Beyer <mail@beyermatthias.de>2017-09-02 15:54:48 +0200
commita22fac81faeee936385d75132ebdfbb4e8c123e8 (patch)
tree6d1156fd0817f0d9aa9dea3e3bccd429363f21fb /src/timetype.rs
parent6ed09b627e62cf719d119dd85064188605976369 (diff)
Add add/sub tests for minutes..years
Diffstat (limited to 'src/timetype.rs')
-rw-r--r--src/timetype.rs731
1 files changed, 731 insertions, 0 deletions
diff --git a/src/timetype.rs b/src/timetype.rs
index e064f35..05ca6b3 100644
--- a/src/timetype.rs
+++ b/src/timetype.rs
@@ -239,5 +239,736 @@ mod tests {
_ => assert!(false, "Subtraction failed"),
}
}
+
+ #[test]
+ fn test_addition_of_minutes() {
+ let a = TT::Minutes(0);
+ let b = TT::Minutes(1);
+
+ let c = a + b;
+
+ match c {
+ TT::Addition(a, b) => {
+ match (*a, *b) {
+ (TT::Minutes(0), TT::Minutes(1)) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+ _ => assert!(false, "Addition failed, returned non-Addition type"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_minutes_multiple() {
+ let a = TT::Minutes(0);
+ let b = TT::Minutes(1);
+ let c = TT::Minutes(2);
+
+ let d = a + b + c;
+
+ match d {
+ TT::Addition(a, b) => {
+ match (*a, *b) {
+ (TT::Addition(c, d), TT::Minutes(2)) => match (*c, *d) {
+ (TT::Minutes(0), TT::Minutes(1)) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ },
+ (a, b) => assert!(false, "Addition failed: \n a = {:?}\n b = {:?}", a, b),
+ }
+ }
+ _ => assert!(false, "Addition failed, returned non-Addition type"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_minutes() {
+ let a = TT::Minutes(5);
+ let b = TT::Minutes(3);
+
+ let c = a - b;
+
+ match c {
+ TT::Subtraction(a, b) => {
+ match (*a, *b) {
+ (TT::Minutes(5), TT::Minutes(3)) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+ _ => assert!(false, "Subtraction failed, returned non-Subtraction type"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_minutes_multiple() {
+ let a = TT::Minutes(3);
+ let b = TT::Minutes(2);
+ let c = TT::Minutes(1);
+
+ let d = a - b - c;
+
+ match d {
+ TT::Subtraction(a, b) => {
+ match (*a, *b) {
+ (TT::Subtraction(c, d), TT::Minutes(1)) => match (*c, *d) {
+ (TT::Minutes(3), TT::Minutes(2)) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ },
+ (a, b) => assert!(false, "Subtraction failed: \n a = {:?}\n b = {:?}", a, b),
+ }
+ }
+ _ => assert!(false, "Subtraction failed, returned non-Subtraction type"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_minutes_calculate() {
+ let a = TT::Minutes(0);
+ let b = TT::Minutes(1);
+
+ let c = (a + b).calculate();
+
+ assert!(c.is_ok());
+ let c = c.unwrap();
+
+ match c {
+ TT::Minutes(1) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_minutes_multiple_calculate() {
+ let a = TT::Minutes(0);
+ let b = TT::Minutes(1);
+ let c = TT::Minutes(2);
+
+ let d = (a + b + c).calculate();
+
+ assert!(d.is_ok());
+ let d = d.unwrap();
+
+ match d {
+ TT::Minutes(3) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_minutes_calculate() {
+ let a = TT::Minutes(5);
+ let b = TT::Minutes(3);
+
+ let c = (a - b).calculate();
+
+ assert!(c.is_ok());
+ let c = c.unwrap();
+
+ match c {
+ TT::Minutes(2) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_minutes_multiple_calculate() {
+ let a = TT::Minutes(3);
+ let b = TT::Minutes(2);
+ let c = TT::Minutes(1);
+
+ let d = (a - b - c).calculate();
+
+ assert!(d.is_ok());
+ let d = d.unwrap();
+
+ match d {
+ TT::Minutes(0) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_days() {
+ let a = TT::Days(0);
+ let b = TT::Days(1);
+
+ let c = a + b;
+
+ match c {
+ TT::Addition(a, b) => {
+ match (*a, *b) {
+ (TT::Days(0), TT::Days(1)) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+ _ => assert!(false, "Addition failed, returned non-Addition type"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_days_multiple() {
+ let a = TT::Days(0);
+ let b = TT::Days(1);
+ let c = TT::Days(2);
+
+ let d = a + b + c;
+
+ match d {
+ TT::Addition(a, b) => {
+ match (*a, *b) {
+ (TT::Addition(c, d), TT::Days(2)) => match (*c, *d) {
+ (TT::Days(0), TT::Days(1)) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ },
+ (a, b) => assert!(false, "Addition failed: \n a = {:?}\n b = {:?}", a, b),
+ }
+ }
+ _ => assert!(false, "Addition failed, returned non-Addition type"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_days() {
+ let a = TT::Days(5);
+ let b = TT::Days(3);
+
+ let c = a - b;
+
+ match c {
+ TT::Subtraction(a, b) => {
+ match (*a, *b) {
+ (TT::Days(5), TT::Days(3)) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+ _ => assert!(false, "Subtraction failed, returned non-Subtraction type"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_days_multiple() {
+ let a = TT::Days(3);
+ let b = TT::Days(2);
+ let c = TT::Days(1);
+
+ let d = a - b - c;
+
+ match d {
+ TT::Subtraction(a, b) => {
+ match (*a, *b) {
+ (TT::Subtraction(c, d), TT::Days(1)) => match (*c, *d) {
+ (TT::Days(3), TT::Days(2)) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ },
+ (a, b) => assert!(false, "Subtraction failed: \n a = {:?}\n b = {:?}", a, b),
+ }
+ }
+ _ => assert!(false, "Subtraction failed, returned non-Subtraction type"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_days_calculate() {
+ let a = TT::Days(0);
+ let b = TT::Days(1);
+
+ let c = (a + b).calculate();
+
+ assert!(c.is_ok());
+ let c = c.unwrap();
+
+ match c {
+ TT::Days(1) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_days_multiple_calculate() {
+ let a = TT::Days(0);
+ let b = TT::Days(1);
+ let c = TT::Days(2);
+
+ let d = (a + b + c).calculate();
+
+ assert!(d.is_ok());
+ let d = d.unwrap();
+
+ match d {
+ TT::Days(3) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_days_calculate() {
+ let a = TT::Days(5);
+ let b = TT::Days(3);
+
+ let c = (a - b).calculate();
+
+ assert!(c.is_ok());
+ let c = c.unwrap();
+
+ match c {
+ TT::Days(2) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_days_multiple_calculate() {
+ let a = TT::Days(3);
+ let b = TT::Days(2);
+ let c = TT::Days(1);
+
+ let d = (a - b - c).calculate();
+
+ assert!(d.is_ok());
+ let d = d.unwrap();
+
+ match d {
+ TT::Days(0) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_weeks() {
+ let a = TT::Weeks(0);
+ let b = TT::Weeks(1);
+
+ let c = a + b;
+
+ match c {
+ TT::Addition(a, b) => {
+ match (*a, *b) {
+ (TT::Weeks(0), TT::Weeks(1)) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+ _ => assert!(false, "Addition failed, returned non-Addition type"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_weeks_multiple() {
+ let a = TT::Weeks(0);
+ let b = TT::Weeks(1);
+ let c = TT::Weeks(2);
+
+ let d = a + b + c;
+
+ match d {
+ TT::Addition(a, b) => {
+ match (*a, *b) {
+ (TT::Addition(c, d), TT::Weeks(2)) => match (*c, *d) {
+ (TT::Weeks(0), TT::Weeks(1)) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ },
+ (a, b) => assert!(false, "Addition failed: \n a = {:?}\n b = {:?}", a, b),
+ }
+ }
+ _ => assert!(false, "Addition failed, returned non-Addition type"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_weeks() {
+ let a = TT::Weeks(5);
+ let b = TT::Weeks(3);
+
+ let c = a - b;
+
+ match c {
+ TT::Subtraction(a, b) => {
+ match (*a, *b) {
+ (TT::Weeks(5), TT::Weeks(3)) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+ _ => assert!(false, "Subtraction failed, returned non-Subtraction type"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_weeks_multiple() {
+ let a = TT::Weeks(3);
+ let b = TT::Weeks(2);
+ let c = TT::Weeks(1);
+
+ let d = a - b - c;
+
+ match d {
+ TT::Subtraction(a, b) => {
+ match (*a, *b) {
+ (TT::Subtraction(c, d), TT::Weeks(1)) => match (*c, *d) {
+ (TT::Weeks(3), TT::Weeks(2)) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ },
+ (a, b) => assert!(false, "Subtraction failed: \n a = {:?}\n b = {:?}", a, b),
+ }
+ }
+ _ => assert!(false, "Subtraction failed, returned non-Subtraction type"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_weeks_calculate() {
+ let a = TT::Weeks(0);
+ let b = TT::Weeks(1);
+
+ let c = (a + b).calculate();
+
+ assert!(c.is_ok());
+ let c = c.unwrap();
+
+ match c {
+ TT::Weeks(1) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_weeks_multiple_calculate() {
+ let a = TT::Weeks(0);
+ let b = TT::Weeks(1);
+ let c = TT::Weeks(2);
+
+ let d = (a + b + c).calculate();
+
+ assert!(d.is_ok());
+ let d = d.unwrap();
+
+ match d {
+ TT::Weeks(3) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_weeks_calculate() {
+ let a = TT::Weeks(5);
+ let b = TT::Weeks(3);
+
+ let c = (a - b).calculate();
+
+ assert!(c.is_ok());
+ let c = c.unwrap();
+
+ match c {
+ TT::Weeks(2) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_weeks_multiple_calculate() {
+ let a = TT::Weeks(3);
+ let b = TT::Weeks(2);
+ let c = TT::Weeks(1);
+
+ let d = (a - b - c).calculate();
+
+ assert!(d.is_ok());
+ let d = d.unwrap();
+
+ match d {
+ TT::Weeks(0) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_months() {
+ let a = TT::Months(0);
+ let b = TT::Months(1);
+
+ let c = a + b;
+
+ match c {
+ TT::Addition(a, b) => {
+ match (*a, *b) {
+ (TT::Months(0), TT::Months(1)) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+ _ => assert!(false, "Addition failed, returned non-Addition type"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_months_multiple() {
+ let a = TT::Months(0);
+ let b = TT::Months(1);
+ let c = TT::Months(2);
+
+ let d = a + b + c;
+
+ match d {
+ TT::Addition(a, b) => {
+ match (*a, *b) {
+ (TT::Addition(c, d), TT::Months(2)) => match (*c, *d) {
+ (TT::Months(0), TT::Months(1)) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ },
+ (a, b) => assert!(false, "Addition failed: \n a = {:?}\n b = {:?}", a, b),
+ }
+ }
+ _ => assert!(false, "Addition failed, returned non-Addition type"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_months() {
+ let a = TT::Months(5);
+ let b = TT::Months(3);
+
+ let c = a - b;
+
+ match c {
+ TT::Subtraction(a, b) => {
+ match (*a, *b) {
+ (TT::Months(5), TT::Months(3)) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+ _ => assert!(false, "Subtraction failed, returned non-Subtraction type"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_months_multiple() {
+ let a = TT::Months(3);
+ let b = TT::Months(2);
+ let c = TT::Months(1);
+
+ let d = a - b - c;
+
+ match d {
+ TT::Subtraction(a, b) => {
+ match (*a, *b) {
+ (TT::Subtraction(c, d), TT::Months(1)) => match (*c, *d) {
+ (TT::Months(3), TT::Months(2)) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ },
+ (a, b) => assert!(false, "Subtraction failed: \n a = {:?}\n b = {:?}", a, b),
+ }
+ }
+ _ => assert!(false, "Subtraction failed, returned non-Subtraction type"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_months_calculate() {
+ let a = TT::Months(0);
+ let b = TT::Months(1);
+
+ let c = (a + b).calculate();
+
+ assert!(c.is_ok());
+ let c = c.unwrap();
+
+ match c {
+ TT::Months(1) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_months_multiple_calculate() {
+ let a = TT::Months(0);
+ let b = TT::Months(1);
+ let c = TT::Months(2);
+
+ let d = (a + b + c).calculate();
+
+ assert!(d.is_ok());
+ let d = d.unwrap();
+
+ match d {
+ TT::Months(3) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_months_calculate() {
+ let a = TT::Months(5);
+ let b = TT::Months(3);
+
+ let c = (a - b).calculate();
+
+ assert!(c.is_ok());
+ let c = c.unwrap();
+
+ match c {
+ TT::Months(2) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_months_multiple_calculate() {
+ let a = TT::Months(3);
+ let b = TT::Months(2);
+ let c = TT::Months(1);
+
+ let d = (a - b - c).calculate();
+
+ assert!(d.is_ok());
+ let d = d.unwrap();
+
+ match d {
+ TT::Months(0) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_years() {
+ let a = TT::Years(0);
+ let b = TT::Years(1);
+
+ let c = a + b;
+
+ match c {
+ TT::Addition(a, b) => {
+ match (*a, *b) {
+ (TT::Years(0), TT::Years(1)) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+ _ => assert!(false, "Addition failed, returned non-Addition type"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_years_multiple() {
+ let a = TT::Years(0);
+ let b = TT::Years(1);
+ let c = TT::Years(2);
+
+ let d = a + b + c;
+
+ match d {
+ TT::Addition(a, b) => {
+ match (*a, *b) {
+ (TT::Addition(c, d), TT::Years(2)) => match (*c, *d) {
+ (TT::Years(0), TT::Years(1)) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ },
+ (a, b) => assert!(false, "Addition failed: \n a = {:?}\n b = {:?}", a, b),
+ }
+ }
+ _ => assert!(false, "Addition failed, returned non-Addition type"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_years() {
+ let a = TT::Years(5);
+ let b = TT::Years(3);
+
+ let c = a - b;
+
+ match c {
+ TT::Subtraction(a, b) => {
+ match (*a, *b) {
+ (TT::Years(5), TT::Years(3)) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+ _ => assert!(false, "Subtraction failed, returned non-Subtraction type"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_years_multiple() {
+ let a = TT::Years(3);
+ let b = TT::Years(2);
+ let c = TT::Years(1);
+
+ let d = a - b - c;
+
+ match d {
+ TT::Subtraction(a, b) => {
+ match (*a, *b) {
+ (TT::Subtraction(c, d), TT::Years(1)) => match (*c, *d) {
+ (TT::Years(3), TT::Years(2)) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ },
+ (a, b) => assert!(false, "Subtraction failed: \n a = {:?}\n b = {:?}", a, b),
+ }
+ }
+ _ => assert!(false, "Subtraction failed, returned non-Subtraction type"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_years_calculate() {
+ let a = TT::Years(0);
+ let b = TT::Years(1);
+
+ let c = (a + b).calculate();
+
+ assert!(c.is_ok());
+ let c = c.unwrap();
+
+ match c {
+ TT::Years(1) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+
+ #[test]
+ fn test_addition_of_years_multiple_calculate() {
+ let a = TT::Years(0);
+ let b = TT::Years(1);
+ let c = TT::Years(2);
+
+ let d = (a + b + c).calculate();
+
+ assert!(d.is_ok());
+ let d = d.unwrap();
+
+ match d {
+ TT::Years(3) => assert!(true),
+ _ => assert!(false, "Addition failed"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_years_calculate() {
+ let a = TT::Years(5);
+ let b = TT::Years(3);
+
+ let c = (a - b).calculate();
+
+ assert!(c.is_ok());
+ let c = c.unwrap();
+
+ match c {
+ TT::Years(2) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
+
+ #[test]
+ fn test_subtraction_of_years_multiple_calculate() {
+ let a = TT::Years(3);
+ let b = TT::Years(2);
+ let c = TT::Years(1);
+
+ let d = (a - b - c).calculate();
+
+ assert!(d.is_ok());
+ let d = d.unwrap();
+
+ match d {
+ TT::Years(0) => assert!(true),
+ _ => assert!(false, "Subtraction failed"),
+ }
+ }
}
+