Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-0x committed Oct 7, 2024
1 parent 7768422 commit 3721273
Showing 1 changed file with 78 additions and 8 deletions.
86 changes: 78 additions & 8 deletions crates/torii/core/src/sql/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ mod tests {

#[test]
fn test_add_zero_true_and_zero_false() {
// 0,true + 0,false
// 0,true + 0,false == 0,false
let a = I256 { value: U256::from(0u8), is_negative: true };
let b = I256::default();
let result = a + b;
Expand All @@ -137,7 +137,7 @@ mod tests {

#[test]
fn test_sub_zero_false_and_zero_false() {
// 0,false - 0,false
// 0,false - 0,false == 0,false
let a = I256::default();
let b = I256::default();
let result = a - b;
Expand All @@ -147,12 +147,12 @@ mod tests {

#[test]
fn test_sub_zero_true_and_zero_false() {
// 0,true - 0,false
// 0,true - 0,false == 0,false
let a = I256 { value: U256::from(0u8), is_negative: true };
let b = I256::default();
let result = a - b;
assert_eq!(result.value, U256::from(0u8));
assert!(result.is_negative);
assert!(!result.is_negative);
}

#[test]
Expand All @@ -177,12 +177,12 @@ mod tests {

#[test]
fn test_sub_larger_from_smaller() {
// 5,false - 10,true == 5,true
// 5,false - 10,true == 15,true
let a = I256::from(U256::from(5u8));
let b = I256::from(U256::from(10u8));
let b = I256 { value: U256::from(10u8), is_negative: true };
let result = a - b;
assert_eq!(result.value, U256::from(5u8));
assert!(result.is_negative);
assert_eq!(result.value, U256::from(15u8));
assert!(!result.is_negative);
}

#[test]
Expand Down Expand Up @@ -264,4 +264,74 @@ mod tests {
assert_eq!(result.value, U256::from(10u8));
assert!(result.is_negative);
}

#[test]
fn test_add_zero_true_and_fifteen_true() {
// 0,true + 15,true == 15,true
let a = I256 { value: U256::from(0u8), is_negative: true };
let b = I256 { value: U256::from(15u8), is_negative: true };
let result = a + b;
assert_eq!(result.value, U256::from(15u8));
assert!(result.is_negative);
}

#[test]
fn test_sub_zero_true_and_fifteen_true() {
// 0,true - 15,true == 15,false
let a = I256 { value: U256::from(0u8), is_negative: true };
let b = I256 { value: U256::from(15u8), is_negative: true };
let result = a - b;
assert_eq!(result.value, U256::from(15u8));
assert!(!result.is_negative);
}

#[test]
fn test_add_fifteen_true_and_zero_true() {
// 15,true + 0,true == 15,true
let a = I256 { value: U256::from(15u8), is_negative: true };
let b = I256 { value: U256::from(0u8), is_negative: true };
let result = a + b;
assert_eq!(result.value, U256::from(15u8));
assert!(result.is_negative);
}

#[test]
fn test_sub_fifteen_true_and_zero_true() {
// 15,true - 0,true == 15,true
let a = I256 { value: U256::from(15u8), is_negative: true };
let b = I256 { value: U256::from(0u8), is_negative: true };
let result = a - b;
assert_eq!(result.value, U256::from(15u8));
assert!(result.is_negative);
}

#[test]
fn test_negative_zero() {
// 0,true + 0,true == 0,false
let a = I256 { value: U256::from(0u8), is_negative: true };
let b = I256 { value: U256::from(0u8), is_negative: true };
let result = a + b;
assert_eq!(result.value, U256::from(0u8));
assert!(!result.is_negative);
}

#[test]
fn test_sub_positive_and_negative_zero() {
// 15,false - 0,true == 15,false
let a = I256::from(U256::from(15u8));
let b = I256 { value: U256::from(0u8), is_negative: true };
let result = a - b;
assert_eq!(result.value, U256::from(15u8));
assert!(!result.is_negative);
}

#[test]
fn test_add_positive_and_negative_zero() {
// 15,false + 0,true == 15,false
let a = I256::from(U256::from(15u8));
let b = I256 { value: U256::from(0u8), is_negative: true };
let result = a + b;
assert_eq!(result.value, U256::from(15u8));
assert!(!result.is_negative);
}
}

0 comments on commit 3721273

Please sign in to comment.