uninum 0.1.1

A robust, ergonomic unified number type for Rust with automatic overflow handling, type promotion, and cross-type consistency.
Documentation
//! Basic tests for the Number type.
//!
//! This module tests fundamental properties of the Number enum type
//! including size, alignment, and basic construction.

use std::mem;

use uninum::{Number, num};

#[test]
fn test_number_size() {
    // The Number enum should be optimized for size
    let size = mem::size_of::<Number>();
    let align = mem::align_of::<Number>();

    // Number contains variants with u64/i64 and Arc<Decimal> (pointer)
    // So it should be around 16 bytes (8 for largest value + 8 for
    // discriminant/padding)
    assert!(size <= 24, "Number size is {size} bytes, expected <= 24");
    assert!(
        align >= 8,
        "Number alignment is {align} bytes, expected >= 8"
    );
}

#[test]
fn test_number_variants() {
    // Test that we can create each variant
    let _u64 = Number::from(42_000_000_000_u64);
    let _i64 = Number::from(-42_000_000_000_i64);
    let _f64 = num!(std::f64::consts::PI);

    #[cfg(feature = "decimal")]
    {
        use rust_decimal::Decimal;
        let _decimal = Number::from(Decimal::new(314, 2));
    }
}

#[test]
fn test_debug_display() {
    // Test Debug implementation - now we use the Display format since variants are
    // non-exhaustive
    let u64_num = Number::from(42_u64);
    let i64_num = Number::from(-42_i64);
    let f64_num = num!(std::f64::consts::PI);

    // Debug format may vary with non-exhaustive enum, so we just test it doesn't
    // panic
    let _ = format!("{u64_num:?}");
    let _ = format!("{i64_num:?}");
    let _ = format!("{f64_num:?}");

    // Test Display implementation
    assert_eq!(format!("{u64_num}"), "42");
    assert_eq!(format!("{i64_num}"), "-42");
    assert_eq!(format!("{f64_num}"), "3.141592653589793");
}