uninum 0.1.1

A robust, ergonomic unified number type for Rust with automatic overflow handling, type promotion, and cross-type consistency.
Documentation
//! Bitwise XOR Operation Tests
//!
//! This module contains comprehensive tests for bitwise XOR operations on
//! Number types:
//!
//! - Basic XOR operations
//! - XOR with all ones (NOT result)
//! - XOR with all zeros (identity)
//! - XOR with self (zero result)
//! - Error handling for non-integer types
//! - Mixed type XOR operation failures
//!
//! These tests are only compiled when the `bitwise` feature is enabled.

use uninum::{Number, num};

#[test]
fn test_basic_xor_operation() {
    // Test XOR
    let e = Number::from(0b1010u64);
    let f = Number::from(0b1100u64);
    assert_eq!((e ^ f).unwrap(), Number::from(0b0110u64));
}

#[test]
fn test_try_bitxor_method() {
    // Test try_bitxor
    let a = Number::from(0b1010u64);
    let b = Number::from(0b1100u64);
    assert_eq!(a.try_bitxor(&b), Some(Number::from(0b0110u64)));

    let float = num!(3.16);
    assert_eq!(float.try_bitxor(&a), None);
}

#[test]
fn test_bitxor_signed_integers() {
    let a = Number::from(-0b1010i64);
    let b = Number::from(-0b0101i64);
    assert_eq!((a ^ b).unwrap(), Number::from(13i64));
}

#[test]
fn test_bitxor_mismatched_types_error() {
    let signed = Number::from(-2i64);
    let unsigned = Number::from(3u64);
    assert!((signed ^ unsigned).is_err());
}

#[test]
fn test_small_integer_bitxor() {
    let a = Number::from(0b1010u64);
    let b = Number::from(0b1100u64);

    assert_eq!(a.try_bitxor(&b), Some(Number::from(0b0110u64)));
}

#[test]
fn test_large_integer_bitxor() {
    let a = Number::from(0x1234567890ABCDEFu64);
    let b = Number::from(0xFEDCBA0987654321u64);

    assert!(a.try_bitxor(&b).is_some());
}

#[test]
fn test_bitxor_with_references() {
    let a = Number::from(0b1010u64);
    let b = Number::from(0b1100u64);

    // Test reference operations (using clones since bitwise ops don't support
    // references)
    assert_eq!((a.clone() ^ b.clone()).unwrap(), Number::from(0b0110u64));

    // Verify original values are still available
    assert_eq!(a, Number::from(0b1010u64));
    assert_eq!(b, Number::from(0b1100u64));
}

#[test]
fn test_bitxor_patterns() {
    // Test common bit patterns
    let all_ones_u32 = Number::from(0xFFFFFFFFu64);
    let all_zeros_u32 = Number::from(0x00000000u64);
    let alternating_u32 = Number::from(0xAAAAAAAAu64); // 10101010...
    let alternating2_u32 = Number::from(0x55555555u64); // 01010101...

    // XOR with all ones = NOT
    assert_eq!(
        (alternating_u32.clone() ^ all_ones_u32).unwrap(),
        alternating2_u32
    );
    // XOR with self = zero
    assert_eq!(
        (alternating_u32.clone() ^ alternating_u32.clone()).unwrap(),
        all_zeros_u32
    );
}

#[test]
#[cfg(feature = "decimal")]
fn test_bitxor_with_decimal_fails() {
    use rust_decimal::Decimal;

    let dec = Number::from(Decimal::new(42, 0));
    let int = Number::from(42u64);

    // All bitwise operations should fail for Decimal
    assert!((dec.clone() ^ int.clone()).is_err());

    // try_* methods should return None
    assert_eq!(dec.try_bitxor(&int), None);
}