use crate::currency::Currency;
use crate::indexes::inflationindex::{YoYInflationIndex, ZeroInflationIndex};
use crate::indexes::region::Region;
use crate::settings::Settings;
use crate::shared::Shared;
use crate::time::date::Date;
use crate::time::frequency::Frequency;
use crate::time::period::Period;
use crate::time::timeunit::TimeUnit;
pub struct UsCpi;
impl UsCpi {
#[allow(clippy::new_ret_no_self)]
pub fn new(settings: Shared<Settings<Date>>) -> ZeroInflationIndex {
ZeroInflationIndex::new(
"CPI".into(),
Region::us(),
false,
Frequency::Monthly,
Period::new(1, TimeUnit::Months),
Currency::usd(),
settings,
)
}
}
pub struct YyUsCpi;
impl YyUsCpi {
#[allow(clippy::new_ret_no_self)]
pub fn new(settings: Shared<Settings<Date>>) -> YoYInflationIndex {
YoYInflationIndex::new(
"YY_CPI".into(),
Region::us(),
false,
Frequency::Monthly,
Period::new(1, TimeUnit::Months),
Currency::usd(),
settings,
)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::indexes::index::Index;
use crate::indexes::inflationindex::InflationIndex;
use crate::shared::shared;
#[test]
fn construction_matches_the_cpp_header() {
let index = UsCpi::new(shared(Settings::<Date>::new()));
assert_eq!(index.name(), "USA CPI");
assert_eq!(index.frequency(), Frequency::Monthly);
assert!(!index.revised());
assert_eq!(index.availability_lag(), Period::new(1, TimeUnit::Months));
assert_eq!(index.currency().code(), "USD");
}
#[test]
fn the_year_on_year_construction_matches_the_cpp_header() {
let index = YyUsCpi::new(shared(Settings::<Date>::new()));
assert_eq!(index.name(), "USA YY_CPI");
assert_eq!(index.frequency(), Frequency::Monthly);
assert!(!index.revised());
assert!(!index.ratio());
assert!(index.underlying_index().is_none());
assert_eq!(index.availability_lag(), Period::new(1, TimeUnit::Months));
assert_eq!(index.currency().code(), "USD");
}
}