From 4bd0e012323a93b628119a51dbec87f3d148b97b Mon Sep 17 00:00:00 2001 From: Rafael Zachariadis Date: Mon, 27 Jul 2020 01:29:33 +0200 Subject: [PATCH] Fix ISO alpha and numeric code definitions in Currency objects; tests --- src/currency/iso.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/currency/iso.rs b/src/currency/iso.rs index 991549f..d46e672 100644 --- a/src/currency/iso.rs +++ b/src/currency/iso.rs @@ -564,7 +564,7 @@ pub fn from_enum(code: &Iso) -> Currency { CZK => Currency { exponent: 2, iso_alpha_code: "CZK", - iso_numeric_code: "132", + iso_numeric_code: "203", locale: EnBy, minor_denomination: 100, name: "Czech Koruna", @@ -793,7 +793,7 @@ pub fn from_enum(code: &Iso) -> Currency { }, HUF => Currency { exponent: 0, - iso_alpha_code: "HTG", + iso_alpha_code: "HUF", iso_numeric_code: "348", locale: EnBy, minor_denomination: 5, @@ -1883,7 +1883,7 @@ pub fn from_enum(code: &Iso) -> Currency { }, ZMW => Currency { exponent: 2, - iso_alpha_code: "ZMK", + iso_alpha_code: "ZMW", iso_numeric_code: "967", locale: EnUs, minor_denomination: 5, @@ -1893,3 +1893,29 @@ pub fn from_enum(code: &Iso) -> Currency { }, } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn iso_enum_name_matches_currency_iso_alpha_code() { + for iso in ISO_CURRENCIES { + let iso_alpha_code = format!("{}", iso); + let currency = from_enum(iso); + assert_eq!(iso_alpha_code, currency.iso_alpha_code); + } + } + + #[test] + fn no_duplicate_currency_numeric_iso_codes() { + let mut numeric_codes: Vec<_> = ISO_CURRENCIES + .iter() + .map(|iso| from_enum(iso).iso_numeric_code) + .collect(); + + numeric_codes.sort(); + numeric_codes.dedup(); + assert_eq!(ISO_CURRENCIES.len(), numeric_codes.len()); + } +}