diff options
author | Yaroslav <contact@yaroslavps.com> | 2020-10-06 00:18:37 +0300 |
---|---|---|
committer | Yaroslav <contact@yaroslavps.com> | 2020-10-06 00:20:03 +0300 |
commit | cc688c4dc73d3b13be5aba1bd292cc31265c5d04 (patch) | |
tree | 66a46e038ea2392600deba03f040b60a8fe7a565 | |
parent | 408b0ac993496b108ec1e479151d549e9535051a (diff) | |
download | finbudg-0.1.1.tar.gz finbudg-0.1.1.zip |
Allow days with no expensesv0.1.1
Also fix "spelling" mistake in output ("..." instead of "..").
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | budget/src/lib.rs | 1 | ||||
-rw-r--r-- | budget/tests/budget.rs | 20 | ||||
-rw-r--r-- | budget/tests/test.toml | 4 | ||||
-rw-r--r-- | src/main.rs | 4 |
6 files changed, 22 insertions, 13 deletions
@@ -1,6 +1,6 @@ [package] name = "finbudg" -version = "0.1.0" +version = "0.1.1" edition = "2018" description = "Quick cli tool to calculate your expenses and balance for a set period of time." license = "MIT" @@ -111,8 +111,8 @@ Total: 22.71 Left on balance: 397.29 Days until balance runs out: -..taking into account all expenses: 34.99 -..taking into account only essential expenses: 42.04 +...taking into account all expenses: 34.99 +...taking into account only essential expenses: 42.04 Your expenses are healthy, they should last you from your last day on entry through your last day of the period. diff --git a/budget/src/lib.rs b/budget/src/lib.rs index 4dab46a..e8bb8f3 100644 --- a/budget/src/lib.rs +++ b/budget/src/lib.rs @@ -22,6 +22,7 @@ pub struct Account { pub struct Day { #[serde(deserialize_with = "deserialize_date")] pub date: NaiveDate, + #[serde(default)] pub expenses: Vec<Expense>, } diff --git a/budget/tests/budget.rs b/budget/tests/budget.rs index 32828f8..1cc02e7 100644 --- a/budget/tests/budget.rs +++ b/budget/tests/budget.rs @@ -82,6 +82,10 @@ fn can_parse_account() -> Result<(), ParseError>{ }, ], }, + Day { + date: NaiveDate::from_ymd(2020, 10, 3), + expenses: Vec::<Expense>::new(), + }, ], }; @@ -95,32 +99,32 @@ fn can_parse_account() -> Result<(), ParseError>{ #[test] fn can_calculate() -> Result<(), ParseError> { let mut should_be = Calculated { - all_day_average: 11.355, - essential_day_average: 9.45, + all_day_average: 7.57, + essential_day_average: 6.3, categories_day_average: HashMap::<String, f64>::new(), essential_subtotal: 18.9, categories_subtotal: HashMap::<String, f64>::new(), total: 22.71, balance: 397.29, - days_left: 34.9881109643329, - days_left_essential: 42.041269841269845, + days_left: 52.48216644649934, + days_left_essential: 63.06190476190476, }; should_be.categories_day_average.insert( "supplies".to_string(), - 1.905, + 1.27, ); should_be.categories_day_average.insert( "products".to_string(), - 3.5, + 2.3333333333333335, ); should_be.categories_day_average.insert( "transport".to_string(), - 3.45, + 2.3000000000000003, ); should_be.categories_day_average.insert( "utilities".to_string(), - 2.5, + 1.6666666666666667, ); should_be.categories_subtotal.insert( diff --git a/budget/tests/test.toml b/budget/tests/test.toml index 7dd5774..1bb1ce7 100644 --- a/budget/tests/test.toml +++ b/budget/tests/test.toml @@ -51,3 +51,7 @@ date = 2020-10-02 name = "Transport card" price = 6.9 category = "transport" + +[[days]] +date = 2020-10-03 + diff --git a/src/main.rs b/src/main.rs index d091965..04d5277 100644 --- a/src/main.rs +++ b/src/main.rs @@ -212,11 +212,11 @@ fn output(account: Account, calculated: Calculated) { }; println!( - "..taking into account all expenses: {}", + "...taking into account all expenses: {}", days_left_output, ); println!( - "..taking into account only essential expenses: {}", + "...taking into account only essential expenses: {}", days_left_essential_output, ); println!(); |