diff --git a/rust/src/instructions/math/arithmetic/add_func.rs b/rust/src/instructions/math/arithmetic/add_func.rs index 1f4efbfc..75c296c8 100644 --- a/rust/src/instructions/math/arithmetic/add_func.rs +++ b/rust/src/instructions/math/arithmetic/add_func.rs @@ -91,19 +91,26 @@ mod tests { use super::*; #[test] fn integer_directive_rejects_float_operands_without_mutating_stack() { - for (a, b, found) in [ - (Value::Float32(1.0), Value::Int32(2), "Float"), - (Value::Int32(1), Value::Float64(2.0), "Double"), + for (a, b, num_type, found) in [ + ( + Value::Float16(half::f16::ONE), + Value::Int16(2), + PrimitiveTypes::Sht, + "Half", + ), + (Value::Int32(1), Value::Float32(2.0), PrimitiveTypes::Int, "Float"), + (Value::Float64(1.0), Value::Int64(2), PrimitiveTypes::Lng, "Double"), + (Value::Int128(1), Value::Float64(2.0), PrimitiveTypes::Oct, "Double"), ] { assert!(matches!( - add_values(a.clone(), b.clone(), PrimitiveTypes::Int, 8), + add_values(a.clone(), b.clone(), num_type, 8), Err(VMError::TypeMismatch { ip: 8, expected: "Integer", found: actual }) if actual == found )); let mut stack = Stack::from_vec(vec![a, b]); let original = stack.clone(); assert!(matches!( - add_func(&mut stack, PrimitiveTypes::Int, 9), + add_func(&mut stack, num_type, 9), Err(VMError::TypeMismatch { ip: 9, expected: "Integer", found: actual }) if actual == found )); diff --git a/rust/src/instructions/math/arithmetic/div_func.rs b/rust/src/instructions/math/arithmetic/div_func.rs index 1505d969..c1d275dd 100644 --- a/rust/src/instructions/math/arithmetic/div_func.rs +++ b/rust/src/instructions/math/arithmetic/div_func.rs @@ -94,18 +94,25 @@ mod tests { use super::*; #[test] fn integer_directive_rejects_float_operands_without_mutating_stack() { - for (a, b, found) in [ - (Value::Float32(1.0), Value::Int32(2), "Float"), - (Value::Int32(1), Value::Float64(2.0), "Double"), + for (a, b, num_type, found) in [ + ( + Value::Float16(half::f16::ONE), + Value::Int16(2), + PrimitiveTypes::Sht, + "Half", + ), + (Value::Int32(1), Value::Float32(2.0), PrimitiveTypes::Int, "Float"), + (Value::Float64(1.0), Value::Int64(2), PrimitiveTypes::Lng, "Double"), + (Value::Int128(1), Value::Float64(2.0), PrimitiveTypes::Oct, "Double"), ] { assert!(matches!( - div_values(a.clone(), b.clone(), PrimitiveTypes::Int, 8), + div_values(a.clone(), b.clone(), num_type, 8), Err(VMError::TypeMismatch { ip: 8, expected: "Integer", found: actual }) if actual == found )); let mut stack = Stack::from_vec(vec![a, b]); let original = stack.clone(); assert!(matches!( - div_func(&mut stack, PrimitiveTypes::Int, 9), + div_func(&mut stack, num_type, 9), Err(VMError::TypeMismatch { ip: 9, expected: "Integer", found: actual }) if actual == found )); assert_eq!(stack, original); diff --git a/rust/src/instructions/math/arithmetic/mod_func.rs b/rust/src/instructions/math/arithmetic/mod_func.rs index aeb354b6..0f30234d 100644 --- a/rust/src/instructions/math/arithmetic/mod_func.rs +++ b/rust/src/instructions/math/arithmetic/mod_func.rs @@ -94,18 +94,25 @@ mod tests { use super::*; #[test] fn integer_directive_rejects_float_operands_without_mutating_stack() { - for (a, b, found) in [ - (Value::Float32(1.0), Value::Int32(2), "Float"), - (Value::Int32(1), Value::Float64(2.0), "Double"), + for (a, b, num_type, found) in [ + ( + Value::Float16(half::f16::ONE), + Value::Int16(2), + PrimitiveTypes::Sht, + "Half", + ), + (Value::Int32(1), Value::Float32(2.0), PrimitiveTypes::Int, "Float"), + (Value::Float64(1.0), Value::Int64(2), PrimitiveTypes::Lng, "Double"), + (Value::Int128(1), Value::Float64(2.0), PrimitiveTypes::Oct, "Double"), ] { assert!(matches!( - mod_values(a.clone(), b.clone(), PrimitiveTypes::Int, 8), + mod_values(a.clone(), b.clone(), num_type, 8), Err(VMError::TypeMismatch { ip: 8, expected: "Integer", found: actual }) if actual == found )); let mut stack = Stack::from_vec(vec![a, b]); let original = stack.clone(); assert!(matches!( - mod_func(&mut stack, PrimitiveTypes::Int, 9), + mod_func(&mut stack, num_type, 9), Err(VMError::TypeMismatch { ip: 9, expected: "Integer", found: actual }) if actual == found )); assert_eq!(stack, original); diff --git a/rust/src/instructions/math/arithmetic/mul_func.rs b/rust/src/instructions/math/arithmetic/mul_func.rs index e1b1b585..cf0d145a 100644 --- a/rust/src/instructions/math/arithmetic/mul_func.rs +++ b/rust/src/instructions/math/arithmetic/mul_func.rs @@ -94,18 +94,25 @@ mod tests { use super::*; #[test] fn integer_directive_rejects_float_operands_without_mutating_stack() { - for (a, b, found) in [ - (Value::Float32(1.0), Value::Int32(2), "Float"), - (Value::Int32(1), Value::Float64(2.0), "Double"), + for (a, b, num_type, found) in [ + ( + Value::Float16(half::f16::ONE), + Value::Int16(2), + PrimitiveTypes::Sht, + "Half", + ), + (Value::Int32(1), Value::Float32(2.0), PrimitiveTypes::Int, "Float"), + (Value::Float64(1.0), Value::Int64(2), PrimitiveTypes::Lng, "Double"), + (Value::Int128(1), Value::Float64(2.0), PrimitiveTypes::Oct, "Double"), ] { assert!(matches!( - mul_values(a.clone(), b.clone(), PrimitiveTypes::Int, 8), + mul_values(a.clone(), b.clone(), num_type, 8), Err(VMError::TypeMismatch { ip: 8, expected: "Integer", found: actual }) if actual == found )); let mut stack = Stack::from_vec(vec![a, b]); let original = stack.clone(); assert!(matches!( - mul_func(&mut stack, PrimitiveTypes::Int, 9), + mul_func(&mut stack, num_type, 9), Err(VMError::TypeMismatch { ip: 9, expected: "Integer", found: actual }) if actual == found )); assert_eq!(stack, original); diff --git a/rust/src/instructions/math/arithmetic/neg_func.rs b/rust/src/instructions/math/arithmetic/neg_func.rs index 6c10c0f0..17b6fe28 100644 --- a/rust/src/instructions/math/arithmetic/neg_func.rs +++ b/rust/src/instructions/math/arithmetic/neg_func.rs @@ -72,26 +72,24 @@ mod tests { use super::*; #[test] fn integer_directive_rejects_float_operand_without_mutating_stack() { - let operand = Value::Float32(1.0); - assert!(matches!( - neg_values(operand.clone(), PrimitiveTypes::Int, 8), - Err(VMError::TypeMismatch { - ip: 8, - expected: "Integer", - found: "Float" - }) - )); - let mut stack = Stack::from_vec(vec![operand]); - let original = stack.clone(); - assert!(matches!( - neg_func(&mut stack, PrimitiveTypes::Int, 9), - Err(VMError::TypeMismatch { - ip: 9, - expected: "Integer", - found: "Float" - }) - )); - assert_eq!(stack, original); + for (operand, num_type, found) in [ + (Value::Float16(half::f16::ONE), PrimitiveTypes::Sht, "Half"), + (Value::Float32(1.0), PrimitiveTypes::Int, "Float"), + (Value::Float64(1.0), PrimitiveTypes::Lng, "Double"), + (Value::Float64(1.0), PrimitiveTypes::Oct, "Double"), + ] { + assert!(matches!( + neg_values(operand.clone(), num_type, 8), + Err(VMError::TypeMismatch { ip: 8, expected: "Integer", found: actual }) if actual == found + )); + let mut stack = Stack::from_vec(vec![operand]); + let original = stack.clone(); + assert!(matches!( + neg_func(&mut stack, num_type, 9), + Err(VMError::TypeMismatch { ip: 9, expected: "Integer", found: actual }) if actual == found + )); + assert_eq!(stack, original); + } } #[test] fn invalid_operand_reports_type_mismatch_and_preserves_stack() { diff --git a/rust/src/instructions/math/arithmetic/pow_func.rs b/rust/src/instructions/math/arithmetic/pow_func.rs index d7132174..5cb4c317 100644 --- a/rust/src/instructions/math/arithmetic/pow_func.rs +++ b/rust/src/instructions/math/arithmetic/pow_func.rs @@ -90,18 +90,25 @@ mod tests { use super::*; #[test] fn integer_directive_rejects_float_operands_without_mutating_stack() { - for (a, b, found) in [ - (Value::Float32(1.0), Value::Int32(2), "Float"), - (Value::Int32(1), Value::Float64(2.0), "Double"), + for (a, b, num_type, found) in [ + ( + Value::Float16(half::f16::ONE), + Value::Int16(2), + PrimitiveTypes::Sht, + "Half", + ), + (Value::Int32(1), Value::Float32(2.0), PrimitiveTypes::Int, "Float"), + (Value::Float64(1.0), Value::Int64(2), PrimitiveTypes::Lng, "Double"), + (Value::Int128(1), Value::Float64(2.0), PrimitiveTypes::Oct, "Double"), ] { assert!(matches!( - pow_values(a.clone(), b.clone(), PrimitiveTypes::Int, 8), + pow_values(a.clone(), b.clone(), num_type, 8), Err(VMError::TypeMismatch { ip: 8, expected: "Integer", found: actual }) if actual == found )); let mut stack = Stack::from_vec(vec![a, b]); let original = stack.clone(); assert!(matches!( - pow_func(&mut stack, PrimitiveTypes::Int, 9), + pow_func(&mut stack, num_type, 9), Err(VMError::TypeMismatch { ip: 9, expected: "Integer", found: actual }) if actual == found )); assert_eq!(stack, original); diff --git a/rust/src/instructions/math/arithmetic/sub_func.rs b/rust/src/instructions/math/arithmetic/sub_func.rs index 2bc91786..6e2d10ac 100644 --- a/rust/src/instructions/math/arithmetic/sub_func.rs +++ b/rust/src/instructions/math/arithmetic/sub_func.rs @@ -94,18 +94,25 @@ mod tests { use super::*; #[test] fn integer_directive_rejects_float_operands_without_mutating_stack() { - for (a, b, found) in [ - (Value::Float32(1.0), Value::Int32(2), "Float"), - (Value::Int32(1), Value::Float64(2.0), "Double"), + for (a, b, num_type, found) in [ + ( + Value::Float16(half::f16::ONE), + Value::Int16(2), + PrimitiveTypes::Sht, + "Half", + ), + (Value::Int32(1), Value::Float32(2.0), PrimitiveTypes::Int, "Float"), + (Value::Float64(1.0), Value::Int64(2), PrimitiveTypes::Lng, "Double"), + (Value::Int128(1), Value::Float64(2.0), PrimitiveTypes::Oct, "Double"), ] { assert!(matches!( - sub_values(a.clone(), b.clone(), PrimitiveTypes::Int, 8), + sub_values(a.clone(), b.clone(), num_type, 8), Err(VMError::TypeMismatch { ip: 8, expected: "Integer", found: actual }) if actual == found )); let mut stack = Stack::from_vec(vec![a, b]); let original = stack.clone(); assert!(matches!( - sub_func(&mut stack, PrimitiveTypes::Int, 9), + sub_func(&mut stack, num_type, 9), Err(VMError::TypeMismatch { ip: 9, expected: "Integer", found: actual }) if actual == found )); assert_eq!(stack, original);