<commit_before>use crate::asset::*;
use std::cmp;

impl Asset {
    pub fn gt(&self, other: &Asset) -> Option<bool> {
        if self.symbol != other.symbol {
            return None;
        }
        let decimals = cmp::max(self.decimals, other.decimals);
        let t = set_decimals_i64(self.amount, self.decimals, decimals)?;
        let o = set_decimals_i64(other.amount, other.decimals, decimals)?;
        Some(t > o)
    }

    pub fn geq(&self, other: &Asset) -> Option<bool> {
        if self.symbol != other.symbol {
            return None;
        }
        let decimals = cmp::max(self.decimals, other.decimals);
        let t = set_decimals_i64(self.amount, self.decimals, decimals)?;
        let o = set_decimals_i64(other.amount, other.decimals, decimals)?;
        Some(t >= o)
    }

    pub fn lt(&self, other: &Asset) -> Option<bool> {
        Some(!(self.geq(other)?))
    }

    pub fn leq(&self, other: &Asset) -> Option<bool> {
        Some(!(self.gt(other)?))
    }

    pub fn eq(&self, other: &Asset) -> Option<bool> {
        if self.symbol != other.symbol {
            return None;
        }
        let decimals = cmp::max(self.decimals, other.decimals);
        let t = set_decimals_i64(self.amount, self.decimals, decimals)?;
        let o = set_decimals_i64(other.amount, other.decimals, decimals)?;
        Some(t == o)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_compare_assets() {
        assert!(get_asset("1 GOLD").gt(&get_asset("0.50 GOLD")).unwrap());
        assert!(get_asset("1.0 GOLD").gt(&get_asset("0.99 GOLD")).unwrap());

        assert!(get_asset("1 GOLD").geq(&get_asset("1.0 GOLD")).unwrap());
        assert!(!get_asset("0.1 GOLD").geq(&get_asset("1.0 GOLD")).unwrap());

        assert!(get_asset("1 GOLD").leq(&get_asset("1.0 GOLD")).unwrap());
        assert!(get_asset("0.1 GOLD").leq(&get_asset("1.0 GOLD")).unwrap());
        assert!(get_asset("5.0 GOLD").leq(&get_asset("10 GOLD")).unwrap());

        assert!(get_asset("1 GOLD").eq(&get_asset("1 GOLD")).unwrap());
        assert!(!get_asset("1 GOLD").gt(&get_asset("1 GOLD")).unwrap());
        assert!(!get_asset("1 GOLD").lt(&get_asset("1 GOLD")).unwrap());
    }

    #[test]
    fn test_invalid_cmp() {
        let a = &get_asset("10 GOLD");
        let b = &get_asset("10 SILVER");

        assert!(a.gt(b).is_none());
        assert!(a.geq(b).is_none());
        assert!(a.lt(b).is_none());
        assert!(a.leq(b).is_none());
        assert!(a.eq(b).is_none());
    }

    fn get_asset(s: &str) -> Asset {
        Asset::from_str(s).unwrap()
    }
}<commit_msg>Add several Asset comparison tests<commit_after>use crate::asset::*;
use std::cmp;

impl Asset {
    pub fn gt(&self, other: &Asset) -> Option<bool> {
        if self.symbol != other.symbol {
            return None;
        }
        let decimals = cmp::max(self.decimals, other.decimals);
        let t = set_decimals_i64(self.amount, self.decimals, decimals)?;
        let o = set_decimals_i64(other.amount, other.decimals, decimals)?;
        Some(t > o)
    }

    pub fn geq(&self, other: &Asset) -> Option<bool> {
        if self.symbol != other.symbol {
            return None;
        }
        let decimals = cmp::max(self.decimals, other.decimals);
        let t = set_decimals_i64(self.amount, self.decimals, decimals)?;
        let o = set_decimals_i64(other.amount, other.decimals, decimals)?;
        Some(t >= o)
    }

    pub fn lt(&self, other: &Asset) -> Option<bool> {
        Some(!(self.geq(other)?))
    }

    pub fn leq(&self, other: &Asset) -> Option<bool> {
        Some(!(self.gt(other)?))
    }

    pub fn eq(&self, other: &Asset) -> Option<bool> {
        if self.symbol != other.symbol {
            return None;
        }
        let decimals = cmp::max(self.decimals, other.decimals);
        let t = set_decimals_i64(self.amount, self.decimals, decimals)?;
        let o = set_decimals_i64(other.amount, other.decimals, decimals)?;
        Some(t == o)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_compare_assets() {
        assert!(get_asset("1 GOLD").gt(&get_asset("0.50 GOLD")).unwrap());
        assert!(get_asset("1.0 GOLD").gt(&get_asset("0.99 GOLD")).unwrap());

        assert!(get_asset("1 GOLD").geq(&get_asset("1.0 GOLD")).unwrap());
        assert!(!get_asset("0.1 GOLD").geq(&get_asset("1.0 GOLD")).unwrap());

        assert!(get_asset("1 GOLD").leq(&get_asset("1.0 GOLD")).unwrap());
        assert!(get_asset("0.1 GOLD").leq(&get_asset("1.0 GOLD")).unwrap());
        assert!(get_asset("5.0 GOLD").leq(&get_asset("10 GOLD")).unwrap());

        assert!(get_asset("1 GOLD").eq(&get_asset("1 GOLD")).unwrap());
        assert!(get_asset("1.0 GOLD").eq(&get_asset("1 GOLD")).unwrap());
        assert!(get_asset("1.0 GOLD").eq(&get_asset("1.0 GOLD")).unwrap());
        assert!(get_asset("1 GOLD").eq(&get_asset("1.00 GOLD")).unwrap());
        assert!(get_asset("1 GOLD").eq(&get_asset("1.0 GOLD")).unwrap());
        assert!(get_asset("1.0 GOLD").eq(&get_asset("1.00 GOLD")).unwrap());

        assert!(!get_asset("1 GOLD").gt(&get_asset("1 GOLD")).unwrap());
        assert!(!get_asset("1.0 GOLD").gt(&get_asset("1 GOLD")).unwrap());
        assert!(!get_asset("1 GOLD").gt(&get_asset("1.0 GOLD")).unwrap());

        assert!(get_asset("-1 GOLD").lt(&get_asset("1 GOLD")).unwrap());
        assert!(!get_asset("1 GOLD").lt(&get_asset("1 GOLD")).unwrap());
        assert!(!get_asset("1 GOLD").lt(&get_asset("1.0 GOLD")).unwrap());
        assert!(!get_asset("1.0 GOLD").lt(&get_asset("1 GOLD")).unwrap());
        assert!(!get_asset("1 GOLD").lt(&get_asset("-1 GOLD")).unwrap());
    }

    #[test]
    fn test_invalid_cmp() {
        let a = &get_asset("10 GOLD");
        let b = &get_asset("10 SILVER");

        assert!(a.gt(b).is_none());
        assert!(a.geq(b).is_none());
        assert!(a.lt(b).is_none());
        assert!(a.leq(b).is_none());
        assert!(a.eq(b).is_none());
    }

    fn get_asset(s: &str) -> Asset {
        Asset::from_str(s).unwrap()
    }
}
{'fraction_non_alphanumeric': 0.2058242843040474, 'fraction_numerical': 0.02188219809147746, 'mean_word_length': 2.8401768793430198, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4809487', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2188, 'n_words': 357}