use crate::{SqlU128, SqlU256, U128, U256};
use std::ops::{
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Sub, SubAssign,
};
macro_rules! impl_primitive_ops_for {
($sql_ty:ty, $uint_ty:ty) => {
impl Add<u8> for $sql_ty {
type Output = Self;
fn add(self, rhs: u8) -> Self::Output { Self::from(<$uint_ty>::from(self.0 + <$uint_ty>::from(rhs))) }
}
impl Add<u16> for $sql_ty {
type Output = Self;
fn add(self, rhs: u16) -> Self::Output { Self::from(<$uint_ty>::from(self.0 + <$uint_ty>::from(rhs))) }
}
impl Add<u32> for $sql_ty {
type Output = Self;
fn add(self, rhs: u32) -> Self::Output { Self::from(<$uint_ty>::from(self.0 + <$uint_ty>::from(rhs))) }
}
impl Add<u64> for $sql_ty {
type Output = Self;
fn add(self, rhs: u64) -> Self::Output { Self::from(<$uint_ty>::from(self.0 + <$uint_ty>::from(rhs))) }
}
impl Add<u128> for $sql_ty {
type Output = Self;
fn add(self, rhs: u128) -> Self::Output { Self::from(<$uint_ty>::from(self.0 + <$uint_ty>::from(rhs))) }
}
impl Add<usize> for $sql_ty {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output { Self::from(<$uint_ty>::from(self.0 + <$uint_ty>::from(rhs as u64))) }
}
impl Sub<u8> for $sql_ty {
type Output = Self;
fn sub(self, rhs: u8) -> Self::Output { Self::from(<$uint_ty>::from(self.0 - <$uint_ty>::from(rhs))) }
}
impl Sub<u16> for $sql_ty {
type Output = Self;
fn sub(self, rhs: u16) -> Self::Output { Self::from(<$uint_ty>::from(self.0 - <$uint_ty>::from(rhs))) }
}
impl Sub<u32> for $sql_ty {
type Output = Self;
fn sub(self, rhs: u32) -> Self::Output { Self::from(<$uint_ty>::from(self.0 - <$uint_ty>::from(rhs))) }
}
impl Sub<u64> for $sql_ty {
type Output = Self;
fn sub(self, rhs: u64) -> Self::Output { Self::from(<$uint_ty>::from(self.0 - <$uint_ty>::from(rhs))) }
}
impl Sub<u128> for $sql_ty {
type Output = Self;
fn sub(self, rhs: u128) -> Self::Output { Self::from(<$uint_ty>::from(self.0 - <$uint_ty>::from(rhs))) }
}
impl Sub<usize> for $sql_ty {
type Output = Self;
fn sub(self, rhs: usize) -> Self::Output { Self::from(<$uint_ty>::from(self.0 - <$uint_ty>::from(rhs as u64))) }
}
impl Mul<u8> for $sql_ty {
type Output = Self;
fn mul(self, rhs: u8) -> Self::Output { Self::from(<$uint_ty>::from(self.0 * <$uint_ty>::from(rhs))) }
}
impl Mul<u16> for $sql_ty {
type Output = Self;
fn mul(self, rhs: u16) -> Self::Output { Self::from(<$uint_ty>::from(self.0 * <$uint_ty>::from(rhs))) }
}
impl Mul<u32> for $sql_ty {
type Output = Self;
fn mul(self, rhs: u32) -> Self::Output { Self::from(<$uint_ty>::from(self.0 * <$uint_ty>::from(rhs))) }
}
impl Mul<u64> for $sql_ty {
type Output = Self;
fn mul(self, rhs: u64) -> Self::Output { Self::from(<$uint_ty>::from(self.0 * <$uint_ty>::from(rhs))) }
}
impl Mul<u128> for $sql_ty {
type Output = Self;
fn mul(self, rhs: u128) -> Self::Output { Self::from(<$uint_ty>::from(self.0 * <$uint_ty>::from(rhs))) }
}
impl Mul<usize> for $sql_ty {
type Output = Self;
fn mul(self, rhs: usize) -> Self::Output { Self::from(<$uint_ty>::from(self.0 * <$uint_ty>::from(rhs as u64))) }
}
impl Div<u8> for $sql_ty {
type Output = Self;
fn div(self, rhs: u8) -> Self::Output { Self::from(<$uint_ty>::from(self.0 / <$uint_ty>::from(rhs))) }
}
impl Div<u16> for $sql_ty {
type Output = Self;
fn div(self, rhs: u16) -> Self::Output { Self::from(<$uint_ty>::from(self.0 / <$uint_ty>::from(rhs))) }
}
impl Div<u32> for $sql_ty {
type Output = Self;
fn div(self, rhs: u32) -> Self::Output { Self::from(<$uint_ty>::from(self.0 / <$uint_ty>::from(rhs))) }
}
impl Div<u64> for $sql_ty {
type Output = Self;
fn div(self, rhs: u64) -> Self::Output { Self::from(<$uint_ty>::from(self.0 / <$uint_ty>::from(rhs))) }
}
impl Div<u128> for $sql_ty {
type Output = Self;
fn div(self, rhs: u128) -> Self::Output { Self::from(<$uint_ty>::from(self.0 / <$uint_ty>::from(rhs))) }
}
impl Div<usize> for $sql_ty {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output { Self::from(<$uint_ty>::from(self.0 / <$uint_ty>::from(rhs as u64))) }
}
impl Rem<u8> for $sql_ty {
type Output = Self;
fn rem(self, rhs: u8) -> Self::Output { Self::from(<$uint_ty>::from(self.0 % <$uint_ty>::from(rhs))) }
}
impl Rem<u16> for $sql_ty {
type Output = Self;
fn rem(self, rhs: u16) -> Self::Output { Self::from(<$uint_ty>::from(self.0 % <$uint_ty>::from(rhs))) }
}
impl Rem<u32> for $sql_ty {
type Output = Self;
fn rem(self, rhs: u32) -> Self::Output { Self::from(<$uint_ty>::from(self.0 % <$uint_ty>::from(rhs))) }
}
impl Rem<u64> for $sql_ty {
type Output = Self;
fn rem(self, rhs: u64) -> Self::Output { Self::from(<$uint_ty>::from(self.0 % <$uint_ty>::from(rhs))) }
}
impl Rem<u128> for $sql_ty {
type Output = Self;
fn rem(self, rhs: u128) -> Self::Output { Self::from(<$uint_ty>::from(self.0 % <$uint_ty>::from(rhs))) }
}
impl Rem<usize> for $sql_ty {
type Output = Self;
fn rem(self, rhs: usize) -> Self::Output { Self::from(<$uint_ty>::from(self.0 % <$uint_ty>::from(rhs as u64))) }
}
impl Add<$sql_ty> for u8 {
type Output = $sql_ty;
fn add(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) + rhs.0) }
}
impl Add<$sql_ty> for u16 {
type Output = $sql_ty;
fn add(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) + rhs.0) }
}
impl Add<$sql_ty> for u32 {
type Output = $sql_ty;
fn add(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) + rhs.0) }
}
impl Add<$sql_ty> for u64 {
type Output = $sql_ty;
fn add(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) + rhs.0) }
}
impl Add<$sql_ty> for u128 {
type Output = $sql_ty;
fn add(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) + rhs.0) }
}
impl Add<$sql_ty> for usize {
type Output = $sql_ty;
fn add(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self as u64) + rhs.0) }
}
impl Sub<$sql_ty> for u8 {
type Output = $sql_ty;
fn sub(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) - rhs.0) }
}
impl Sub<$sql_ty> for u16 {
type Output = $sql_ty;
fn sub(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) - rhs.0) }
}
impl Sub<$sql_ty> for u32 {
type Output = $sql_ty;
fn sub(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) - rhs.0) }
}
impl Sub<$sql_ty> for u64 {
type Output = $sql_ty;
fn sub(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) - rhs.0) }
}
impl Sub<$sql_ty> for u128 {
type Output = $sql_ty;
fn sub(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) - rhs.0) }
}
impl Sub<$sql_ty> for usize {
type Output = $sql_ty;
fn sub(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self as u64) - rhs.0) }
}
impl Mul<$sql_ty> for u8 {
type Output = $sql_ty;
fn mul(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) * rhs.0) }
}
impl Mul<$sql_ty> for u16 {
type Output = $sql_ty;
fn mul(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) * rhs.0) }
}
impl Mul<$sql_ty> for u32 {
type Output = $sql_ty;
fn mul(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) * rhs.0) }
}
impl Mul<$sql_ty> for u64 {
type Output = $sql_ty;
fn mul(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) * rhs.0) }
}
impl Mul<$sql_ty> for u128 {
type Output = $sql_ty;
fn mul(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) * rhs.0) }
}
impl Mul<$sql_ty> for usize {
type Output = $sql_ty;
fn mul(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self as u64) * rhs.0) }
}
impl Div<$sql_ty> for u8 {
type Output = $sql_ty;
fn div(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) / rhs.0) }
}
impl Div<$sql_ty> for u16 {
type Output = $sql_ty;
fn div(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) / rhs.0) }
}
impl Div<$sql_ty> for u32 {
type Output = $sql_ty;
fn div(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) / rhs.0) }
}
impl Div<$sql_ty> for u64 {
type Output = $sql_ty;
fn div(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) / rhs.0) }
}
impl Div<$sql_ty> for u128 {
type Output = $sql_ty;
fn div(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) / rhs.0) }
}
impl Div<$sql_ty> for usize {
type Output = $sql_ty;
fn div(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self as u64) / rhs.0) }
}
impl Rem<$sql_ty> for u8 {
type Output = $sql_ty;
fn rem(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) % rhs.0) }
}
impl Rem<$sql_ty> for u16 {
type Output = $sql_ty;
fn rem(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) % rhs.0) }
}
impl Rem<$sql_ty> for u32 {
type Output = $sql_ty;
fn rem(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) % rhs.0) }
}
impl Rem<$sql_ty> for u64 {
type Output = $sql_ty;
fn rem(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) % rhs.0) }
}
impl Rem<$sql_ty> for u128 {
type Output = $sql_ty;
fn rem(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self) % rhs.0) }
}
impl Rem<$sql_ty> for usize {
type Output = $sql_ty;
fn rem(self, rhs: $sql_ty) -> Self::Output { <$sql_ty>::from(<$uint_ty>::from(self as u64) % rhs.0) }
}
impl Add<u8> for &$sql_ty { type Output = $sql_ty; fn add(self, rhs: u8) -> Self::Output { <$sql_ty>::from(self.0 + <$uint_ty>::from(rhs)) } }
impl Add<u16> for &$sql_ty { type Output = $sql_ty; fn add(self, rhs: u16) -> Self::Output { <$sql_ty>::from(self.0 + <$uint_ty>::from(rhs)) } }
impl Add<u32> for &$sql_ty { type Output = $sql_ty; fn add(self, rhs: u32) -> Self::Output { <$sql_ty>::from(self.0 + <$uint_ty>::from(rhs)) } }
impl Add<u64> for &$sql_ty { type Output = $sql_ty; fn add(self, rhs: u64) -> Self::Output { <$sql_ty>::from(self.0 + <$uint_ty>::from(rhs)) } }
impl Add<u128> for &$sql_ty { type Output = $sql_ty; fn add(self, rhs: u128) -> Self::Output { <$sql_ty>::from(self.0 + <$uint_ty>::from(rhs)) } }
impl Add<usize> for &$sql_ty { type Output = $sql_ty; fn add(self, rhs: usize) -> Self::Output { <$sql_ty>::from(self.0 + <$uint_ty>::from(rhs as u64)) } }
impl Sub<u8> for &$sql_ty { type Output = $sql_ty; fn sub(self, rhs: u8) -> Self::Output { <$sql_ty>::from(self.0 - <$uint_ty>::from(rhs)) } }
impl Sub<u16> for &$sql_ty { type Output = $sql_ty; fn sub(self, rhs: u16) -> Self::Output { <$sql_ty>::from(self.0 - <$uint_ty>::from(rhs)) } }
impl Sub<u32> for &$sql_ty { type Output = $sql_ty; fn sub(self, rhs: u32) -> Self::Output { <$sql_ty>::from(self.0 - <$uint_ty>::from(rhs)) } }
impl Sub<u64> for &$sql_ty { type Output = $sql_ty; fn sub(self, rhs: u64) -> Self::Output { <$sql_ty>::from(self.0 - <$uint_ty>::from(rhs)) } }
impl Sub<u128> for &$sql_ty { type Output = $sql_ty; fn sub(self, rhs: u128) -> Self::Output { <$sql_ty>::from(self.0 - <$uint_ty>::from(rhs)) } }
impl Sub<usize> for &$sql_ty { type Output = $sql_ty; fn sub(self, rhs: usize) -> Self::Output { <$sql_ty>::from(self.0 - <$uint_ty>::from(rhs as u64)) } }
impl Mul<u8> for &$sql_ty { type Output = $sql_ty; fn mul(self, rhs: u8) -> Self::Output { <$sql_ty>::from(self.0 * <$uint_ty>::from(rhs)) } }
impl Mul<u16> for &$sql_ty { type Output = $sql_ty; fn mul(self, rhs: u16) -> Self::Output { <$sql_ty>::from(self.0 * <$uint_ty>::from(rhs)) } }
impl Mul<u32> for &$sql_ty { type Output = $sql_ty; fn mul(self, rhs: u32) -> Self::Output { <$sql_ty>::from(self.0 * <$uint_ty>::from(rhs)) } }
impl Mul<u64> for &$sql_ty { type Output = $sql_ty; fn mul(self, rhs: u64) -> Self::Output { <$sql_ty>::from(self.0 * <$uint_ty>::from(rhs)) } }
impl Mul<u128> for &$sql_ty { type Output = $sql_ty; fn mul(self, rhs: u128) -> Self::Output { <$sql_ty>::from(self.0 * <$uint_ty>::from(rhs)) } }
impl Mul<usize> for &$sql_ty { type Output = $sql_ty; fn mul(self, rhs: usize) -> Self::Output { <$sql_ty>::from(self.0 * <$uint_ty>::from(rhs as u64)) } }
impl Div<u8> for &$sql_ty { type Output = $sql_ty; fn div(self, rhs: u8) -> Self::Output { <$sql_ty>::from(self.0 / <$uint_ty>::from(rhs)) } }
impl Div<u16> for &$sql_ty { type Output = $sql_ty; fn div(self, rhs: u16) -> Self::Output { <$sql_ty>::from(self.0 / <$uint_ty>::from(rhs)) } }
impl Div<u32> for &$sql_ty { type Output = $sql_ty; fn div(self, rhs: u32) -> Self::Output { <$sql_ty>::from(self.0 / <$uint_ty>::from(rhs)) } }
impl Div<u64> for &$sql_ty { type Output = $sql_ty; fn div(self, rhs: u64) -> Self::Output { <$sql_ty>::from(self.0 / <$uint_ty>::from(rhs)) } }
impl Div<u128> for &$sql_ty { type Output = $sql_ty; fn div(self, rhs: u128) -> Self::Output { <$sql_ty>::from(self.0 / <$uint_ty>::from(rhs)) } }
impl Div<usize> for &$sql_ty { type Output = $sql_ty; fn div(self, rhs: usize) -> Self::Output { <$sql_ty>::from(self.0 / <$uint_ty>::from(rhs as u64)) } }
impl Rem<u8> for &$sql_ty { type Output = $sql_ty; fn rem(self, rhs: u8) -> Self::Output { <$sql_ty>::from(self.0 % <$uint_ty>::from(rhs)) } }
impl Rem<u16> for &$sql_ty { type Output = $sql_ty; fn rem(self, rhs: u16) -> Self::Output { <$sql_ty>::from(self.0 % <$uint_ty>::from(rhs)) } }
impl Rem<u32> for &$sql_ty { type Output = $sql_ty; fn rem(self, rhs: u32) -> Self::Output { <$sql_ty>::from(self.0 % <$uint_ty>::from(rhs)) } }
impl Rem<u64> for &$sql_ty { type Output = $sql_ty; fn rem(self, rhs: u64) -> Self::Output { <$sql_ty>::from(self.0 % <$uint_ty>::from(rhs)) } }
impl Rem<u128> for &$sql_ty { type Output = $sql_ty; fn rem(self, rhs: u128) -> Self::Output { <$sql_ty>::from(self.0 % <$uint_ty>::from(rhs)) } }
impl Rem<usize> for &$sql_ty { type Output = $sql_ty; fn rem(self, rhs: usize) -> Self::Output { <$sql_ty>::from(self.0 % <$uint_ty>::from(rhs as u64)) } }
};
}
impl_primitive_ops_for!(SqlU128, U128);
impl_primitive_ops_for!(SqlU256, U256);
macro_rules! impl_primitive_assign_ops_for {
($sql_ty:ty) => {
impl AddAssign<u8> for $sql_ty { fn add_assign(&mut self, rhs: u8) { *self = *self + rhs; } }
impl AddAssign<u16> for $sql_ty { fn add_assign(&mut self, rhs: u16) { *self = *self + rhs; } }
impl AddAssign<u32> for $sql_ty { fn add_assign(&mut self, rhs: u32) { *self = *self + rhs; } }
impl AddAssign<u64> for $sql_ty { fn add_assign(&mut self, rhs: u64) { *self = *self + rhs; } }
impl AddAssign<u128> for $sql_ty { fn add_assign(&mut self, rhs: u128) { *self = *self + rhs; } }
impl AddAssign<usize> for $sql_ty { fn add_assign(&mut self, rhs: usize) { *self = *self + rhs; } }
impl SubAssign<u8> for $sql_ty { fn sub_assign(&mut self, rhs: u8) { *self = *self - rhs; } }
impl SubAssign<u16> for $sql_ty { fn sub_assign(&mut self, rhs: u16) { *self = *self - rhs; } }
impl SubAssign<u32> for $sql_ty { fn sub_assign(&mut self, rhs: u32) { *self = *self - rhs; } }
impl SubAssign<u64> for $sql_ty { fn sub_assign(&mut self, rhs: u64) { *self = *self - rhs; } }
impl SubAssign<u128> for $sql_ty { fn sub_assign(&mut self, rhs: u128) { *self = *self - rhs; } }
impl SubAssign<usize> for $sql_ty { fn sub_assign(&mut self, rhs: usize) { *self = *self - rhs; } }
impl MulAssign<u8> for $sql_ty { fn mul_assign(&mut self, rhs: u8) { *self = *self * rhs; } }
impl MulAssign<u16> for $sql_ty { fn mul_assign(&mut self, rhs: u16) { *self = *self * rhs; } }
impl MulAssign<u32> for $sql_ty { fn mul_assign(&mut self, rhs: u32) { *self = *self * rhs; } }
impl MulAssign<u64> for $sql_ty { fn mul_assign(&mut self, rhs: u64) { *self = *self * rhs; } }
impl MulAssign<u128> for $sql_ty { fn mul_assign(&mut self, rhs: u128) { *self = *self * rhs; } }
impl MulAssign<usize> for $sql_ty { fn mul_assign(&mut self, rhs: usize) { *self = *self * rhs; } }
impl DivAssign<u8> for $sql_ty { fn div_assign(&mut self, rhs: u8) { *self = *self / rhs; } }
impl DivAssign<u16> for $sql_ty { fn div_assign(&mut self, rhs: u16) { *self = *self / rhs; } }
impl DivAssign<u32> for $sql_ty { fn div_assign(&mut self, rhs: u32) { *self = *self / rhs; } }
impl DivAssign<u64> for $sql_ty { fn div_assign(&mut self, rhs: u64) { *self = *self / rhs; } }
impl DivAssign<u128> for $sql_ty { fn div_assign(&mut self, rhs: u128) { *self = *self / rhs; } }
impl DivAssign<usize> for $sql_ty { fn div_assign(&mut self, rhs: usize) { *self = *self / rhs; } }
impl RemAssign<u8> for $sql_ty { fn rem_assign(&mut self, rhs: u8) { *self = *self % rhs; } }
impl RemAssign<u16> for $sql_ty { fn rem_assign(&mut self, rhs: u16) { *self = *self % rhs; } }
impl RemAssign<u32> for $sql_ty { fn rem_assign(&mut self, rhs: u32) { *self = *self % rhs; } }
impl RemAssign<u64> for $sql_ty { fn rem_assign(&mut self, rhs: u64) { *self = *self % rhs; } }
impl RemAssign<u128> for $sql_ty { fn rem_assign(&mut self, rhs: u128) { *self = *self % rhs; } }
impl RemAssign<usize> for $sql_ty { fn rem_assign(&mut self, rhs: usize) { *self = *self % rhs; } }
};
}
impl_primitive_assign_ops_for!(SqlU128);
impl_primitive_assign_ops_for!(SqlU256);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_unsigned_primitive_operations_u256() {
let value = SqlU256::from(100u64);
assert_eq!(value + 50u64, SqlU256::from(150u64));
assert_eq!(value - 30u64, SqlU256::from(70u64));
assert_eq!(value * 2u64, SqlU256::from(200u64));
assert_eq!(value / 2u64, SqlU256::from(50u64));
assert_eq!(value % 30u64, SqlU256::from(10u64));
assert_eq!(50u64 + value, SqlU256::from(150u64));
assert_eq!(200u64 - value, SqlU256::from(100u64));
assert_eq!(2u64 * value, SqlU256::from(200u64));
assert_eq!(1000u64 / value, SqlU256::from(10u64));
assert_eq!(250u64 % value, SqlU256::from(50u64));
}
#[test]
fn test_different_unsigned_types() {
let value = SqlU256::from(100u64);
assert_eq!(value * 2u8, SqlU256::from(200u64));
assert_eq!(value * 2u16, SqlU256::from(200u64));
assert_eq!(value * 2u32, SqlU256::from(200u64));
assert_eq!(value * 2u128, SqlU256::from(200u64));
assert_eq!(value * 2usize, SqlU256::from(200u64));
assert_eq!(2u8 * value, SqlU256::from(200u64));
assert_eq!(2u16 * value, SqlU256::from(200u64));
assert_eq!(2u32 * value, SqlU256::from(200u64));
assert_eq!(2u128 * value, SqlU256::from(200u64));
assert_eq!(2usize * value, SqlU256::from(200u64));
}
#[test]
fn test_reference_operations() {
let value = SqlU256::from(100u64);
let multiplier = 2u64;
assert_eq!(&value * multiplier, SqlU256::from(200u64));
}
#[test]
fn test_u128_operations() {
let value = SqlU128::from(100u64);
assert_eq!(value + 50u64, SqlU128::from(150u64));
assert_eq!(value - 30u64, SqlU128::from(70u64));
assert_eq!(value * 2u64, SqlU128::from(200u64));
assert_eq!(value / 2u64, SqlU128::from(50u64));
assert_eq!(value % 30u64, SqlU128::from(10u64));
assert_eq!(50u64 + value, SqlU128::from(150u64));
assert_eq!(2u64 * value, SqlU128::from(200u64));
}
#[test]
fn test_common_ethereum_scenarios() {
let balance = SqlU256::from(1_000_000_000_000_000_000u64); let gas_price = SqlU256::from(20_000_000_000u64);
let doubled_balance = balance * 2u64;
assert_eq!(doubled_balance, SqlU256::from(2_000_000_000_000_000_000u64));
let gas_limit = 21000u64;
let tx_cost = gas_price * gas_limit;
assert_eq!(tx_cost, SqlU256::from(420_000_000_000_000u64));
let remaining = balance - tx_cost;
assert_eq!(remaining, SqlU256::from(999_580_000_000_000_000u64));
let fee_percentage = 5u64;
let fee = balance * fee_percentage / 100u64;
assert_eq!(fee, SqlU256::from(50_000_000_000_000_000u64));
}
#[test]
fn test_assign_ops_with_primitives_u256() {
let mut val = SqlU256::from(100u64);
val += 50u64;
assert_eq!(val, SqlU256::from(150u64));
val -= 30u64;
assert_eq!(val, SqlU256::from(120u64));
val *= 2u64;
assert_eq!(val, SqlU256::from(240u64));
val /= 3u64;
assert_eq!(val, SqlU256::from(80u64));
val %= 9u64;
assert_eq!(val, SqlU256::from(8u64));
}
#[test]
fn test_assign_ops_with_primitives_u128() {
let mut val = SqlU128::from(200u64);
val += 100u64;
assert_eq!(val, SqlU128::from(300u64));
val -= 50u64;
assert_eq!(val, SqlU128::from(250u64));
val *= 2u16;
assert_eq!(val, SqlU128::from(500u64));
val /= 5u8;
assert_eq!(val, SqlU128::from(100u64));
val %= 30u32;
assert_eq!(val, SqlU128::from(10u64));
}
}