lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

domain.rs (896B)


      1 use radroots::{
      2     OperationId,
      3     domain::{AmountError, Decimal, OrderId},
      4 };
      5 
      6 #[test]
      7 fn ordinary_facade_keeps_exact_values_and_distinct_operation_identity() {
      8     let a: Decimal = "0.1".parse().unwrap();
      9     let b: Decimal = "0.2".parse().unwrap();
     10     assert_eq!(a.checked_add(b).unwrap().to_string(), "0.3");
     11     assert_eq!(a.checked_sub(b), Err(AmountError::NegativeResult));
     12     assert!("1e3".parse::<Decimal>().is_err());
     13     let operation: OperationId = "0123456789abcdef".repeat(4).parse().unwrap();
     14     assert_eq!(
     15         serde_json::to_string(&operation).unwrap(),
     16         format!("\"{operation}\"")
     17     );
     18     let order: OrderId = operation.to_string().parse().unwrap();
     19     assert_eq!(order.to_string(), operation.to_string());
     20     assert!(
     21         operation
     22             .to_string()
     23             .to_uppercase()
     24             .parse::<OperationId>()
     25             .is_err()
     26     );
     27 }