pub fn compare_balances(
    expected_balances: Vec<(f64, String)>,
    extracted_balances: Vec<String>,
) -> bool {
    if extracted_balances.len() != extracted_balances.len() {
        return false;
    }

    let extracted_balances_dec: BTreeMap<_, _> = extracted_balances
        .into_iter()
        .map(|balance_str| {
            let (currency_code, stripped_str) = if balance_str.ends_with("XUS") {
                ("XUS", balance_str.trim_end_matches("XUS"))
            } else if balance_str.ends_with("XDX") {
                ("XDX", balance_str.trim_end_matches("XDX"))
            } else {
                panic!("Unexpected currency type returned for balance")
            };
            (currency_code, Decimal::from_str(stripped_str).ok())
        })
        .collect();

    expected_balances
        .into_iter()
        .all(|(balance, currency_code)| {
            if let Some(extracted_balance) = extracted_balances_dec.get(currency_code.as_str()) {
                Decimal::from_f64(balance) == *extracted_balance
            } else {
                false
            }
        })
}
// TODO(joshlind): Refactor all of these so that they can be contained within the calling
// test files and not shared across all tests.
Refactor all of these so that they can be contained within the calling
test files and not shared across all tests.
Refactor all of these so that they can be contained within the calling test files and not shared across all tests .
pub fn compare_balances(
    expected_balances: Vec<(f64, String)>,
    extracted_balances: Vec<String>,
) -> bool {
    if extracted_balances.len() != extracted_balances.len() {
        return false;
    }
    let extracted_balances_dec: BTreeMap<_, _> = extracted_balances
        .into_iter()
        .map(|balance_str| {
            let (currency_code, stripped_str) = if balance_str.ends_with("XUS") {
                ("XUS", balance_str.trim_end_matches("XUS"))
            } else if balance_str.ends_with("XDX") {
                ("XDX", balance_str.trim_end_matches("XDX"))
            } else {
                panic!("Unexpected currency type returned for balance")
            };
            (currency_code, Decimal::from_str(stripped_str).ok())
        })
        .collect();
    expected_balances
        .into_iter()
        .all(|(balance, currency_code)| {
            if let Some(extracted_balance) = extracted_balances_dec.get(currency_code.as_str()) {
                Decimal::from_f64(balance) == *extracted_balance
            } else {
                false
            }
        })
}
pub fn compare_balances ( expected_balances : Vec < ( f64 , String ) > , extracted_balances : Vec < String > , ) -> bool { if extracted_balances . len ( ) != extracted_balances . len ( ) { return false ; } let extracted_balances_dec : BTreeMap < _ , _ > = extracted_balances . into_iter ( ) . map ( | balance_str | { let ( currency_code , stripped_str ) = if balance_str . ends_with ( " " ) { ( " " , balance_str . trim_end_matches ( " " ) ) } else if balance_str . ends_with ( " " ) { ( " " , balance_str . trim_end_matches ( " " ) ) } else { panic ! ( " " ) } ; ( currency_code , Decimal :: from_str ( stripped_str ) . ok ( ) ) } ) . collect ( ) ; expected_balances . into_iter ( ) . all ( | ( balance , currency_code ) | { if let Some ( extracted_balance ) = extracted_balances_dec . get ( currency_code . as_str ( ) ) { Decimal :: from_f64 ( balance ) == * extracted_balance } else { false } } ) }
TODO(joshlind): Refactor all of these so that they can be contained within the calling
test files and not shared across all tests.
TODO ( joshlind ) : Refactor all of these so that they can be contained within the calling test files and not shared across all tests .
expected_balances
Vec<(f64, String)>
extracted_balances
Vec<String>