✅ Phase 4 complete: All comparison operators working perfectly
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
@ -1217,7 +1217,7 @@ pub struct CompareBox;
|
|||||||
|
|
||||||
impl CompareBox {
|
impl CompareBox {
|
||||||
pub fn less(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
pub fn less(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
||||||
use crate::boxes::math_box::FloatBox;
|
use crate::boxes::FloatBox;
|
||||||
|
|
||||||
// Integer < Integer
|
// Integer < Integer
|
||||||
if let (Some(left_int), Some(right_int)) = (
|
if let (Some(left_int), Some(right_int)) = (
|
||||||
@ -1255,7 +1255,7 @@ impl CompareBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn greater(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
pub fn greater(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
||||||
use crate::boxes::math_box::FloatBox;
|
use crate::boxes::FloatBox;
|
||||||
|
|
||||||
// Integer > Integer
|
// Integer > Integer
|
||||||
if let (Some(left_int), Some(right_int)) = (
|
if let (Some(left_int), Some(right_int)) = (
|
||||||
@ -1293,7 +1293,7 @@ impl CompareBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn less_equal(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
pub fn less_equal(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
||||||
use crate::boxes::math_box::FloatBox;
|
use crate::boxes::FloatBox;
|
||||||
|
|
||||||
// Integer <= Integer
|
// Integer <= Integer
|
||||||
if let (Some(left_int), Some(right_int)) = (
|
if let (Some(left_int), Some(right_int)) = (
|
||||||
@ -1331,7 +1331,7 @@ impl CompareBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn greater_equal(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
pub fn greater_equal(left: &dyn NyashBox, right: &dyn NyashBox) -> BoolBox {
|
||||||
use crate::boxes::math_box::FloatBox;
|
use crate::boxes::FloatBox;
|
||||||
|
|
||||||
// Integer >= Integer
|
// Integer >= Integer
|
||||||
if let (Some(left_int), Some(right_int)) = (
|
if let (Some(left_int), Some(right_int)) = (
|
||||||
|
|||||||
77
test_comparison_operators.nyash
Normal file
77
test_comparison_operators.nyash
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
// test_comparison_operators.nyash - Comparison operators test
|
||||||
|
// Phase 4: Comparison operators implementation validation
|
||||||
|
|
||||||
|
print("⚖️ Testing comparison operators implementation...")
|
||||||
|
|
||||||
|
// Basic variables for testing
|
||||||
|
local f1, f2, i1, i2, s1, s2, result
|
||||||
|
|
||||||
|
// Test FloatBox comparisons
|
||||||
|
f1 = new FloatBox(3.14)
|
||||||
|
f2 = new FloatBox(2.86)
|
||||||
|
|
||||||
|
print("=== FloatBox Comparisons ===")
|
||||||
|
result = f1 > f2
|
||||||
|
print("3.14 > 2.86: " + result.toString())
|
||||||
|
|
||||||
|
result = f1 < f2
|
||||||
|
print("3.14 < 2.86: " + result.toString())
|
||||||
|
|
||||||
|
result = f1 >= f2
|
||||||
|
print("3.14 >= 2.86: " + result.toString())
|
||||||
|
|
||||||
|
result = f1 <= f2
|
||||||
|
print("3.14 <= 2.86: " + result.toString())
|
||||||
|
|
||||||
|
result = f1 == f2
|
||||||
|
print("3.14 == 2.86: " + result.toString())
|
||||||
|
|
||||||
|
result = f1 != f2
|
||||||
|
print("3.14 != 2.86: " + result.toString())
|
||||||
|
|
||||||
|
// Test IntegerBox comparisons
|
||||||
|
i1 = 10
|
||||||
|
i2 = 5
|
||||||
|
|
||||||
|
print("=== IntegerBox Comparisons ===")
|
||||||
|
result = i1 > i2
|
||||||
|
print("10 > 5: " + result.toString())
|
||||||
|
|
||||||
|
result = i1 < i2
|
||||||
|
print("10 < 5: " + result.toString())
|
||||||
|
|
||||||
|
result = i1 >= i2
|
||||||
|
print("10 >= 5: " + result.toString())
|
||||||
|
|
||||||
|
result = i1 <= i2
|
||||||
|
print("10 <= 5: " + result.toString())
|
||||||
|
|
||||||
|
result = i1 == i2
|
||||||
|
print("10 == 5: " + result.toString())
|
||||||
|
|
||||||
|
result = i1 != i2
|
||||||
|
print("10 != 5: " + result.toString())
|
||||||
|
|
||||||
|
// Test mixed type comparisons (FloatBox vs IntegerBox)
|
||||||
|
print("=== Mixed Type Comparisons ===")
|
||||||
|
result = f1 > i2
|
||||||
|
print("3.14 > 5: " + result.toString())
|
||||||
|
|
||||||
|
result = f1 < i1
|
||||||
|
print("3.14 < 10: " + result.toString())
|
||||||
|
|
||||||
|
result = i1 >= f1
|
||||||
|
print("10 >= 3.14: " + result.toString())
|
||||||
|
|
||||||
|
result = i2 <= f2
|
||||||
|
print("5 <= 2.86: " + result.toString())
|
||||||
|
|
||||||
|
// Test logical operators
|
||||||
|
print("=== Logical Operators ===")
|
||||||
|
result = (f1 > f2) and (i1 > i2)
|
||||||
|
print("(3.14 > 2.86) and (10 > 5): " + result.toString())
|
||||||
|
|
||||||
|
result = (f1 < f2) or (i1 > i2)
|
||||||
|
print("(3.14 < 2.86) or (10 > 5): " + result.toString())
|
||||||
|
|
||||||
|
print("✅ Comparison operators Phase 4 tests completed!")
|
||||||
Reference in New Issue
Block a user