aboutsummaryrefslogtreecommitdiff
path: root/budget/tests/budget.rs
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2020-12-08 00:39:16 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2020-12-08 00:39:16 +0300
commitcc00db276c203bdcff9ca32d857d23e5dc61f400 (patch)
tree42d6940af40002aef9d630cdcb2aa7d738405dfc /budget/tests/budget.rs
parentd79b2661c8af24c508f90419f01009175cd704d4 (diff)
downloadfinbudg-cc00db276c203bdcff9ca32d857d23e5dc61f400.tar.gz
finbudg-cc00db276c203bdcff9ca32d857d23e5dc61f400.zip
Change way that shared expenses are calculated
The way that shared expenses are recorded and calculated has changed. Now instead of specifying how among many people the expense was divided, the names of the persons are specified. You can also specified expenses that are "owed", or in other words, things that you paid for other people, or maybe loans you made. Don't know why I didn't think of this system before. Sometimes good ideas just come at the least expected times. Also removed some unused fields.
Diffstat (limited to 'budget/tests/budget.rs')
-rw-r--r--budget/tests/budget.rs121
1 files changed, 82 insertions, 39 deletions
diff --git a/budget/tests/budget.rs b/budget/tests/budget.rs
index 4ed549c..836a715 100644
--- a/budget/tests/budget.rs
+++ b/budget/tests/budget.rs
@@ -11,7 +11,7 @@ fn can_parse_account() -> Result<(), ParseError> {
end_date: NaiveDate::from_ymd(2020, 10, 31),
budget: 420.0,
essential_categories: vec![
- String::from("products"),
+ String::from("produce"),
String::from("transport"),
String::from("utilities"),
],
@@ -22,42 +22,40 @@ fn can_parse_account() -> Result<(), ParseError> {
Expense {
name: String::from("Potato masher"),
price: 3.81,
- qty: 1,
- shared: 1,
- recurring: false,
+ shared: vec![],
+ owed: false,
category: Some(String::from("supplies")),
},
Expense {
name: String::from("Bacon"),
price: 3.33,
- qty: 1,
- shared: 3,
- recurring: false,
- category: Some(String::from("products")),
+ shared: vec![
+ String::from("Fox"),
+ String::from("Falco"),
+ ],
+ owed: false,
+ category: Some(String::from("produce")),
},
Expense {
name: String::from("Yoghurt"),
price: 1.24,
- qty: 2,
- shared: 2,
- recurring: false,
- category: Some(String::from("products")),
+ shared: vec![String::from("Falco")],
+ owed: true,
+ category: Some(String::from("produce")),
},
Expense {
name: String::from("Onion"),
price: 0.15,
- qty: 1,
- shared: 1,
- recurring: false,
- category: Some(String::from("products")),
+ shared: vec![],
+ owed: false,
+ category: Some(String::from("produce")),
},
Expense {
name: String::from("Chicken"),
price: 2.28,
- qty: 1,
- shared: 2,
- recurring: false,
- category: Some(String::from("products")),
+ shared: vec![String::from("Fox")],
+ owed: false,
+ category: Some(String::from("produce")),
},
],
},
@@ -71,17 +69,15 @@ fn can_parse_account() -> Result<(), ParseError> {
Expense {
name: String::from("VPS"),
price: 5.0,
- qty: 1,
- shared: 1,
- recurring: true,
+ shared: vec![],
+ owed: false,
category: Some(String::from("utilities")),
},
Expense {
name: String::from("Transport card"),
price: 6.9,
- qty: 1,
- shared: 1,
- recurring: false,
+ shared: vec![],
+ owed: false,
category: Some(String::from("transport")),
},
],
@@ -99,16 +95,17 @@ fn can_parse_account() -> Result<(), ParseError> {
#[test]
fn can_calculate() -> Result<(), ParseError> {
let mut should_be = Calculated {
- all_day_average: 5.6775,
- essential_day_average: 4.725,
+ all_day_average: 4.5275,
+ essential_day_average: 3.575,
categories_day_average: HashMap::<String, f64>::new(),
- essential_subtotal: 18.9,
+ essential_subtotal: 14.3,
categories_subtotal: HashMap::<String, f64>::new(),
- total: 22.71,
- balance: 397.29,
- total_owed: HashMap::<u32, f64>::new(),
- days_left: 69.9762219286658,
- days_left_essential: 84.08253968253969,
+ total: 18.11,
+ balance: 401.89,
+ owed: HashMap::<String, f64>::new(),
+ total_owed: 4.6,
+ days_left: 88.76642738818333,
+ days_left_essential: 112.4167832167832,
last_day: NaiveDate::from_ymd(2020, 10, 04),
};
@@ -117,7 +114,7 @@ fn can_calculate() -> Result<(), ParseError> {
.insert("supplies".to_string(), 0.9525);
should_be
.categories_day_average
- .insert("products".to_string(), 1.75);
+ .insert("produce".to_string(), 0.6);
should_be
.categories_day_average
.insert("transport".to_string(), 1.725);
@@ -130,7 +127,7 @@ fn can_calculate() -> Result<(), ParseError> {
.insert("supplies".to_string(), 3.81);
should_be
.categories_subtotal
- .insert("products".to_string(), 7.0);
+ .insert("produce".to_string(), 2.4);
should_be
.categories_subtotal
.insert("transport".to_string(), 6.9);
@@ -138,13 +135,59 @@ fn can_calculate() -> Result<(), ParseError> {
.categories_subtotal
.insert("utilities".to_string(), 5.0);
- should_be.total_owed.insert(2, 1.7599999999999998);
- should_be.total_owed.insert(3, 2.22);
+ should_be.owed.insert(String::from("Fox"), 2.25);
+ should_be.owed.insert(String::from("Falco"), 2.35);
+
+ let mut should_be_with_owed = Calculated {
+ all_day_average: 5.6775,
+ essential_day_average: 4.725,
+ categories_day_average: HashMap::<String, f64>::new(),
+ essential_subtotal: 18.9,
+ categories_subtotal: HashMap::<String, f64>::new(),
+ total: 22.71,
+ balance: 397.29,
+ owed: HashMap::<String, f64>::new(),
+ total_owed: 4.6,
+ days_left: 69.9762219286658,
+ days_left_essential: 84.08253968253969,
+ last_day: NaiveDate::from_ymd(2020, 10, 04),
+ };
+
+ should_be_with_owed
+ .categories_day_average
+ .insert("supplies".to_string(), 0.9525);
+ should_be_with_owed
+ .categories_day_average
+ .insert("produce".to_string(), 1.75);
+ should_be_with_owed
+ .categories_day_average
+ .insert("transport".to_string(), 1.725);
+ should_be_with_owed
+ .categories_day_average
+ .insert("utilities".to_string(), 1.25);
+
+ should_be_with_owed
+ .categories_subtotal
+ .insert("supplies".to_string(), 3.81);
+ should_be_with_owed
+ .categories_subtotal
+ .insert("produce".to_string(), 7.0);
+ should_be_with_owed
+ .categories_subtotal
+ .insert("transport".to_string(), 6.9);
+ should_be_with_owed
+ .categories_subtotal
+ .insert("utilities".to_string(), 5.0);
+
+ should_be_with_owed.owed.insert(String::from("Fox"), 2.25);
+ should_be_with_owed.owed.insert(String::from("Falco"), 2.35);
let account = budget::parse_account("tests/test.toml")?;
- let actually_is = budget::calculate(&account).unwrap();
+ let actually_is = budget::calculate(&account, false).unwrap();
+ let actually_is_with_owed = budget::calculate(&account, true).unwrap();
assert_eq!(actually_is, should_be);
+ assert_eq!(actually_is_with_owed, should_be_with_owed);
Ok(())
}