diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml index 08d0843..821670a 100644 --- a/.github/workflows/run_tests.yaml +++ b/.github/workflows/run_tests.yaml @@ -58,7 +58,7 @@ jobs: - name: Run tests run: | - pixi run mojo test tests + bash ./tests/test_all.sh - name: Install pre-commit run: | diff --git a/pixi.toml b/pixi.toml index dac41ce..aa8e0a3 100644 --- a/pixi.toml +++ b/pixi.toml @@ -1,4 +1,4 @@ -[project] +[workspace] authors = ["ZHU Yuhao 朱宇浩 "] channels = ["https://conda.modular.com/max-nightly", "https://conda.modular.com/max", "https://repo.prefix.dev/modular-community", "conda-forge"] description = "An arbitrary-precision decimal and integer mathematics library for Mojo" @@ -9,7 +9,7 @@ readme = "README.md" version = "0.6.0" [dependencies] -mojo = "==0.25.6" +mojo = "==0.25.7.0" [tasks] # format the code @@ -26,9 +26,9 @@ c = "clear && pixi run clean" clean = "rm tests/decimojo.mojopkg && rm benches/decimojo.mojopkg && rm tests/tomlmojo.mojopkg" # tests (use the mojo testing tool) -b = "pixi run t big" -t = "clear && pixi run package && pixi run mojo test tests -D ASSERT=all --filter" -test = "pixi run package && pixi run mojo test tests -D ASSERT=all --filter" +b = "clear && pixi run package && bash ./tests/test_big.sh" +t = "clear && pixi run package && bash ./tests/test_all.sh" +test = "pixi run package && bash ./tests/test_all.sh" # benches bdec = "clear && pixi run package && cd benches/bigdecimal && pixi run mojo run -I ../ bench.mojo && cd ../.. && pixi run clean" diff --git a/src/decimojo/bigdecimal/bigdecimal.mojo b/src/decimojo/bigdecimal/bigdecimal.mojo index 0b9e4eb..eb3dc4d 100644 --- a/src/decimojo/bigdecimal/bigdecimal.mojo +++ b/src/decimojo/bigdecimal/bigdecimal.mojo @@ -236,7 +236,7 @@ struct BigDecimal( return Self(coefficient=BigUInt(words^), scale=0, sign=sign) @staticmethod - fn from_uint(value: Int) -> Self: + fn from_uint(value: UInt) -> Self: """Creates a BigDecimal from an unsigned integer.""" return Self(coefficient=BigUInt.from_uint(value), scale=0, sign=False) diff --git a/src/decimojo/bigdecimal/trigonometric.mojo b/src/decimojo/bigdecimal/trigonometric.mojo index 1a3548a..e4894ce 100644 --- a/src/decimojo/bigdecimal/trigonometric.mojo +++ b/src/decimojo/bigdecimal/trigonometric.mojo @@ -492,7 +492,7 @@ fn arctan(x: BigDecimal, precision: Int) raises -> BigDecimal: # arctan(x) = 2 * arctan(x / (1 + sqrt(1 + x²))) # This is to ensure convergence of the Taylor series. # print("Using identity for arctan with |x| <= 2") - print(bdec_1 + x * x) + # print(bdec_1 + x * x) var sqrt_term = (bdec_1 + x * x).sqrt(precision=working_precision) var x_divided = x.true_divide( bdec_1 + sqrt_term, precision=working_precision diff --git a/src/decimojo/bigint/bigint.mojo b/src/decimojo/bigint/bigint.mojo index ddd3163..93b3849 100644 --- a/src/decimojo/bigint/bigint.mojo +++ b/src/decimojo/bigint/bigint.mojo @@ -645,7 +645,7 @@ struct BigInt( # Other dunders # ===------------------------------------------------------------------=== # - fn __merge_with__[other_type: __type_of(BigDecimal)](self) -> BigDecimal: + fn __merge_with__[other_type: type_of(BigDecimal)](self) -> BigDecimal: "Merges this BigInt with a BigDecimal into a BigDecimal." return BigDecimal(self) diff --git a/src/decimojo/biguint/arithmetics.mojo b/src/decimojo/biguint/arithmetics.mojo index 4f68ca4..0e3083c 100644 --- a/src/decimojo/biguint/arithmetics.mojo +++ b/src/decimojo/biguint/arithmetics.mojo @@ -300,18 +300,18 @@ fn add_slices_simd( min(n_words_x_slice, n_words_y_slice) ) - var longer: Pointer[BigUInt, __origin_of(x, y)] + var longer: Pointer[BigUInt, origin_of(x, y)] var n_words_longer_slice: Int var n_words_shorter_slice: Int var longer_start: Int if n_words_x_slice >= n_words_y_slice: - longer = Pointer[BigUInt, __origin_of(x, y)](to=x) + longer = Pointer[BigUInt, origin_of(x, y)](to=x) n_words_longer_slice = n_words_x_slice n_words_shorter_slice = n_words_y_slice longer_start = bounds_x[0] else: - longer = Pointer[BigUInt, __origin_of(x, y)](to=y) + longer = Pointer[BigUInt, origin_of(x, y)](to=y) n_words_longer_slice = n_words_y_slice n_words_shorter_slice = n_words_x_slice longer_start = bounds_y[0] diff --git a/src/decimojo/biguint/biguint.mojo b/src/decimojo/biguint/biguint.mojo index 6b9c16f..bcc896d 100644 --- a/src/decimojo/biguint/biguint.mojo +++ b/src/decimojo/biguint/biguint.mojo @@ -465,8 +465,8 @@ struct BigUInt( return Self() var list_of_words = List[UInt32]() - var remainder: Int = value - var quotient: Int + var remainder: UInt = value + var quotient: UInt while remainder != 0: quotient = remainder // 1_000_000_000 @@ -904,7 +904,7 @@ struct BigUInt( # " of UInt128 (340282366920938463463374607431768211455)" # ) - var result: UInt128 = 0 + var result: UInt128 if len(self.words) == 1: result = self.words._data.load[width=1]().cast[DType.uint128]() @@ -1295,11 +1295,11 @@ struct BigUInt( # Other dunders # ===------------------------------------------------------------------=== # - fn __merge_with__[other_type: __type_of(BigInt)](self) -> BigInt: + fn __merge_with__[other_type: type_of(BigInt)](self) -> BigInt: "Merges this BigUInt with a BigInt into a BigInt." return BigInt(self) - fn __merge_with__[other_type: __type_of(BigDecimal)](self) -> BigDecimal: + fn __merge_with__[other_type: type_of(BigDecimal)](self) -> BigDecimal: "Merges this BigUInt with a BigDecimal into a BigDecimal." return BigDecimal(self) diff --git a/src/decimojo/decimal128/decimal128.mojo b/src/decimojo/decimal128/decimal128.mojo index 702552f..e77668f 100644 --- a/src/decimojo/decimal128/decimal128.mojo +++ b/src/decimojo/decimal128/decimal128.mojo @@ -316,7 +316,7 @@ struct Decimal128( var flags: UInt32 = 0 flags |= (scale << Self.SCALE_SHIFT) & Self.SCALE_MASK - flags |= sign << 31 + flags |= UInt32(sign) << 31 return Self(low, mid, high, flags) @@ -489,7 +489,7 @@ struct Decimal128( var result = UnsafePointer(to=value).bitcast[Decimal128]()[] result.flags |= (scale << Self.SCALE_SHIFT) & Self.SCALE_MASK - result.flags |= sign << 31 + result.flags |= UInt32(sign) << 31 return result @@ -528,7 +528,7 @@ struct Decimal128( if value_bytes_len == 0: return Decimal128.ZERO() - if value_bytes_len != value_string_slice.char_length(): + if value_bytes_len != Int(value_string_slice.char_length()): raise Error( String( "There are invalid characters in decimal128 string: {}" diff --git a/src/decimojo/str.mojo b/src/decimojo/str.mojo index 5be5aaf..f59036b 100644 --- a/src/decimojo/str.mojo +++ b/src/decimojo/str.mojo @@ -65,7 +65,7 @@ fn parse_numeric_string( if value_bytes_len == 0: raise Error("Error in `parse_numeric_string`: Empty string.") - if value_bytes_len != value_string_slice.char_length(): + if value_bytes_len != Int(value_string_slice.char_length()): raise Error( String( "There are invalid characters in the string of the number: {}" diff --git a/tests/bigdecimal/test_bigdecimal_arithmetics.mojo b/tests/bigdecimal/test_bigdecimal_arithmetics.mojo index e16444e..4dc2ef2 100644 --- a/tests/bigdecimal/test_bigdecimal_arithmetics.mojo +++ b/tests/bigdecimal/test_bigdecimal_arithmetics.mojo @@ -22,11 +22,12 @@ fn test_bigdecimal_arithmetics() raises: var toml = parse_file(file_path) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigDecimal addition...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal addition...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "addition_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a) + BDec(test_case.b) try: @@ -47,13 +48,21 @@ fn test_bigdecimal_arithmetics() raises: pydecimal.Decimal(test_case.a) + pydecimal.Decimal(test_case.b) ), + "\n", ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal subtraction...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal subtraction...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "subtraction_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a) - BDec(test_case.b) try: @@ -74,13 +83,21 @@ fn test_bigdecimal_arithmetics() raises: pydecimal.Decimal(test_case.a) - pydecimal.Decimal(test_case.b) ), + "\n", ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal multiplication...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal multiplication...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "multiplication_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a) * BDec(test_case.b) try: @@ -101,15 +118,25 @@ fn test_bigdecimal_arithmetics() raises: pydecimal.Decimal(test_case.a) * pydecimal.Decimal(test_case.b) ), + "\n", ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal division...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal division...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "division_tests") + count_wrong = 0 for test_case in test_cases: - var result = BDec(test_case.a) / BDec(test_case.b) + var result = BDec(test_case.a).true_divide( + BDec(test_case.b), precision=28 + ) try: testing.assert_equal( lhs=String(result), @@ -128,12 +155,19 @@ fn test_bigdecimal_arithmetics() raises: pydecimal.Decimal(test_case.a) / pydecimal.Decimal(test_case.b) ), + "\n", ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) fn main() raises: - print("Running BigDecimal arithmetic tests") + # print("Running BigDecimal arithmetic tests") - test_bigdecimal_arithmetics() + testing.TestSuite.discover_tests[__functions_in_module()]().run() - print("All BigDecimal arithmetic tests passed!") + # print("All BigDecimal arithmetic tests passed!") diff --git a/tests/bigdecimal/test_bigdecimal_compare.mojo b/tests/bigdecimal/test_bigdecimal_compare.mojo index 3dc7564..0e03c7e 100644 --- a/tests/bigdecimal/test_bigdecimal_compare.mojo +++ b/tests/bigdecimal/test_bigdecimal_compare.mojo @@ -16,9 +16,9 @@ fn test_bigdecimal_compare() raises: var toml = parse_file(file_path) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigDecimal compare_absolute...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal compare_absolute...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "compare_absolute_tests") for test_case in test_cases: @@ -29,9 +29,9 @@ fn test_bigdecimal_compare() raises: msg=test_case.description, ) - print("------------------------------------------------------") - print("Testing BigDecimal > operator...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal > operator...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "greater_than_tests") for test_case in test_cases: var result = BDec(test_case.a) > BDec(test_case.b) @@ -41,9 +41,9 @@ fn test_bigdecimal_compare() raises: msg=test_case.description, ) - print("------------------------------------------------------") - print("Testing BigDecimal < operator...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal < operator...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "less_than_tests") for test_case in test_cases: var result = BDec(test_case.a) < BDec(test_case.b) @@ -53,9 +53,9 @@ fn test_bigdecimal_compare() raises: msg=test_case.description, ) - print("------------------------------------------------------") - print("Testing BigDecimal >= operator...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal >= operator...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "greater_than_or_equal_tests") for test_case in test_cases: var result = BDec(test_case.a) >= BDec(test_case.b) @@ -65,9 +65,9 @@ fn test_bigdecimal_compare() raises: msg=test_case.description, ) - print("------------------------------------------------------") - print("Testing BigDecimal <= operator...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal <= operator...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "less_than_or_equal_tests") for test_case in test_cases: var result = BDec(test_case.a) <= BDec(test_case.b) @@ -77,9 +77,9 @@ fn test_bigdecimal_compare() raises: msg=test_case.description, ) - print("------------------------------------------------------") - print("Testing BigDecimal == operator...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal == operator...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "equal_tests") for test_case in test_cases: var result = BDec(test_case.a) == BDec(test_case.b) @@ -89,9 +89,9 @@ fn test_bigdecimal_compare() raises: msg=test_case.description, ) - print("------------------------------------------------------") - print("Testing BigDecimal != operator...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal != operator...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "not_equal_tests") for test_case in test_cases: var result = BDec(test_case.a) != BDec(test_case.b) @@ -103,9 +103,9 @@ fn test_bigdecimal_compare() raises: fn main() raises: - print("Running BigDecimal comparison tests") + # print("Running BigDecimal comparison tests") # Run compare_absolute tests - test_bigdecimal_compare() + testing.TestSuite.discover_tests[__functions_in_module()]().run() - print("All BigDecimal comparison tests passed!") + # print("All BigDecimal comparison tests passed!") diff --git a/tests/bigdecimal/test_bigdecimal_exponential.mojo b/tests/bigdecimal/test_bigdecimal_exponential.mojo index 153f6aa..02d0c71 100644 --- a/tests/bigdecimal/test_bigdecimal_exponential.mojo +++ b/tests/bigdecimal/test_bigdecimal_exponential.mojo @@ -17,11 +17,12 @@ fn test_bigdecimal_exponential() raises: var toml = parse_file(file_path) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigDecimal square root...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal square root...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "sqrt_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).sqrt(precision=28) try: @@ -40,12 +41,19 @@ fn test_bigdecimal_exponential() raises: "\n Python decimal result (for reference):", String(pydecimal.Decimal(test_case.a).sqrt()), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal natural logarithm (ln)...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal natural logarithm (ln)...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "ln_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).ln(precision=28) try: @@ -64,12 +72,19 @@ fn test_bigdecimal_exponential() raises: "\n Python decimal result (for reference):", String(pydecimal.Decimal(test_case.a).ln()), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal root function...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal root function...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "root_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).root(BDec(test_case.b), precision=28) try: @@ -91,12 +106,19 @@ fn test_bigdecimal_exponential() raises: ** (pydecimal.Decimal(1) / pydecimal.Decimal(test_case.b)) ), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal power function...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal power function...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "power_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).power(BDec(test_case.b), precision=28) try: @@ -118,12 +140,18 @@ fn test_bigdecimal_exponential() raises: ** pydecimal.Decimal(test_case.b) ), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) fn test_negative_sqrt() raises: """Test that square root of negative number raises an error.""" - print("------------------------------------------------------") - print("Testing BigDecimal square root with negative input...") + # print("------------------------------------------------------") + # print("Testing BigDecimal square root with negative input...") var negative_number = BDec("-1") @@ -137,14 +165,14 @@ fn test_negative_sqrt() raises: testing.assert_true( exception_caught, "Square root of negative number should raise an error" ) - print("✓ Square root of negative number correctly raises an error") + # print("✓ Square root of negative number correctly raises an error") fn test_ln_invalid_inputs() raises: """Test that natural logarithm with invalid inputs raises appropriate errors. """ - print("------------------------------------------------------") - print("Testing BigDecimal natural logarithm with invalid inputs...") + # print("------------------------------------------------------") + # print("Testing BigDecimal natural logarithm with invalid inputs...") # Test 1: ln of zero should raise an error var zero = BDec("0") @@ -155,7 +183,7 @@ fn test_ln_invalid_inputs() raises: except: exception_caught = True testing.assert_true(exception_caught, "ln(0) should raise an error") - print("✓ ln(0) correctly raises an error") + # print("✓ ln(0) correctly raises an error") # Test 2: ln of negative number should raise an error var negative = BDec("-1") @@ -167,13 +195,13 @@ fn test_ln_invalid_inputs() raises: testing.assert_true( exception_caught, "ln of negative number should raise an error" ) - print("✓ ln of negative number correctly raises an error") + # print("✓ ln of negative number correctly raises an error") fn test_root_invalid_inputs() raises: """Test that root function with invalid inputs raises appropriate errors.""" - print("------------------------------------------------------") - print("Testing BigDecimal root with invalid inputs...") + # print("------------------------------------------------------") + # print("Testing BigDecimal root with invalid inputs...") # Test 1: 0th root should raise an error var a1 = BDec("16") @@ -185,7 +213,7 @@ fn test_root_invalid_inputs() raises: except: exception_caught = True testing.assert_true(exception_caught, "0th root should raise an error") - print("✓ 0th root correctly raises an error") + # print("✓ 0th root correctly raises an error") # Test 2: Even root of negative number should raise an error var a2 = BDec("-16") @@ -198,7 +226,7 @@ fn test_root_invalid_inputs() raises: testing.assert_true( exception_caught, "Even root of negative number should raise an error" ) - print("✓ Even root of negative number correctly raises an error") + # print("✓ Even root of negative number correctly raises an error") # Test 3: Fractional root with even denominator of negative number should raise an error var a3 = BDec("-16") @@ -215,17 +243,17 @@ fn test_root_invalid_inputs() raises: " raise an error" ), ) - print( - "✓ Fractional root with even denominator of negative number correctly" - " raises an error" - ) + # print( + # "✓ Fractional root with even denominator of negative number correctly" + # " raises an error" + # ) fn test_power_invalid_inputs() raises: """Test that power function with invalid inputs raises appropriate errors. """ - print("------------------------------------------------------") - print("Testing BigDecimal power with invalid inputs...") + # print("------------------------------------------------------") + # print("Testing BigDecimal power with invalid inputs...") # Test 1: 0^0 should raise an error (undefined) var base1 = BDec("0") @@ -237,7 +265,7 @@ fn test_power_invalid_inputs() raises: except: exception_caught = True testing.assert_true(exception_caught, "0^0 should raise an error") - print("✓ 0^0 correctly raises an error") + # print("✓ 0^0 correctly raises an error") # Test 2: 0^-1 should raise an error (division by zero) var base2 = BDec("0") @@ -250,7 +278,7 @@ fn test_power_invalid_inputs() raises: testing.assert_true( exception_caught, "0 raised to a negative power should raise an error" ) - print("✓ 0 raised to a negative power correctly raises an error") + # print("✓ 0 raised to a negative power correctly raises an error") # Test 3: Negative number raised to a fractional power should raise an error var base3 = BDec("-2") @@ -264,28 +292,26 @@ fn test_power_invalid_inputs() raises: exception_caught, "Negative number raised to a fractional power should raise an error", ) - print( - "✓ Negative number raised to a fractional power correctly raises an" - " error" - ) + # print( + # "✓ Negative number raised to a fractional power correctly raises an" + # " error" + # ) fn main() raises: - print("Running BigDecimal exponential tests") + # print("Running BigDecimal exponential tests") # Run all tests - test_bigdecimal_exponential() - + # test_bigdecimal_exponential() # Test sqrt of negative number - test_negative_sqrt() - + # test_negative_sqrt() # Test root with invalid inputs - test_root_invalid_inputs() - + # test_root_invalid_inputs() # Test power with invalid inputs - test_power_invalid_inputs() - + # test_power_invalid_inputs() # Test ln with invalid inputs - test_ln_invalid_inputs() + # test_ln_invalid_inputs() + + testing.TestSuite.discover_tests[__functions_in_module()]().run() - print("All BigDecimal exponential tests passed!") + # print("All BigDecimal exponential tests passed!") diff --git a/tests/bigdecimal/test_bigdecimal_rounding.mojo b/tests/bigdecimal/test_bigdecimal_rounding.mojo index 367b3f4..158c5cf 100644 --- a/tests/bigdecimal/test_bigdecimal_rounding.mojo +++ b/tests/bigdecimal/test_bigdecimal_rounding.mojo @@ -17,12 +17,13 @@ fn test_bigdecimal_rounding() raises: var toml = parse_file(file_path) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigDecimal ROUND_DOWN mode...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal ROUND_DOWN mode...") + # print("------------------------------------------------------") pydecimal.getcontext().rounding = pydecimal.ROUND_DOWN test_cases = load_test_cases(toml, "round_down_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).round( Int(test_case.b), RoundingMode.down() @@ -45,13 +46,20 @@ fn test_bigdecimal_rounding() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal ROUND_UP mode...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal ROUND_UP mode...") + # print("------------------------------------------------------") pydecimal.getcontext().rounding = pydecimal.ROUND_UP test_cases = load_test_cases(toml, "round_up_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).round( Int(test_case.b), RoundingMode.up() @@ -74,16 +82,23 @@ fn test_bigdecimal_rounding() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal ROUND_HALF_UP mode...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal ROUND_HALF_UP mode...") + # print("------------------------------------------------------") pydecimal.getcontext().rounding = pydecimal.ROUND_HALF_UP test_cases = load_test_cases(toml, "round_half_up_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).round( - Int(test_case.b), RoundingMode.up() + Int(test_case.b), RoundingMode.half_up() ) try: testing.assert_equal( @@ -103,13 +118,20 @@ fn test_bigdecimal_rounding() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal ROUND_HALF_EVEN (banker's rounding) mode...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal ROUND_HALF_EVEN (banker's rounding) mode...") + # print("------------------------------------------------------") pydecimal.getcontext().rounding = pydecimal.ROUND_HALF_EVEN test_cases = load_test_cases(toml, "round_half_even_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).round( Int(test_case.b), RoundingMode.half_even() @@ -132,12 +154,19 @@ fn test_bigdecimal_rounding() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal rounding with extreme values...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal rounding with extreme values...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "extreme_value_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).round( Int(test_case.b), RoundingMode.half_even() @@ -160,12 +189,19 @@ fn test_bigdecimal_rounding() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal rounding with special edge cases...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal rounding with special edge cases...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "edge_case_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).round( Int(test_case.b), RoundingMode.half_even() @@ -188,15 +224,22 @@ fn test_bigdecimal_rounding() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) - - print("------------------------------------------------------") - print( - "Testing BigDecimal rounding with negative precision (rounding to tens," - " hundreds, etc.)" + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", ) - print("------------------------------------------------------") + + # print("------------------------------------------------------") + # print( + # "Testing BigDecimal rounding with negative precision (rounding to tens," + # " hundreds, etc.)" + # ) + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "precision_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).round( Int(test_case.b), RoundingMode.half_even() @@ -219,12 +262,19 @@ fn test_bigdecimal_rounding() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) - print("------------------------------------------------------") - print("Testing BigDecimal rounding with scientific notation inputs...") - print("------------------------------------------------------") + # print("------------------------------------------------------") + # print("Testing BigDecimal rounding with scientific notation inputs...") + # print("------------------------------------------------------") test_cases = load_test_cases(toml, "scientific_tests") + count_wrong = 0 for test_case in test_cases: var result = BDec(test_case.a).round( Int(test_case.b), RoundingMode.half_even() @@ -247,12 +297,18 @@ fn test_bigdecimal_rounding() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) fn test_default_rounding_mode() raises: """Test that the default rounding mode is ROUND_HALF_EVEN.""" - print("------------------------------------------------------") - print("Testing BigDecimal default rounding mode...") + # print("------------------------------------------------------") + # print("Testing BigDecimal default rounding mode...") var value = BDec("2.5") var result = value.round(0) @@ -274,16 +330,16 @@ fn test_default_rounding_mode() raises: "Default rounding mode should be ROUND_HALF_EVEN", ) - print("✓ Default rounding mode tests passed") + # print("✓ Default rounding mode tests passed") fn main() raises: - print("Running BigDecimal rounding tests") + # print("Running BigDecimal rounding tests") # Test different rounding modes - test_bigdecimal_rounding() - + # test_bigdecimal_rounding() # Test default rounding mode - test_default_rounding_mode() + # test_default_rounding_mode() + testing.TestSuite.discover_tests[__functions_in_module()]().run() - print("All BigDecimal rounding tests passed!") + # print("All BigDecimal rounding tests passed!") diff --git a/tests/bigdecimal/test_bigdecimal_trigonometric.mojo b/tests/bigdecimal/test_bigdecimal_trigonometric.mojo index e36ad9b..4720736 100644 --- a/tests/bigdecimal/test_bigdecimal_trigonometric.mojo +++ b/tests/bigdecimal/test_bigdecimal_trigonometric.mojo @@ -15,19 +15,32 @@ fn run_test[ func: fn (BDec, Int) raises -> BDec ](toml: tomlmojo.parser.TOMLDocument, table_name: String, msg: String) raises: """Run a specific test case from the TOML document.""" - print("------------------------------------------------------") - print("Testing BigDecimal ", msg, "...", sep="") + # print("------------------------------------------------------") + # print("Testing BigDecimal ", msg, "...", sep="") var test_cases = load_test_cases(toml, table_name) + count_wrong = 0 for test_case in test_cases: + var result = func(BDec(test_case.a), 50) try: - var result = func(BDec(test_case.a), 50) testing.assert_equal( lhs=result, rhs=BDec(test_case.expected), msg=test_case.description, ) except e: + print( + test_case.description, + "\n Expected:", + test_case.expected, + "\n Got:", + ) print(test_case.description) + count_wrong += 1 + testing.assert_equal( + count_wrong, + 0, + "Some test cases failed. See above for details.", + ) fn test_bigdecimal_trignometric() raises: @@ -62,9 +75,8 @@ fn test_bigdecimal_trignometric() raises: fn main() raises: - print("Running BigDecimal trigonometric tests") + # print("Running BigDecimal trigonometric tests") - # Run all tests - test_bigdecimal_trignometric() + testing.TestSuite.discover_tests[__functions_in_module()]().run() - print("All BigDecimal trigonometric tests passed!") + # print("All BigDecimal trigonometric tests passed!") diff --git a/tests/bigdecimal/test_data/bigdecimal_arithmetics.toml b/tests/bigdecimal/test_data/bigdecimal_arithmetics.toml index 435c2d9..57354ba 100644 --- a/tests/bigdecimal/test_data/bigdecimal_arithmetics.toml +++ b/tests/bigdecimal/test_data/bigdecimal_arithmetics.toml @@ -5,312 +5,312 @@ [[addition_tests]] a = "42" b = "58" -expected = "100" description = "Simple integer addition" +expected = "100" [[addition_tests]] a = "3.14" b = "2.71" -expected = "5.85" description = "Simple decimal addition" +expected = "5.85" [[addition_tests]] a = "0" b = "0" -expected = "0" description = "Zero plus zero" +expected = "0" [[addition_tests]] a = "1" b = "0" -expected = "1" description = "Addition with zero" +expected = "1" [[addition_tests]] a = "123.456" b = "0" -expected = "123.456" description = "Decimal plus zero" +expected = "123.456" # === DIFFERENT SCALE TESTS === [[addition_tests]] a = "1.2345" b = "5.67" -expected = "6.9045" description = "Addition with different scales" +expected = "6.9045" [[addition_tests]] a = "1.23456789012345678901234567" b = "5.6" -expected = "6.83456789012345678901234567" description = "Addition with very different scales" +expected = "6.83456789012345678901234567" [[addition_tests]] a = "9.999" b = "0.001" -expected = "10.000" description = "Addition with carry" +expected = "10.000" [[addition_tests]] a = "999999.999999" b = "0.000001" -expected = "1000000.000000" description = "Addition causing scale reduction" +expected = "1000000.000000" [[addition_tests]] a = "1.000000000000000000000000001" b = "2.000000000000000000000000002" -expected = "3.000000000000000000000000003" description = "Addition with high precision" +expected = "3.000000000000000000000000003" # === SIGN COMBINATION TESTS === [[addition_tests]] a = "-1" b = "-2" -expected = "-3" description = "Negative plus negative" +expected = "-3" [[addition_tests]] a = "-3.14" b = "10" -expected = "6.86" description = "Negative plus positive (negative smaller)" +expected = "6.86" [[addition_tests]] a = "-10" b = "3.14" -expected = "-6.86" description = "Negative plus positive (negative larger)" +expected = "-6.86" [[addition_tests]] a = "-5.75" b = "-10.25" -expected = "-16.00" description = "Negative plus negative" +expected = "-16.00" [[addition_tests]] a = "123.456" b = "-123.456" -expected = "0.000" description = "Addition resulting in zero (pos + neg)" +expected = "0.000" [[addition_tests]] a = "0.0000001" b = "-0.00000005" -expected = "0.00000005" description = "Addition near zero (small difference)" +expected = "5E-8" # === LARGE NUMBER TESTS === [[addition_tests]] a = "9999999999999999999999999999" b = "1" -expected = "10000000000000000000000000000" description = "Large integer addition" +expected = "1.0000000000000000000000000000E+28" [[addition_tests]] a = "-9999999999999999999999999999" b = "9999999999999999999999999998" -expected = "-1" description = "Large negative plus positive" +expected = "-1" [[addition_tests]] a = "99999999999999999999.99999999" b = "0.00000001" -expected = "100000000000000000000.00000000" description = "Very large decimal addition with carry" +expected = "100000000000000000000.00000000" [[addition_tests]] a = "10000000000000000000000000000" b = "0.00000000000000000000000001" -expected = "10000000000000000000000000000.00000000000000000000000001" description = "Very large plus very small" +expected = "1.000000000000000000000000000000000000000000000000000001E+28" # === SMALL NUMBER TESTS === [[addition_tests]] a = "0.0000000000000000000000001" b = "0.0000000000000000000000002" -expected = "0.0000000000000000000000003" description = "Very small positive values" +expected = "3E-25" [[addition_tests]] a = "-0.0000000000000000000000001" b = "-0.0000000000000000000000002" -expected = "-0.0000000000000000000000003" description = "Very small negative values" +expected = "-3E-25" [[addition_tests]] a = "0.0000000000000001" b = "0.00000000000000000000000001" -expected = "0.00000000000000010000000001" description = "Small values with different scales" +expected = "1.0000000001E-16" # === SCIENTIFIC NOTATION TESTS === [[addition_tests]] a = "1.23e5" b = "4.56e4" -expected = "1.686E+5" description = "Addition with scientific notation" +expected = "1.686E+5" [[addition_tests]] a = "1.23e-10" b = "4.56e-11" -expected = "0.0000000001686" description = "Addition with negative exponents" +expected = "1.686E-10" [[addition_tests]] a = "1.23e-10" b = "4.56e10" -expected = "45600000000.000000000123" description = "Addition with extreme exponent difference" +expected = "45600000000.000000000123" # === SPECIAL CASES === [[addition_tests]] a = "3.14159265358979323846" b = "2.71828182845904523536" -expected = "5.85987448204883847382" description = "Addition of mathematical constants (PI + E)" +expected = "5.85987448204883847382" [[addition_tests]] a = "0.33333333333333333333333333" b = "0.66666666666666666666666667" -expected = "1.00000000000000000000000000" description = "Addition of repeating patterns" +expected = "1.00000000000000000000000000" [[addition_tests]] a = "0.499999999999999999" b = "0.500000000000000001" -expected = "1.000000000000000000" description = "Addition resulting in exact integer" +expected = "1.000000000000000000" [[addition_tests]] a = "9.99999999999999999999999999" b = "0.00000000000000000000000001" -expected = "10.00000000000000000000000000" description = "Addition at precision limit with carry" +expected = "10.00000000000000000000000000" # === FINANCIAL SCENARIOS === [[addition_tests]] a = "10542.75" b = "3621.50" -expected = "14164.25" description = "Financial numbers (dollars and cents)" +expected = "14164.25" [[addition_tests]] a = "0.09" b = "0.01" -expected = "0.10" description = "Financial numbers (cents)" +expected = "0.10" [[addition_tests]] a = "99.99" b = "0.01" -expected = "100.00" description = "Financial addition with carry" +expected = "100.00" # === PRECISION BOUNDARY TESTS === [[addition_tests]] a = "999999999999999999.9999999" b = "0.0000001" -expected = "1000000000000000000.0000000" description = "Addition with rounding at precision boundary" +expected = "1000000000000000000.0000000" [[addition_tests]] a = "1.1000000000000000000000000" b = "2.2000000000000000000000000" -expected = "3.3000000000000000000000000" description = "Addition with trailing zeros" +expected = "3.3000000000000000000000000" [[addition_tests]] a = "0.125" b = "0.0625" -expected = "0.1875" description = "Addition of binary-friendly values (1/8 + 1/16)" +expected = "0.1875" [[addition_tests]] a = "0.1" b = "0.2" -expected = "0.3" description = "Simple tenths addition" +expected = "0.3" # === ADDITIONAL EDGE CASES === [[addition_tests]] a = "0.000000000000000000000000009" b = "0.000000000000000000000000001" -expected = "0.000000000000000000000000010" description = "Addition near zero with precision limit" +expected = "1.0E-26" [[addition_tests]] a = "0.0" b = "0.0" -expected = "0.0" description = "Zero plus zero with decimal point" +expected = "0.0" [[addition_tests]] a = "0.142857142857142857142857" b = "0.076923076923076923076923" -expected = "0.219780219780219780219780" description = "Addition of recurring decimals (1/7 + 1/13)" +expected = "0.219780219780219780219780" [[addition_tests]] a = "-0" b = "0" -expected = "0" description = "Addition of negative zero and zero" +expected = "0" [[addition_tests]] a = "1E6" b = "2000000" -expected = "3000000" description = "Addition with E notation" +expected = "3000000" [[addition_tests]] a = "1.79769313486231570E+308" b = "10" -expected = "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010" description = "Addition near max double precision" +expected = "1.79769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010E+308" [[addition_tests]] a = "-9.9999999999999999999999" b = "9.9999999999999999999999" -expected = "0.0000000000000000000000" description = "Exact cancellation of large numbers" +expected = "0E-22" [[addition_tests]] a = "123456789012345678.987654321012345678" b = "987654321098765432.123456789098765432" -expected = "1111111110111111111.111111110111111110" description = "Addition with digit carryover throughout" +expected = "1111111110111111111.111111110111111110" # === SPECIFIC APPLICATION DOMAINS === [[addition_tests]] a = "37.7749" b = "0.0001" -expected = "37.7750" description = "GPS coordinates (latitude + delta)" +expected = "37.7750" [[addition_tests]] a = "98.6" b = "1.2" -expected = "99.8" description = "Body temperature in Fahrenheit" +expected = "99.8" [[addition_tests]] a = "273.15" b = "32.0" -expected = "305.15" description = "Temperature conversion constants (K offset + F offset)" +expected = "305.15" [[addition_tests]] a = "987654321987654321.987654321" b = "0.000000000000000000000000001" -expected = "987654321987654321.987654321000000000000000001" description = "Addition with extreme scale difference" +expected = "987654321987654321.987654321000000000000000001" [[addition_tests]] a = "0.0425" b = "0.0015" -expected = "0.0440" description = "Interest rate calculation" +expected = "0.0440" # ===----------------------------------------------------------------------=== # # Test cases for BigDecimal subtraction @@ -319,318 +319,318 @@ description = "Interest rate calculation" [[subtraction_tests]] a = "100" b = "42" -expected = "58" description = "Simple integer subtraction" +expected = "58" [[subtraction_tests]] a = "5.85" b = "2.71" -expected = "3.14" description = "Simple decimal subtraction" +expected = "3.14" [[subtraction_tests]] a = "0" b = "0" -expected = "0" description = "Zero minus zero" +expected = "0" [[subtraction_tests]] a = "1" b = "0" -expected = "1" description = "Subtraction with zero" +expected = "1" [[subtraction_tests]] a = "123.456" b = "0" -expected = "123.456" description = "Decimal minus zero" +expected = "123.456" # === DIFFERENT SCALE TESTS === [[subtraction_tests]] a = "10.2345" b = "5.67" -expected = "4.5645" description = "Subtraction with different scales" +expected = "4.5645" [[subtraction_tests]] a = "5.23456789012345678901234567" b = "1.6" -expected = "3.63456789012345678901234567" description = "Subtraction with very different scales" +expected = "3.63456789012345678901234567" [[subtraction_tests]] a = "10.000" b = "0.001" -expected = "9.999" description = "Subtraction with borrowing" +expected = "9.999" [[subtraction_tests]] a = "1000000.000000" b = "0.000001" -expected = "999999.999999" description = "Subtraction causing scale reduction" +expected = "999999.999999" [[subtraction_tests]] a = "3.000000000000000000000000003" b = "2.000000000000000000000000002" -expected = "1.000000000000000000000000001" description = "Subtraction with high precision" +expected = "1.000000000000000000000000001" # === SIGN COMBINATION TESTS === [[subtraction_tests]] a = "-1" b = "-2" -expected = "1" description = "Negative minus negative" +expected = "1" [[subtraction_tests]] a = "10" b = "-3.14" -expected = "13.14" description = "Positive minus negative (becomes addition)" +expected = "13.14" [[subtraction_tests]] a = "-10" b = "3.14" -expected = "-13.14" description = "Negative minus positive" +expected = "-13.14" [[subtraction_tests]] a = "50" b = "60.5" -expected = "-10.5" description = "Subtraction resulting in negative" +expected = "-10.5" [[subtraction_tests]] a = "123.456" b = "123.456" -expected = "0.000" description = "Subtraction resulting in zero" +expected = "0.000" [[subtraction_tests]] a = "0.0000001" b = "0.00000005" -expected = "0.00000005" description = "Subtraction near zero (small difference)" +expected = "5E-8" # === LARGE NUMBER TESTS === [[subtraction_tests]] a = "10000000000000000000000000000" b = "1" -expected = "9999999999999999999999999999" description = "Large integer subtraction" +expected = "9999999999999999999999999999" [[subtraction_tests]] a = "-9999999999999999999999999999" b = "1" -expected = "-10000000000000000000000000000" description = "Large negative minus positive" +expected = "-1.0000000000000000000000000000E+28" [[subtraction_tests]] a = "100000000000000000000.00000000" b = "0.00000001" -expected = "99999999999999999999.99999999" description = "Very large decimal subtraction with borrowing" +expected = "99999999999999999999.99999999" [[subtraction_tests]] a = "10000000000000000000000000" b = "0.00000000000000000000000001" -expected = "9999999999999999999999999.99999999999999999999999999" description = "Very large minus very small" +expected = "9999999999999999999999999.99999999999999999999999999" # === SMALL NUMBER TESTS === [[subtraction_tests]] a = "0.0000000000000000000000003" b = "0.0000000000000000000000002" -expected = "0.0000000000000000000000001" description = "Very small positive values" +expected = "1E-25" [[subtraction_tests]] a = "-0.0000000000000000000000003" b = "-0.0000000000000000000000002" -expected = "-0.0000000000000000000000001" description = "Very small negative values (negative minus negative)" +expected = "-1E-25" [[subtraction_tests]] a = "-0.0000000000000000000000002" b = "-0.0000000000000000000000003" -expected = "0.0000000000000000000000001" description = "Very small negative values (smaller negative minus larger negative)" +expected = "1E-25" [[subtraction_tests]] a = "0.00000000003" b = "0.000000000000000000001" -expected = "0.000000000029999999999" description = "Small values with different scales" +expected = "2.9999999999E-11" # === SCIENTIFIC NOTATION TESTS === [[subtraction_tests]] a = "1.23e5" b = "4.56e4" -expected = "7.74E+4" description = "Subtraction with scientific notation" +expected = "7.74E+4" [[subtraction_tests]] a = "1.23e-10" b = "4.56e-11" -expected = "0.0000000000774" description = "Subtraction with negative exponents" +expected = "7.74E-11" [[subtraction_tests]] a = "4.56e10" b = "1.23e-10" -expected = "45599999999.999999999877" description = "Subtraction with extreme exponent difference" +expected = "45599999999.999999999877" # === SPECIAL CASES === [[subtraction_tests]] a = "3.14159265358979323846" b = "2.71828182845904523536" -expected = "0.42331082513074800310" description = "Subtraction of mathematical constants (PI - E)" +expected = "0.42331082513074800310" [[subtraction_tests]] a = "1.00000000000000000000000000" b = "0.33333333333333333333333333" -expected = "0.66666666666666666666666667" description = "Subtraction with repeating pattern" +expected = "0.66666666666666666666666667" [[subtraction_tests]] a = "1.000000000000000000" b = "0.500000000000000001" -expected = "0.499999999999999999" description = "Subtraction resulting in almost half" +expected = "0.499999999999999999" [[subtraction_tests]] a = "10.00000000000000000000000000" b = "9.99999999999999999999999999" -expected = "0.00000000000000000000000001" description = "Subtraction with many borrows" +expected = "1E-26" # === FINANCIAL SCENARIOS === [[subtraction_tests]] a = "10542.75" b = "3621.50" -expected = "6921.25" description = "Financial numbers (dollars and cents)" +expected = "6921.25" [[subtraction_tests]] a = "0.10" b = "0.01" -expected = "0.09" description = "Financial numbers (cents)" +expected = "0.09" [[subtraction_tests]] a = "100.00" b = "0.01" -expected = "99.99" description = "Financial subtraction with borrowing" +expected = "99.99" # === PRECISION BOUNDARY TESTS === [[subtraction_tests]] a = "1000000000000000000.0000000" b = "0.0000001" -expected = "999999999999999999.9999999" description = "Subtraction with rounding at precision boundary" +expected = "999999999999999999.9999999" [[subtraction_tests]] a = "3.3000000000000000000000000" b = "2.2000000000000000000000000" -expected = "1.1000000000000000000000000" description = "Subtraction with trailing zeros" +expected = "1.1000000000000000000000000" [[subtraction_tests]] a = "0.125" b = "0.0625" -expected = "0.0625" description = "Subtraction of binary-friendly values (1/8 - 1/16)" +expected = "0.0625" [[subtraction_tests]] a = "0.3" b = "0.2" -expected = "0.1" description = "Simple tenths subtraction" +expected = "0.1" # === ADDITIONAL EDGE CASES === [[subtraction_tests]] a = "0.000000000000000000000000010" b = "0.000000000000000000000000001" -expected = "0.000000000000000000000000009" description = "Subtraction near zero with precision limit" +expected = "9E-27" [[subtraction_tests]] a = "0.0" b = "0.0" -expected = "0.0" description = "Zero minus zero with decimal point" +expected = "0.0" [[subtraction_tests]] a = "0.142857142857142857142857" b = "0.076923076923076923076923" -expected = "0.065934065934065934065934" description = "Subtraction of recurring decimals (1/7 - 1/13)" +expected = "0.065934065934065934065934" [[subtraction_tests]] a = "0" b = "-0" -expected = "0" description = "Zero minus negative zero" +expected = "0" [[subtraction_tests]] a = "3E6" b = "2000000" -expected = "1000000" description = "Subtraction with E notation" +expected = "1000000" [[subtraction_tests]] a = "1.79769313486231570E+308" b = "10" -expected = "179769313486231569999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990" description = "Subtraction near max double precision" +expected = "1.79769313486231569999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999990E+308" [[subtraction_tests]] a = "9.9999999999999999999999" b = "9.9999999999999999999999" -expected = "0.0000000000000000000000" description = "Exact cancellation of large numbers" +expected = "0E-22" [[subtraction_tests]] a = "1111111110111111111.111111110111111110" b = "987654321098765432.123456789098765432" -expected = "123456789012345678.987654321012345678" description = "Complex subtraction with different digit patterns" +expected = "123456789012345678.987654321012345678" # === SPECIFIC APPLICATION DOMAINS === [[subtraction_tests]] a = "37.7749" b = "37.7748" -expected = "0.0001" description = "GPS coordinates (latitude difference)" +expected = "0.0001" [[subtraction_tests]] a = "98.6" b = "37.0" -expected = "61.6" description = "Temperature conversion (F - C)" +expected = "61.6" [[subtraction_tests]] a = "1000.50" b = "243.22" -expected = "757.28" description = "Bank balance calculation" +expected = "757.28" [[subtraction_tests]] a = "987654321987654321.987654321" b = "0.000000000000000000000000001" -expected = "987654321987654321.987654320999999999999999999" description = "Subtraction with extreme scale difference" +expected = "987654321987654321.987654320999999999999999999" [[subtraction_tests]] a = "0.0440" b = "0.0015" -expected = "0.0425" description = "Interest rate calculation" +expected = "0.0425" # ===----------------------------------------------------------------------=== # # Test cases for BigDecimal multiplication @@ -639,288 +639,288 @@ description = "Interest rate calculation" [[multiplication_tests]] a = "2" b = "3" -expected = "6" description = "Simple integer multiplication" +expected = "6" [[multiplication_tests]] a = "1.5" b = "2" -expected = "3.0" description = "Simple decimal by integer" +expected = "3.0" [[multiplication_tests]] a = "0.5" b = "0.5" -expected = "0.25" description = "Decimal by decimal multiplication" +expected = "0.25" [[multiplication_tests]] a = "0" b = "123.456" -expected = "0.000" description = "Multiplication by zero" +expected = "0.000" [[multiplication_tests]] a = "1" b = "123.456" -expected = "123.456" description = "Multiplication by one" +expected = "123.456" [[multiplication_tests]] a = "-1" b = "123.456" -expected = "-123.456" description = "Multiplication by negative one" +expected = "-123.456" # === DIFFERENT SCALE TESTS === [[multiplication_tests]] a = "1.23" b = "4.56" -expected = "5.6088" description = "Multiplication with scales addition" +expected = "5.6088" [[multiplication_tests]] a = "1.2345" b = "6.789" -expected = "8.3810205" description = "Multiplication with different scales" +expected = "8.3810205" [[multiplication_tests]] a = "1.23456789" b = "9.87654321" -expected = "12.1932631112635269" description = "Multiplication with high precision" +expected = "12.1932631112635269" [[multiplication_tests]] a = "9.999" b = "9.999" -expected = "99.980001" description = "Multiplication near power of 10" +expected = "99.980001" [[multiplication_tests]] a = "0.1" b = "0.1" -expected = "0.01" description = "Multiplication of tenths" +expected = "0.01" # === SIGN COMBINATION TESTS === [[multiplication_tests]] a = "-2" b = "-3" -expected = "6" description = "Negative times negative" +expected = "6" [[multiplication_tests]] a = "-3.14" b = "2" -expected = "-6.28" description = "Negative times positive" +expected = "-6.28" [[multiplication_tests]] a = "10" b = "-0.5" -expected = "-5.0" description = "Positive times negative" +expected = "-5.0" [[multiplication_tests]] a = "-5.75" b = "-10.25" -expected = "58.9375" description = "Negative times negative decimal" +expected = "58.9375" [[multiplication_tests]] a = "0" b = "-123.456" -expected = "-0.000" description = "Zero times negative" +expected = "-0.000" # === LARGE NUMBER TESTS === [[multiplication_tests]] a = "9999999999" b = "9999999999" -expected = "99999999980000000001" description = "Large integer multiplication" +expected = "99999999980000000001" [[multiplication_tests]] a = "-9999999999" b = "9999999999" -expected = "-99999999980000000001" description = "Large integer with negative" +expected = "-99999999980000000001" [[multiplication_tests]] a = "12345678901234567890" b = "0.00000000001" -expected = "123456789.01234567890" description = "Large integer times small decimal" +expected = "123456789.01234567890" [[multiplication_tests]] a = "0.0000000001" b = "0.0000000001" -expected = "0.00000000000000000001" description = "Small decimal multiplication" +expected = "1E-20" # === SCIENTIFIC NOTATION TESTS === [[multiplication_tests]] a = "1.23e5" b = "4.56e2" -expected = "5.6088E+7" description = "Multiplication with scientific notation" +expected = "5.6088E+7" [[multiplication_tests]] a = "1.23e-5" b = "4.56e-2" -expected = "0.00000056088" description = "Multiplication with negative exponents" +expected = "5.6088E-7" [[multiplication_tests]] a = "1.23e5" b = "4.56e-2" -expected = "5608.8" description = "Multiplication with mixed exponents" +expected = "5608.8" # === SPECIAL CASES === [[multiplication_tests]] a = "3.14159265358979323846" b = "2.71828182845904523536" -expected = "8.5397342226735670654554622909226073039456" description = "Multiplication of mathematical constants (PI * E)" +expected = "8.5397342226735670654554622909226073039456" [[multiplication_tests]] a = "0.33333333333333333333333333" b = "3" -expected = "0.99999999999999999999999999" description = "Multiplication resulting in almost one" +expected = "0.99999999999999999999999999" [[multiplication_tests]] a = "0.5" b = "2" -expected = "1.0" description = "Multiplication resulting in exact integer" +expected = "1.0" [[multiplication_tests]] a = "0.1" b = "10" -expected = "1.0" description = "Decimal shifted by multiplication" +expected = "1.0" # === FINANCIAL SCENARIOS === [[multiplication_tests]] a = "10.99" b = "3" -expected = "32.97" description = "Financial multiplication (price * quantity)" +expected = "32.97" [[multiplication_tests]] a = "100" b = "0.075" -expected = "7.500" description = "Financial multiplication (principal * interest)" +expected = "7.500" [[multiplication_tests]] a = "9.99" b = "1.08" -expected = "10.7892" description = "Financial multiplication (price * tax)" +expected = "10.7892" # === PRECISION BOUNDARY TESTS === [[multiplication_tests]] a = "9.9999999999999999999999999" b = "9.9999999999999999999999999" -expected = "99.99999999999999999999999800000000000000000000000001" description = "Multiplication at precision boundary" +expected = "99.99999999999999999999999800000000000000000000000001" [[multiplication_tests]] a = "1.0000000000000000000000001" b = "1.0000000000000000000000001" -expected = "1.00000000000000000000000020000000000000000000000001" description = "Multiplication slightly above one" +expected = "1.00000000000000000000000020000000000000000000000001" [[multiplication_tests]] a = "0.125" b = "8" -expected = "1.000" description = "Binary-friendly multiplication (1/8 * 8)" +expected = "1.000" # === ADDITIONAL EDGE CASES === [[multiplication_tests]] a = "0.000000000000000000000000001" b = "1000000000000000000000000000" -expected = "1.000000000000000000000000000" description = "Multiplication of very small and very large" +expected = "1.000000000000000000000000000" [[multiplication_tests]] a = "0.9" b = "0.9" -expected = "0.81" description = "Multiplication less than one" +expected = "0.81" [[multiplication_tests]] a = "1.11111111111111111111111111" b = "9" -expected = "9.99999999999999999999999999" description = "Multiplication of repeating decimal" +expected = "9.99999999999999999999999999" [[multiplication_tests]] a = "2.5" b = "0.4" -expected = "1.00" description = "Multiplication resulting in exact one" +expected = "1.00" [[multiplication_tests]] a = "0.000000000000000000000000009" b = "0.000000000000000000000000009" -expected = "0.000000000000000000000000000000000000000000000000000081" description = "Multiplication of very small numbers" +expected = "8.1E-53" # === APPLICATION SCENARIOS === [[multiplication_tests]] a = "299792458" b = "0.000000001" -expected = "0.299792458" description = "Physical unit conversion (m/s to km/μs)" +expected = "0.299792458" [[multiplication_tests]] a = "6.022e23" b = "0.001" -expected = "6.022e20" description = "Scientific calculation (Avogadro's number * milli-mole)" +expected = "6.022E+20" [[multiplication_tests]] a = "29.92" b = "33.8639" -expected = "1013.207888" description = "Weather calculation (inches of mercury to hPa)" +expected = "1013.207888" [[multiplication_tests]] a = "42.195" b = "0.621371" -expected = "26.218749345" description = "Distance conversion (km to miles)" +expected = "26.218749345" [[multiplication_tests]] a = "180" b = "0.017453292519943295" -expected = "3.141592653589793100" description = "Angle conversion (degrees to radians)" +expected = "3.141592653589793100" # === ROUNDING AND PRECISION TESTS === [[multiplication_tests]] a = "3.333333333333333333333333333" b = "3" -expected = "9.999999999999999999999999999" description = "Multiplication preserving precision" +expected = "9.999999999999999999999999999" [[multiplication_tests]] a = "1.000000000000000000000000001" b = "0.999999999999999999999999999" -expected = "0.999999999999999999999999999999999999999999999999999999" description = "Multiplication with potential precision loss" +expected = "0.999999999999999999999999999999999999999999999999999999" [[multiplication_tests]] a = "3.1415926535897932384626433832795" b = "1.0" -expected = "3.14159265358979323846264338327950" description = "Multiplication preserving significant digits up to precision" +expected = "3.14159265358979323846264338327950" # ===----------------------------------------------------------------------=== # # Test cases for BigDecimal division @@ -929,322 +929,322 @@ description = "Multiplication preserving significant digits up to precision" [[division_tests]] a = "10" b = "2" -expected = "5" description = "Simple integer division" +expected = "5" [[division_tests]] a = "10" b = "4" -expected = "2.5" description = "Integer division resulting in decimal" +expected = "2.5" [[division_tests]] a = "1" b = "3" -expected = "0.3333333333333333333333333333" description = "Division resulting in repeating decimal" +expected = "0.3333333333333333333333333333" [[division_tests]] a = "10.5" b = "2.5" -expected = "4.2" description = "Decimal division resulting in exact decimal" +expected = "4.2" [[division_tests]] a = "0" b = "5" -expected = "0" description = "Zero divided by something" +expected = "0" # === DIVISION WITH DIFFERENT SCALES === [[division_tests]] a = "1.23456789" b = "0.001" -expected = "1234.56789" description = "Division by small decimal (scale increase)" +expected = "1234.56789" [[division_tests]] a = "0.001" b = "100" -expected = "0.00001" description = "Small number divided by large (scale increase)" +expected = "0.00001" [[division_tests]] a = "1.234" b = "10" -expected = "0.1234" description = "Division resulting in scale increase" +expected = "0.1234" [[division_tests]] a = "5.75" b = "0.1" -expected = "57.5" description = "Division by 0.1 (scale shift)" +expected = "57.5" [[division_tests]] a = "5.75" b = "0.01" -expected = "575" description = "Division by 0.01 (scale shift)" +expected = "575" # === SIGN COMBINATION TESTS === [[division_tests]] a = "-10" b = "2" -expected = "-5" description = "Negative divided by positive" +expected = "-5" [[division_tests]] a = "10" b = "-2" -expected = "-5" description = "Positive divided by negative" +expected = "-5" [[division_tests]] a = "-10" b = "-2" -expected = "5" description = "Negative divided by negative" +expected = "5" [[division_tests]] a = "-0" b = "5" -expected = "-0" description = "Negative zero divided by positive" +expected = "-0" [[division_tests]] a = "0" b = "-5" -expected = "-0" description = "Zero divided by negative" +expected = "-0" # === ROUNDING TESTS === [[division_tests]] a = "1" b = "7" -expected = "0.1428571428571428571428571429" description = "Division with repeating decimal (1/7)" +expected = "0.1428571428571428571428571429" [[division_tests]] a = "2" b = "3" -expected = "0.6666666666666666666666666667" description = "Division with repeating decimal (2/3)" +expected = "0.6666666666666666666666666667" [[division_tests]] a = "10" b = "6" -expected = "1.666666666666666666666666667" description = "Division with repeating decimal (10/6)" +expected = "1.666666666666666666666666667" [[division_tests]] a = "1" b = "9" -expected = "0.1111111111111111111111111111" description = "Division with repeating digit (1/9)" +expected = "0.1111111111111111111111111111" [[division_tests]] a = "100" b = "3" -expected = "33.33333333333333333333333333" description = "Large repeating division" +expected = "33.33333333333333333333333333" # === LARGE AND SMALL NUMBER TESTS === [[division_tests]] a = "9999999999999999999999999999" b = "3" -expected = "3333333333333333333333333333" description = "Large number simple division" +expected = "3333333333333333333333333333" [[division_tests]] a = "1" b = "9999999999999999999999999999" -expected = "0.0000000000000000000000000001000000000000000000000000000" description = "One divided by large number" +expected = "1.000000000000000000000000000E-28" [[division_tests]] a = "0.0000000000000000000000000001" b = "0.0000000000000000000000000003" -expected = "0.3333333333333333333333333333" description = "Small number division" +expected = "0.3333333333333333333333333333" [[division_tests]] a = "1000000000000000000000000000000" b = "0.0000000000000000000000000001" -expected = "1.000000000000000000000000000E+58" description = "Large divided by small" +expected = "1.000000000000000000000000000E+58" [[division_tests]] a = "0.0000000000000000000000000001" b = "1000000000000000000000000000000" -expected = "0.0000000000000000000000000000000000000000000000000000000001" description = "Small divided by large" +expected = "1E-58" # === SCIENTIFIC NOTATION TESTS === [[division_tests]] a = "1.23e5" b = "4.56e2" -expected = "269.7368421052631578947368421" description = "Division with scientific notation" +expected = "269.7368421052631578947368421" [[division_tests]] a = "1.23e-5" b = "4.56e-2" -expected = "0.0002697368421052631578947368421" description = "Division with negative exponents" +expected = "0.0002697368421052631578947368421" [[division_tests]] a = "1.23e5" b = "4.56e-2" -expected = "2697368.421052631578947368421" description = "Division with mixed exponents" +expected = "2697368.421052631578947368421" # === SPECIAL CASES === [[division_tests]] a = "3.14159265358979323846" b = "2.71828182845904523536" -expected = "1.155727349790921717909242961" description = "Division of mathematical constants (PI / E)" +expected = "1.155727349790921717909242961" [[division_tests]] a = "1" b = "1" -expected = "1" description = "Division by one" +expected = "1" [[division_tests]] a = "0.33333333333333333333333333" b = "3" -expected = "0.11111111111111111111111111" description = "Repeating decimal divided by integer" +expected = "0.11111111111111111111111111" [[division_tests]] a = "5" b = "10" -expected = "0.5" description = "Division resulting in exact fraction" +expected = "0.5" # === DECIMAL PLACE SHIFTS === [[division_tests]] a = "123.456789" b = "10" -expected = "12.3456789" description = "Division by 10 (decimal shift left)" +expected = "12.3456789" [[division_tests]] a = "123.456789" b = "100" -expected = "1.23456789" description = "Division by 100 (decimal shift left)" +expected = "1.23456789" [[division_tests]] a = "123.456789" b = "1000" -expected = "0.123456789" description = "Division by 1000 (decimal shift left)" +expected = "0.123456789" [[division_tests]] a = "123.456789" b = "0.1" -expected = "1234.56789" description = "Division by 0.1 (decimal shift right)" +expected = "1234.56789" [[division_tests]] a = "123.456789" b = "0.01" -expected = "12345.6789" description = "Division by 0.01 (decimal shift right)" +expected = "12345.6789" # === PRECISION BOUNDARY TESTS === [[division_tests]] a = "1" b = "3" -expected = "0.3333333333333333333333333333" description = "Division at precision boundary (1/3)" +expected = "0.3333333333333333333333333333" [[division_tests]] a = "2" b = "3" -expected = "0.6666666666666666666666666667" description = "Division at precision boundary (2/3)" +expected = "0.6666666666666666666666666667" [[division_tests]] a = "9.9999999999999999999999999" b = "9.9999999999999999999999999" -expected = "1" description = "Division of equal values at precision limit" +expected = "1" [[division_tests]] a = "0.0000000000000000000000001" b = "0.0000000000000000000000001" -expected = "1" description = "Division of equal small values" +expected = "1" # === FINANCIAL SCENARIOS === [[division_tests]] a = "100.00" b = "4" -expected = "25.00" description = "Financial division (dollars)" +expected = "25.00" [[division_tests]] a = "100.00" b = "3" -expected = "33.33333333333333333333333333" description = "Financial division with repeating result" +expected = "33.33333333333333333333333333" [[division_tests]] a = "156.48" b = "12" -expected = "13.04" description = "Financial calculation (price per item)" +expected = "13.04" # === APPLICATION SCENARIOS === [[division_tests]] a = "360" b = "12" -expected = "30" description = "Circle division (degrees in a circle / months)" +expected = "30" [[division_tests]] a = "1000" b = "3" -expected = "333.3333333333333333333333333" description = "Division for equal distribution" +expected = "333.3333333333333333333333333" [[division_tests]] a = "2.54" b = "0.01" -expected = "254" description = "Unit conversion (cm to m)" +expected = "254" [[division_tests]] a = "1234.56" b = "51.44" -expected = "24" description = "Division resulting in exact integer" +expected = "24" # === EDGE CASES === [[division_tests]] a = "0.0000000000000000000000000009" b = "0.0000000000000000000000000003" -expected = "3" description = "Division of very small numbers" +expected = "3" [[division_tests]] a = "1" b = "0.000000000000000000000000001" -expected = "1E+27" description = "One divided by very small number" +expected = "1E+27" [[division_tests]] a = "9999999999999999999999999999.9999999999999999999999999999" b = "9999999999999999999999999999.9999999999999999999999999999" -expected = "1" description = "Division of very large equal numbers" +expected = "1" [[division_tests]] a = "0" b = "1" -expected = "0" description = "Division of zero" +expected = "0" diff --git a/tests/bigdecimal/test_data/bigdecimal_compare.toml b/tests/bigdecimal/test_data/bigdecimal_compare.toml index 252a612..5e0c85b 100644 --- a/tests/bigdecimal/test_data/bigdecimal_compare.toml +++ b/tests/bigdecimal/test_data/bigdecimal_compare.toml @@ -3,677 +3,677 @@ [[compare_absolute_tests]] a = "10" b = "5" -expected = "1" description = "Simple case: a > b" +expected = "1" [[compare_absolute_tests]] a = "5" b = "10" -expected = "-1" description = "Simple case: a < b" +expected = "-1" [[compare_absolute_tests]] a = "5" b = "5" -expected = "0" description = "Simple case: a == b" +expected = "0" [[compare_absolute_tests]] a = "-10" b = "5" -expected = "1" description = "Negative a, positive b, |a| > |b|" +expected = "1" [[compare_absolute_tests]] a = "10" b = "-5" -expected = "1" description = "Positive a, negative b, |a| > |b|" +expected = "1" [[compare_absolute_tests]] a = "-5" b = "10" -expected = "-1" description = "Negative a, positive b, |a| < |b|" +expected = "-1" [[compare_absolute_tests]] a = "5" b = "-10" -expected = "-1" description = "Positive a, negative b, |a| < |b|" +expected = "-1" [[compare_absolute_tests]] a = "-10" b = "-5" -expected = "1" description = "Negative a, negative b, |a| > |b|" +expected = "1" [[compare_absolute_tests]] a = "-5" b = "-10" -expected = "-1" description = "Negative a, negative b, |a| < |b|" +expected = "-1" [[compare_absolute_tests]] a = "-5" b = "5" -expected = "0" description = "Negative a, positive b, |a| == |b|" +expected = "0" [[compare_absolute_tests]] a = "5" b = "-5" -expected = "0" description = "Positive a, negative b, |a| == |b|" +expected = "0" [[compare_absolute_tests]] a = "-0" b = "0" -expected = "0" description = "Negative zero vs positive zero" +expected = "0" [[compare_absolute_tests]] a = "0" b = "-0" -expected = "0" description = "Positive zero vs negative zero" +expected = "0" [[compare_absolute_tests]] a = "12345678901234567890" b = "1234567890123456789" -expected = "1" description = "Large numbers: a > b" +expected = "1" [[compare_absolute_tests]] a = "1234567890123456789" b = "12345678901234567890" -expected = "-1" description = "Large numbers: a < b" +expected = "-1" [[compare_absolute_tests]] a = "99999999999999999999" b = "99999999999999999999" -expected = "0" description = "Large numbers: a == b" +expected = "0" [[compare_absolute_tests]] a = "0.000000001" b = "0.0000000001" -expected = "1" description = "Small decimals: a > b" +expected = "1" [[compare_absolute_tests]] a = "0.0000000001" b = "0.000000001" -expected = "-1" description = "Small decimals: a < b" +expected = "-1" [[compare_absolute_tests]] a = "0.000000001" b = "0.000000001" -expected = "0" description = "Small decimals: a == b" +expected = "0" [[compare_absolute_tests]] a = "1.23456789" b = "1.23456788" -expected = "1" description = "Close decimals: a > b" +expected = "1" [[compare_absolute_tests]] a = "1.23456788" b = "1.23456789" -expected = "-1" description = "Close decimals: a < b" +expected = "-1" [[compare_absolute_tests]] a = "1.23456789" b = "1.23456789" -expected = "0" description = "Close decimals: a == b" +expected = "0" [[compare_absolute_tests]] a = "1.23e5" b = "4.56e4" -expected = "1" description = "Scientific notation: a > b" +expected = "1" [[compare_absolute_tests]] a = "1.23e-5" b = "4.56e-2" -expected = "-1" description = "Scientific notation: a < b" +expected = "-1" [[compare_absolute_tests]] a = "1.23e5" b = "1.23e5" -expected = "0" description = "Scientific notation: a == b" +expected = "0" [[compare_absolute_tests]] a = "3.14159265358979323846" b = "2.71828182845904523536" -expected = "1" description = "Math constants: PI > E" +expected = "1" [[compare_absolute_tests]] a = "1.61803398874989484820" b = "1.41421356237309504880" -expected = "1" description = "Math constants: PHI > sqrt(2)" +expected = "1" [[compare_absolute_tests]] a = "0.66666666666666666666" b = "0.33333333333333333333" -expected = "1" description = "Repeating decimals: 2/3 > 1/3" +expected = "1" [[compare_absolute_tests]] a = "10000000000000000000000000000" b = "1" -expected = "1" description = "Large vs small: a > b" +expected = "1" [[compare_absolute_tests]] a = "0.000000000000000000000000001" b = "1" -expected = "-1" description = "Small vs large: a < b" +expected = "-1" [[compare_absolute_tests]] a = "1000.00" b = "999.99" -expected = "1" description = "Financial numbers: a > b" +expected = "1" [[compare_absolute_tests]] a = "999.99" b = "1000.00" -expected = "-1" description = "Financial numbers: a < b" +expected = "-1" [[compare_absolute_tests]] a = "1000.00" b = "1000.00" -expected = "0" description = "Financial numbers: a == b" +expected = "0" [[compare_absolute_tests]] a = "1.79769313486231570E+308" b = "10" -expected = "1" description = "Near max double precision: a > b" +expected = "1" [[compare_absolute_tests]] a = "9.9999999999999999999999" b = "9.9999999999999999999998" -expected = "1" description = "Near equal large numbers: a > b" +expected = "1" [[compare_absolute_tests]] a = "9.9999999999999999999998" b = "9.9999999999999999999999" -expected = "-1" description = "Near equal large numbers: a < b" +expected = "-1" [[compare_absolute_tests]] a = "1111111110111111111.111111110111111110" b = "987654321098765432.123456789098765432" -expected = "1" description = "Complex numbers: a > b" +expected = "1" [[compare_absolute_tests]] a = "37.7749" b = "37.7748" -expected = "1" description = "GPS coordinates: a > b" +expected = "1" [[compare_absolute_tests]] a = "98.6" b = "37.0" -expected = "1" description = "Temperature conversion: a > b" +expected = "1" [[compare_absolute_tests]] a = "1000.50" b = "243.22" -expected = "1" description = "Bank balance: a > b" +expected = "1" [[compare_absolute_tests]] a = "987654321987654321.987654321" b = "0.000000000000000000000000001" -expected = "1" description = "Extreme scale difference: a > b" +expected = "1" [[compare_absolute_tests]] a = "0.0440" b = "0.0015" -expected = "1" description = "Interest rate: a > b" +expected = "1" [[compare_absolute_tests]] a = "1.23456789012345678901234567" b = "1.23456789012345678901234566" -expected = "1" description = "Very close numbers: a > b" +expected = "1" [[compare_absolute_tests]] a = "1.23456789012345678901234566" b = "1.23456789012345678901234567" -expected = "-1" description = "Very close numbers: a < b" +expected = "-1" [[compare_absolute_tests]] a = "1.23456789012345678901234567" b = "1.23456789012345678901234567" -expected = "0" description = "Very close numbers: a == b" +expected = "0" [[compare_absolute_tests]] a = "1.000000000000000000000000000" b = "0.999999999999999999999999999" -expected = "1" description = "Near one: a > b" +expected = "1" [[compare_absolute_tests]] a = "0.999999999999999999999999999" b = "1.000000000000000000000000000" -expected = "-1" description = "Near one: a < b" +expected = "-1" [[compare_absolute_tests]] a = "1.000000000000000000000000000" b = "1.000000000000000000000000000" -expected = "0" description = "Near one: a == b" +expected = "0" # Test cases for BigDecimal comparison (>) [[greater_than_tests]] a = "10" b = "5" -expected = "1" description = "Simple case: a > b" +expected = "1" [[greater_than_tests]] a = "5" b = "10" -expected = "0" description = "Simple case: a < b" +expected = "0" [[greater_than_tests]] a = "5" b = "5" -expected = "0" description = "Simple case: a == b" +expected = "0" [[greater_than_tests]] a = "-10" b = "5" -expected = "0" description = "Negative a, positive b, |a| > |b|" +expected = "0" [[greater_than_tests]] a = "10" b = "-5" -expected = "1" description = "Positive a, negative b, |a| > |b|" +expected = "1" [[greater_than_tests]] a = "12345678901234567890" b = "1234567890123456789" -expected = "1" description = "Large numbers: a > b" +expected = "1" [[greater_than_tests]] a = "0.000000001" b = "0.0000000001" -expected = "1" description = "Small decimals: a > b" +expected = "1" [[greater_than_tests]] a = "1.23456789" b = "1.23456788" -expected = "1" description = "Close decimals: a > b" +expected = "1" [[greater_than_tests]] a = "1.23e5" b = "4.56e4" -expected = "1" description = "Scientific notation: a > b" +expected = "1" [[greater_than_tests]] a = "3.14159265358979323846" b = "2.71828182845904523536" -expected = "1" description = "Math constants: PI > E" +expected = "1" [[greater_than_tests]] a = "1.61803398874989484820" b = "1.41421356237309504880" -expected = "1" description = "Math constants: PHI > sqrt(2)" +expected = "1" [[greater_than_tests]] a = "0.66666666666666666666" b = "0.33333333333333333333" -expected = "1" description = "Repeating decimals: 2/3 > 1/3" +expected = "1" [[greater_than_tests]] a = "10000000000000000000000000000" b = "1" -expected = "1" description = "Large vs small: a > b" +expected = "1" [[greater_than_tests]] a = "1000.00" b = "999.99" -expected = "1" description = "Financial numbers: a > b" +expected = "1" [[greater_than_tests]] a = "1.79769313486231570E+308" b = "10" -expected = "1" description = "Near max double precision: a > b" +expected = "1" [[greater_than_tests]] a = "9.9999999999999999999999" b = "9.9999999999999999999998" -expected = "1" description = "Near equal large numbers: a > b" +expected = "1" [[greater_than_tests]] a = "1111111110111111111.111111110111111110" b = "987654321098765432.123456789098765432" -expected = "1" description = "Complex numbers: a > b" +expected = "1" [[greater_than_tests]] a = "37.7749" b = "37.7748" -expected = "1" description = "GPS coordinates: a > b" +expected = "1" [[greater_than_tests]] a = "98.6" b = "37.0" -expected = "1" description = "Temperature conversion: a > b" +expected = "1" [[greater_than_tests]] a = "1000.50" b = "243.22" -expected = "1" description = "Bank balance: a > b" +expected = "1" [[greater_than_tests]] a = "987654321987654321.987654321" b = "0.000000000000000000000000001" -expected = "1" description = "Extreme scale difference: a > b" +expected = "1" [[greater_than_tests]] a = "0.0440" b = "0.0015" -expected = "1" description = "Interest rate: a > b" +expected = "1" [[greater_than_tests]] a = "1.23456789012345678901234567" b = "1.23456789012345678901234566" -expected = "1" description = "Very close numbers: a > b" +expected = "1" [[greater_than_tests]] a = "1.000000000000000000000000000" b = "0.999999999999999999999999999" -expected = "1" description = "Near one: a > b" +expected = "1" # Test cases for BigDecimal comparison (<) [[less_than_tests]] a = "10" b = "5" -expected = "0" description = "Simple case: a > b" +expected = "0" [[less_than_tests]] a = "5" b = "10" -expected = "1" description = "Simple case: a < b" +expected = "1" [[less_than_tests]] a = "5" b = "5" -expected = "0" description = "Simple case: a == b" +expected = "0" [[less_than_tests]] a = "-5" b = "10" -expected = "1" description = "Negative a, positive b, |a| < |b|" +expected = "1" [[less_than_tests]] a = "5" b = "-10" -expected = "0" description = "Positive a, negative b, |a| < |b|" +expected = "0" [[less_than_tests]] a = "-10" b = "-5" -expected = "1" description = "Negative a, negative b, |a| > |b|" +expected = "1" [[less_than_tests]] a = "-5" b = "-10" -expected = "0" description = "Negative a, negative b, |a| < |b|" +expected = "0" [[less_than_tests]] a = "1234567890123456789" b = "12345678901234567890" -expected = "1" description = "Large numbers: a < b" +expected = "1" [[less_than_tests]] a = "0.0000000001" b = "0.000000001" -expected = "1" description = "Small decimals: a < b" +expected = "1" [[less_than_tests]] a = "1.23456788" b = "1.23456789" -expected = "1" description = "Close decimals: a < b" +expected = "1" [[less_than_tests]] a = "1.23e-5" b = "4.56e-2" -expected = "1" description = "Scientific notation: a < b" +expected = "1" [[less_than_tests]] a = "0.000000000000000000000000001" b = "1" -expected = "1" description = "Small vs large: a < b" +expected = "1" [[less_than_tests]] a = "999.99" b = "1000.00" -expected = "1" description = "Financial numbers: a < b" +expected = "1" [[less_than_tests]] a = "9.9999999999999999999998" b = "9.9999999999999999999999" -expected = "1" description = "Near equal large numbers: a < b" +expected = "1" [[less_than_tests]] a = "1.23456789012345678901234566" b = "1.23456789012345678901234567" -expected = "1" description = "Very close numbers: a < b" +expected = "1" [[less_than_tests]] a = "0.999999999999999999999999999" b = "1.000000000000000000000000000" -expected = "1" description = "Near one: a < b" +expected = "1" # Test cases for BigDecimal comparison (>=) [[greater_than_or_equal_tests]] a = "10" b = "5" -expected = "1" description = "Simple case: a > b" +expected = "1" [[greater_than_or_equal_tests]] a = "5" b = "10" -expected = "0" description = "Simple case: a < b" +expected = "0" [[greater_than_or_equal_tests]] a = "5" b = "5" -expected = "1" description = "Simple case: a == b" +expected = "1" # Test cases for BigDecimal comparison (<=) [[less_than_or_equal_tests]] a = "10" b = "5" -expected = "0" description = "Simple case: a > b" +expected = "0" [[less_than_or_equal_tests]] a = "5" b = "10" -expected = "1" description = "Simple case: a < b" +expected = "1" [[less_than_or_equal_tests]] a = "5" b = "5" -expected = "1" description = "Simple case: a == b" +expected = "1" # Test cases for BigDecimal comparison (==) [[equal_tests]] a = "10" b = "5" -expected = "0" description = "Simple case: a > b" +expected = "0" [[equal_tests]] a = "5" b = "10" -expected = "0" description = "Simple case: a < b" +expected = "0" [[equal_tests]] a = "5" b = "5" -expected = "1" description = "Simple case: a == b" +expected = "1" [[equal_tests]] a = "-5" b = "5" -expected = "0" description = "Negative a, positive b, |a| == |b|" +expected = "0" [[equal_tests]] a = "5" b = "-5" -expected = "0" description = "Positive a, negative b, |a| == |b|" +expected = "0" [[equal_tests]] a = "-0" b = "0" -expected = "1" description = "Negative zero vs positive zero" +expected = "1" [[equal_tests]] a = "0" b = "-0" -expected = "1" description = "Positive zero vs negative zero" +expected = "1" [[equal_tests]] a = "99999999999999999999" b = "99999999999999999999" -expected = "1" description = "Large numbers: a == b" +expected = "1" [[equal_tests]] a = "0.000000001" b = "0.000000001" -expected = "1" description = "Small decimals: a == b" +expected = "1" [[equal_tests]] a = "1.23456789" b = "1.23456789" -expected = "1" description = "Close decimals: a == b" +expected = "1" [[equal_tests]] a = "1.23e5" b = "1.23e5" -expected = "1" description = "Scientific notation: a == b" +expected = "1" [[equal_tests]] a = "1000.00" b = "1000.00" -expected = "1" description = "Financial numbers: a == b" +expected = "1" [[equal_tests]] a = "1.23456789012345678901234567" b = "1.23456789012345678901234567" -expected = "1" description = "Very close numbers: a == b" +expected = "1" [[equal_tests]] a = "1.000000000000000000000000000" b = "1.000000000000000000000000000" -expected = "1" description = "Near one: a == b" +expected = "1" # Test cases for BigDecimal comparison (!=) [[not_equal_tests]] a = "10" b = "5" -expected = "1" description = "Simple case: a > b" +expected = "1" [[not_equal_tests]] a = "5" b = "10" -expected = "1" description = "Simple case: a < b" +expected = "1" [[not_equal_tests]] a = "5" b = "5" +description = "Simple case: a == b" expected = "0" -description = "Simple case: a == b" \ No newline at end of file diff --git a/tests/bigdecimal/test_data/bigdecimal_exponential.toml b/tests/bigdecimal/test_data/bigdecimal_exponential.toml index 80a8ae6..f2b31dd 100644 --- a/tests/bigdecimal/test_data/bigdecimal_exponential.toml +++ b/tests/bigdecimal/test_data/bigdecimal_exponential.toml @@ -2,346 +2,346 @@ [[sqrt_tests]] a = "0" b = "" -expected = "0" description = "Square root of zero" +expected = "0" [[sqrt_tests]] a = "1" b = "" -expected = "1" description = "Square root of one" +expected = "1" [[sqrt_tests]] a = "4" b = "" -expected = "2" description = "Square root of perfect square (small)" +expected = "2" [[sqrt_tests]] a = "9" b = "" -expected = "3" description = "Square root of perfect square (single digit)" +expected = "3" [[sqrt_tests]] a = "16" b = "" -expected = "4" description = "Square root of perfect square (16)" +expected = "4" [[sqrt_tests]] a = "25" b = "" -expected = "5" description = "Square root of perfect square (25)" +expected = "5" [[sqrt_tests]] a = "100" b = "" -expected = "10" description = "Square root of perfect square (100)" +expected = "10" # === NON-PERFECT SQUARES === [[sqrt_tests]] a = "2" b = "" -expected = "1.414213562373095048801688724" description = "Square root of 2 (irrational)" +expected = "1.414213562373095048801688724" [[sqrt_tests]] a = "3" b = "" -expected = "1.732050807568877293527446342" description = "Square root of 3 (irrational)" +expected = "1.732050807568877293527446342" [[sqrt_tests]] a = "5" b = "" -expected = "2.236067977499789696409173669" description = "Square root of 5 (irrational)" +expected = "2.236067977499789696409173669" [[sqrt_tests]] a = "10" b = "" -expected = "3.162277660168379331998893544" description = "Square root of 10 (irrational)" +expected = "3.162277660168379331998893544" # === DECIMAL INPUTS === [[sqrt_tests]] a = "0.25" b = "" -expected = "0.5" description = "Square root of 0.25" +expected = "0.5" [[sqrt_tests]] a = "0.01" b = "" -expected = "0.1" description = "Square root of 0.01" +expected = "0.1" [[sqrt_tests]] a = "0.0625" b = "" -expected = "0.25" description = "Square root of 0.0625" +expected = "0.25" [[sqrt_tests]] a = "2.25" b = "" -expected = "1.5" description = "Square root of 2.25" +expected = "1.5" [[sqrt_tests]] a = "12.25" b = "" -expected = "3.5" description = "Square root of 12.25" +expected = "3.5" # === LARGE NUMBERS === [[sqrt_tests]] a = "1000000" b = "" -expected = "1000" description = "Square root of large perfect square" +expected = "1000" [[sqrt_tests]] a = "9999999999" b = "" -expected = "99999.99999499999999987500000" description = "Square root of large near-perfect square" +expected = "99999.99999499999999987500000" [[sqrt_tests]] a = "1000000000000000000000000000" b = "" -expected = "31622776601683.79331998893544" description = "Square root of very large imperfect square" +expected = "31622776601683.79331998893544" # === SMALL NUMBERS === [[sqrt_tests]] a = "0.0001" b = "" -expected = "0.01" description = "Square root of small number" +expected = "0.01" [[sqrt_tests]] a = "0.000000000001" b = "" -expected = "0.000001" description = "Square root of very small number" +expected = "1E-6" [[sqrt_tests]] a = "0.0000000000000000000000000001" b = "" -expected = "1E-14" description = "Square root of extremely small number" +expected = "1E-14" # === SCIENTIFIC NOTATION === [[sqrt_tests]] a = "1e10" b = "" -expected = "1E+5" description = "Square root with scientific notation (positive exponent)" +expected = "1E+5" [[sqrt_tests]] a = "1e-10" b = "" -expected = "0.00001" description = "Square root with scientific notation (negative exponent)" +expected = "0.00001" # === PRECISION TESTS === [[sqrt_tests]] a = "2" b = "" -expected = "1.414213562373095048801688724" description = "High precision square root of 2" +expected = "1.414213562373095048801688724" [[sqrt_tests]] a = "0.9999999999999999" b = "" -expected = "0.9999999999999999500000000000" description = "Square root slightly less than 1" +expected = "0.9999999999999999500000000000" [[sqrt_tests]] a = "1.0000000000000001" b = "" -expected = "1.000000000000000050000000000" description = "Square root slightly more than 1" +expected = "1.000000000000000050000000000" # === APPLICATION SCENARIOS === [[sqrt_tests]] a = "3.14159265358979323846" b = "" -expected = "1.772453850905516027297421799" description = "Square root of π" +expected = "1.772453850905516027297421799" [[sqrt_tests]] a = "2.71828182845904523536" b = "" -expected = "1.648721270700128146848563608" description = "Square root of e" +expected = "1.648721270700128146848563608" # === BASIC NATURAL LOGARITHM TESTS === [[ln_tests]] a = "1" b = "" -expected = "0" description = "Natural logarithm of 1 (exactly 0)" +expected = "0" [[ln_tests]] a = "2.718281828459045235360287471" b = "" -expected = "0.9999999999999999999999999999" description = "Natural logarithm of e (approximately 1)" +expected = "0.9999999999999999999999999999" [[ln_tests]] a = "10" b = "" -expected = "2.302585092994045684017991455" description = "Natural logarithm of 10" +expected = "2.302585092994045684017991455" [[ln_tests]] a = "2" b = "" -expected = "0.6931471805599453094172321215" description = "Natural logarithm of 2" +expected = "0.6931471805599453094172321215" [[ln_tests]] a = "0.5" b = "" -expected = "-0.6931471805599453094172321215" description = "Natural logarithm of 0.5 (negative result)" +expected = "-0.6931471805599453094172321215" # === POWERS OF e === [[ln_tests]] a = "7.389056098930650227230427461" b = "" -expected = "2.000000000000000000000000000" description = "Natural logarithm of e^2 (exactly 2)" +expected = "2.000000000000000000000000000" [[ln_tests]] a = "20.08553692318766774092852965" b = "" -expected = "3.000000000000000000000000000" description = "Natural logarithm of e^3 (exactly 3)" +expected = "3.000000000000000000000000000" [[ln_tests]] a = "0.3678794411714423215955237702" b = "" -expected = "-0.9999999999999999999999999999" description = "Natural logarithm of 1/e (exactly -1)" +expected = "-0.9999999999999999999999999999" [[ln_tests]] a = "0.1353352832366126918939994949" b = "" -expected = "-2.000000000000000000000000001" description = "Natural logarithm of 1/e^2 (exactly -2)" +expected = "-2.000000000000000000000000001" # === POWERS OF 10 === [[ln_tests]] a = "100" b = "" -expected = "4.605170185988091368035982909" description = "Natural logarithm of 10^2" +expected = "4.605170185988091368035982909" [[ln_tests]] a = "0.01" b = "" -expected = "-4.605170185988091368035982909" description = "Natural logarithm of 10^-2" +expected = "-4.605170185988091368035982909" [[ln_tests]] a = "1000" b = "" -expected = "6.907755278982137052053974364" description = "Natural logarithm of 10^3" +expected = "6.907755278982137052053974364" [[ln_tests]] a = "0.001" b = "" -expected = "-6.907755278982137052053974364" description = "Natural logarithm of 10^-3" +expected = "-6.907755278982137052053974364" # === SMALL NUMBERS === [[ln_tests]] a = "0.1" b = "" -expected = "-2.302585092994045684017991455" description = "Natural logarithm of 0.1" +expected = "-2.302585092994045684017991455" [[ln_tests]] a = "0.00001" b = "" -expected = "-11.51292546497022842008995727" description = "Natural logarithm of 1e-5" +expected = "-11.51292546497022842008995727" [[ln_tests]] a = "0.0000000001" b = "" -expected = "-23.02585092994045684017991455" description = "Natural logarithm of 1e-10" +expected = "-23.02585092994045684017991455" # === LARGE NUMBERS === [[ln_tests]] a = "1000000" b = "" -expected = "13.81551055796427410410794873" description = "Natural logarithm of 1e6" +expected = "13.81551055796427410410794873" [[ln_tests]] a = "1000000000000" b = "" -expected = "27.63102111592854820821589746" description = "Natural logarithm of 1e12" +expected = "27.63102111592854820821589746" [[ln_tests]] a = "1e50" b = "" -expected = "115.1292546497022842008995727" description = "Natural logarithm of 1e50" +expected = "115.1292546497022842008995727" # === VALUES NEAR 1 === [[ln_tests]] a = "0.9" b = "" -expected = "-0.1053605156578263012275009808" description = "Natural logarithm of 0.9 (near 1)" +expected = "-0.1053605156578263012275009808" [[ln_tests]] a = "1.1" b = "" -expected = "0.09531017980432486004395212328" description = "Natural logarithm of 1.1 (near 1)" +expected = "0.09531017980432486004395212328" [[ln_tests]] a = "0.999999" b = "" -expected = "-0.000001000000500000333333583333533" description = "Natural logarithm very close to 0 (0.999999)" +expected = "-1.000000500000333333583333533E-6" [[ln_tests]] a = "1.000001" b = "" -expected = "9.999995000003333330833335333E-7" description = "Natural logarithm very close to 0 (1.000001)" +expected = "9.999995000003333330833335333E-7" # === MATHEMATICAL CONSTANTS === [[ln_tests]] a = "3.141592653589793238462643383" b = "" -expected = "1.144729885849400174143427351" description = "Natural logarithm of π" +expected = "1.144729885849400174143427351" [[ln_tests]] a = "1.618033988749894848204586834" b = "" -expected = "0.4812118250596034474977589132" description = "Natural logarithm of φ (golden ratio)" +expected = "0.4812118250596034474977589132" [[ln_tests]] a = "1.414213562373095048801688724" b = "" -expected = "0.3465735902799726547086160606" description = "Natural logarithm of √2" +expected = "0.3465735902799726547086160606" # === ROOT TESTS === # Testing different roots (both integer and fractional) @@ -349,168 +349,168 @@ description = "Natural logarithm of √2" [[root_tests]] a = "64" b = "2" -expected = "8" description = "Square root of 64" +expected = "8" [[root_tests]] a = "27" b = "3" -expected = "3.000000000000000000000000000" description = "Cube root of 27" +expected = "3.000000000000000000000000000" [[root_tests]] a = "-27" b = "3" -expected = "-3.000000000000000000000000000" description = "Cube root of negative number" +expected = "-3.000000000000000000000000000" [[root_tests]] a = "16" b = "4" -expected = "2.000000000000000000000000000" description = "4th root of 16" +expected = "2.000000000000000000000000000" [[root_tests]] a = "32" b = "5" -expected = "2.000000000000000000000000000" description = "5th root of 32" +expected = "2.000000000000000000000000000" [[root_tests]] a = "64" b = "6" -expected = "2.000000000000000000000000000" description = "6th root of 64" +expected = "2.000000000000000000000000000" [[root_tests]] a = "128" b = "7" -expected = "2.000000000000000000000000000" description = "7th root of 128" +expected = "2.000000000000000000000000000" [[root_tests]] a = "256" b = "8" -expected = "2.000000000000000000000000000" description = "8th root of 256" +expected = "2.000000000000000000000000000" [[root_tests]] a = "1024" b = "10" -expected = "2.000000000000000000000000000" description = "10th root of 1024" +expected = "2.000000000000000000000000000" [[root_tests]] a = "1000000" b = "6" -expected = "10.00000000000000000000000000" description = "6th root of one million" +expected = "10.00000000000000000000000000" [[root_tests]] a = "0" b = "3" -expected = "0" description = "Root of zero" +expected = "0" [[root_tests]] a = "1" b = "99" -expected = "1" description = "Any root of 1" +expected = "1" # Fractional roots [[root_tests]] a = "16" b = "0.5" -expected = "256" description = "Fractional root (0.5 is power of 2)" +expected = "256" [[root_tests]] a = "27" b = "1.5" -expected = "9.000000000000000000000000000" description = "Fractional root (x^(3/2))" +expected = "9.000000000000000000000000000" [[root_tests]] a = "16" b = "2.5" -expected = "3.031433133020796164694519603" description = "Fractional root (nth root where n=2.5)" +expected = "3.031433133020796164694519603" [[root_tests]] a = "100" b = "2.5" -expected = "6.309573444801932494343601366" description = "Fractional root of perfect power" +expected = "6.309573444801932494343601366" # Negative roots (reciprocal of positive roots) [[root_tests]] a = "16" b = "-2" -expected = "0.25" description = "Negative root (reciprocal of square root)" +expected = "0.25" [[root_tests]] a = "27" b = "-3" -expected = "0.3333333333333333333333333333" description = "Negative root (reciprocal of cube root)" +expected = "0.3333333333333333333333333333" # Special cases and edge cases [[root_tests]] a = "0.25" b = "2" -expected = "0.5" description = "Root of number less than 1" +expected = "0.5" [[root_tests]] a = "0.0625" b = "4" -expected = "0.5000000000000000000000000000" description = "Higher root of number less than 1" +expected = "0.5000000000000000000000000000" [[root_tests]] a = "0.000001" b = "3" -expected = "0.01000000000000000000000000000" description = "Root of very small number" +expected = "0.01000000000000000000000000000" [[root_tests]] a = "1000000000000000000000000" b = "6" -expected = "10000.00000000000000000000000" description = "Root of very large number" +expected = "10000.00000000000000000000000" [[root_tests]] a = "2" b = "1" -expected = "2" description = "First root (identity)" +expected = "2" [[root_tests]] a = "3.14159265358979323846264338328" b = "2" -expected = "1.772453850905516027298167483" description = "Root of π" +expected = "1.772453850905516027298167483" [[root_tests]] a = "2.71828182845904523536028747135" b = "3" -expected = "1.395612425086089528628125320" description = "Root of e" +expected = "1.395612425086089528628125320" # Extreme precision tests [[root_tests]] a = "12345.6789" b = "2" -expected = "111.1111106055555544054166614" description = "High precision square root" +expected = "111.1111106055555544054166614" [[root_tests]] a = "1.0001" b = "10000" -expected = "1.000000009999500083325834158" description = "Very high root close to 1" +expected = "1.000000009999500083325834158" # === POWER TESTS === # Testing power function with various base and exponent combinations @@ -518,119 +518,119 @@ description = "Very high root close to 1" [[power_tests]] a = "2" b = "3" -expected = "8" description = "Integer base, integer exponent (2^3)" +expected = "8" [[power_tests]] a = "10" b = "2" -expected = "100" description = "Power of 10 (10^2)" +expected = "100" [[power_tests]] a = "2.5" b = "2" -expected = "6.25" description = "Decimal base, integer exponent (2.5^2)" +expected = "6.25" [[power_tests]] a = "4" b = "0.5" -expected = "2.000000000000000000000000000" description = "Integer base, fractional exponent (4^0.5 = sqrt(4))" +expected = "2.000000000000000000000000000" [[power_tests]] a = "9" b = "0.5" -expected = "3.000000000000000000000000000" description = "Integer base, fractional exponent (9^0.5 = sqrt(9))" +expected = "3.000000000000000000000000000" [[power_tests]] a = "27" b = "0.3333333333333333333333333333" -expected = "3.000000000000000000000000000" description = "Integer base, fractional exponent (27^(1/3) = cube root of 27)" +expected = "3.000000000000000000000000000" [[power_tests]] a = "2" b = "10" -expected = "1024" description = "Small base, large exponent (2^10)" +expected = "1024" [[power_tests]] a = "1.5" b = "3" -expected = "3.375" description = "Decimal base, integer exponent (1.5^3)" +expected = "3.375" [[power_tests]] a = "0" b = "5" -expected = "0" description = "Zero base, positive exponent" +expected = "0" [[power_tests]] a = "1" b = "1000" -expected = "1" description = "Base of 1, any exponent" +expected = "1" [[power_tests]] a = "-2" b = "3" -expected = "-8" description = "Negative base, odd exponent" +expected = "-8" [[power_tests]] a = "-2" b = "2" -expected = "4" description = "Negative base, even exponent" +expected = "4" [[power_tests]] a = "0.1" b = "2" -expected = "0.01" description = "Decimal less than 1, integer exponent" +expected = "0.01" [[power_tests]] a = "2" b = "-2" -expected = "0.25" description = "Positive base, negative exponent" +expected = "0.25" [[power_tests]] a = "4" b = "-0.5" -expected = "0.5000000000000000000000000000" description = "Integer base, negative fractional exponent" +expected = "0.5000000000000000000000000000" [[power_tests]] a = "10" b = "-1" -expected = "0.1" description = "Base 10, negative exponent" +expected = "0.1" [[power_tests]] a = "3.14159" b = "2" -expected = "9.8695877281" description = "Pi approximation squared" +expected = "9.8695877281" [[power_tests]] a = "2.71828" b = "3" -expected = "20.085496391455552" description = "E approximation cubed" +expected = "20.085496391455552" [[power_tests]] a = "1.5" b = "2.5" -expected = "2.755675960631075360471944584" description = "Decimal base, decimal exponent" +expected = "2.755675960631075360471944584" [[power_tests]] a = "1.5" b = "0" -expected = "1" description = "Any base, zero exponent" +expected = "1" diff --git a/tests/bigdecimal/test_data/bigdecimal_rounding.toml b/tests/bigdecimal/test_data/bigdecimal_rounding.toml index 3656a50..1219db7 100644 --- a/tests/bigdecimal/test_data/bigdecimal_rounding.toml +++ b/tests/bigdecimal/test_data/bigdecimal_rounding.toml @@ -2,348 +2,348 @@ [[round_down_tests]] a = "12.345" b = "0" -expected = "12" description = "Round down to integer" +expected = "12" [[round_down_tests]] a = "12.345" b = "1" -expected = "12.3" description = "Round down to 1 decimal place" +expected = "12.3" [[round_down_tests]] a = "12.345" b = "2" -expected = "12.34" description = "Round down to 2 decimal places" +expected = "12.34" [[round_down_tests]] a = "12.345" b = "3" -expected = "12.345" description = "Round to same precision" +expected = "12.345" [[round_down_tests]] a = "12.345" b = "4" -expected = "12.3450" description = "Round to higher precision" +expected = "12.3450" [[round_down_tests]] a = "-12.345" b = "0" -expected = "-12" description = "Round down negative to integer" +expected = "-12" [[round_down_tests]] a = "-12.345" b = "1" -expected = "-12.3" description = "Round down negative to 1 decimal place" +expected = "-12.3" [[round_down_tests]] a = "-12.345" b = "2" -expected = "-12.34" description = "Round down negative to 2 decimal places" +expected = "-12.34" [[round_down_tests]] a = "0.9999" b = "0" -expected = "0" description = "Round down near-1 value to integer" +expected = "0" [[round_down_tests]] a = "9.9999" b = "0" -expected = "9" description = "Round down near-10 value to integer" +expected = "9" # === ROUND UP TESTS === [[round_up_tests]] a = "12.345" b = "0" -expected = "13" description = "Round up to integer" +expected = "13" [[round_up_tests]] a = "12.345" b = "1" -expected = "12.4" description = "Round up to 1 decimal place" +expected = "12.4" [[round_up_tests]] a = "12.345" b = "2" -expected = "12.35" description = "Round up to 2 decimal places" +expected = "12.35" [[round_up_tests]] a = "12.345" b = "3" -expected = "12.345" description = "Round to same precision" +expected = "12.345" [[round_up_tests]] a = "-12.345" b = "0" -expected = "-13" description = "Round up negative to integer" +expected = "-13" [[round_up_tests]] a = "-12.345" b = "1" -expected = "-12.4" description = "Round up negative to 1 decimal place" +expected = "-12.4" [[round_up_tests]] a = "0.001" b = "0" -expected = "0" description = "Round up small positive value to integer" +expected = "0" [[round_up_tests]] a = "-0.001" b = "0" -expected = "-0" description = "Round up small negative value to integer" +expected = "-0" # === ROUND HALF UP TESTS === [[round_half_up_tests]] a = "12.5" b = "0" -expected = "13" description = "Round half up to integer" +expected = "13" [[round_half_up_tests]] a = "12.4" b = "0" -expected = "12" description = "Round half up where less than .5" +expected = "12" [[round_half_up_tests]] a = "12.25" b = "1" -expected = "12.3" description = "Round half up to 1 decimal place" +expected = "12.3" [[round_half_up_tests]] a = "12.35" b = "1" -expected = "12.4" description = "Round half up exactly .5 to 1 decimal place" +expected = "12.4" [[round_half_up_tests]] a = "-12.5" b = "0" -expected = "-13" description = "Round half up negative to integer" +expected = "-13" [[round_half_up_tests]] a = "-12.45" b = "1" -expected = "-12.5" description = "Round half up negative to 1 decimal place" +expected = "-12.5" [[round_half_up_tests]] a = "0.5" b = "0" -expected = "1" description = "Round half up exactly 0.5 to integer" +expected = "1" [[round_half_up_tests]] a = "-0.5" b = "0" -expected = "-1" description = "Round half up exactly -0.5 to integer" +expected = "-1" # === ROUND HALF EVEN TESTS (BANKER'S ROUNDING) === [[round_half_even_tests]] a = "12.5" b = "0" -expected = "12" description = "Round half even to integer (toward even digit)" +expected = "12" [[round_half_even_tests]] a = "13.5" b = "0" -expected = "14" description = "Round half even to integer (toward even digit)" +expected = "14" [[round_half_even_tests]] a = "12.25" b = "1" -expected = "12.2" description = "Round half even to 1 decimal place (toward even digit)" +expected = "12.2" [[round_half_even_tests]] a = "12.35" b = "1" -expected = "12.4" description = "Round half even to 1 decimal place (toward even digit)" +expected = "12.4" [[round_half_even_tests]] a = "12.65" b = "1" -expected = "12.6" description = "Round half even to 1 decimal place (toward even digit)" +expected = "12.6" [[round_half_even_tests]] a = "12.75" b = "1" -expected = "12.8" description = "Round half even to 1 decimal place (toward even digit)" +expected = "12.8" [[round_half_even_tests]] a = "-12.5" b = "0" -expected = "-12" description = "Round half even negative to integer (toward even digit)" +expected = "-12" [[round_half_even_tests]] a = "-13.5" b = "0" -expected = "-14" description = "Round half even negative to integer (toward even digit)" +expected = "-14" [[round_half_even_tests]] a = "0.5" b = "0" -expected = "0" description = "Round half even exactly 0.5 to integer (0 is even)" +expected = "0" [[round_half_even_tests]] a = "-0.5" b = "0" -expected = "-0" description = "Round half even exactly -0.5 to integer (0 is even)" +expected = "-0" # === EXTREME VALUES TESTS === [[extreme_value_tests]] a = "0.00000000000000000000000001" b = "10" -expected = "0.0000000000" description = "Rounding very small number" +expected = "0E-10" [[extreme_value_tests]] a = "9999999999999999999999999999.99999" b = "2" -expected = "1.000000000000000000000000000000E+28" description = "Rounding very large number" +expected = "1.000000000000000000000000000000E+28" [[extreme_value_tests]] a = "0.5555555555555555555555555" b = "10" -expected = "0.5555555556" description = "Rounding repeated digits" +expected = "0.5555555556" [[extreme_value_tests]] a = "1.000000000000000000000000001" b = "10" -expected = "1.0000000000" description = "Rounding number very close to whole" +expected = "1.0000000000" [[extreme_value_tests]] a = "-0.000000000000000000000000001" b = "10" -expected = "-0E-10" description = "Rounding very small negative number (becomes zero)" +expected = "-0E-10" # === SPECIAL EDGE CASES === [[edge_case_tests]] a = "9.9999999999999999999999999" b = "2" -expected = "10.00" description = "Rounding causes carrying over to next digit" +expected = "10.00" [[edge_case_tests]] a = "999.9999999999999999999999999" b = "0" -expected = "1000" description = "Rounding causes carrying over to next 10s place" +expected = "1000" [[edge_case_tests]] a = "0.00000000000000000000000005" b = "28" -expected = "5.00E-26" description = "Rounding at maximum precision boundary" +expected = "5.00E-26" [[edge_case_tests]] a = "0" b = "10" -expected = "0.0000000000" description = "Rounding zero" +expected = "0E-10" [[edge_case_tests]] a = "-0" b = "10" -expected = "-0.0000000000" description = "Rounding negative zero" +expected = "-0E-10" [[edge_case_tests]] a = "0.499999999999999999999999999" b = "0" -expected = "0" description = "Rounding just under half" +expected = "0" [[edge_case_tests]] a = "0.500000000000000000000000001" b = "0" -expected = "1" description = "Rounding just over half" +expected = "1" # === PRECISION CONVERSIONS === [[precision_tests]] a = "123.456" b = "-2" -expected = "1E+2" description = "Rounding to negative precision (hundreds)" +expected = "1E+2" [[precision_tests]] a = "1234.56" b = "-1" -expected = "1.23E+3" description = "Rounding to negative precision (tens)" +expected = "1.23E+3" [[precision_tests]] a = "1234.56" b = "-3" -expected = "1E+3" description = "Rounding to negative precision (thousands)" +expected = "1E+3" [[precision_tests]] a = "9999.99" b = "-3" -expected = "1.0E+4" description = "Rounding to negative precision with carry" +expected = "1.0E+4" [[precision_tests]] a = "0.000123456" b = "5" -expected = "0.00012" description = "Rounding where leading zeros matter" +expected = "0.00012" # === SCIENTIFIC NOTATION INPUTS === [[scientific_tests]] a = "1.2345e5" b = "2" -expected = "123450.00" description = "Rounding scientific notation value" +expected = "123450.00" [[scientific_tests]] a = "1.2345e-5" b = "8" -expected = "0.00001234" description = "Rounding small scientific notation value" +expected = "0.00001234" [[scientific_tests]] a = "9.9999e20" b = "0" -expected = "999990000000000000000" description = "Rounding large scientific notation value" +expected = "999990000000000000000" [[scientific_tests]] a = "-1.2345e-10" b = "12" -expected = "-0.000000000123" description = "Rounding negative scientific notation value" +expected = "-1.23E-10" diff --git a/tests/bigdecimal/test_data/bigdecimal_trigonometric.toml b/tests/bigdecimal/test_data/bigdecimal_trigonometric.toml index 0925442..0acd3f6 100644 --- a/tests/bigdecimal/test_data/bigdecimal_trigonometric.toml +++ b/tests/bigdecimal/test_data/bigdecimal_trigonometric.toml @@ -5,122 +5,122 @@ [[sin_tests]] a = "0" b = "" -expected = "0" description = "sin(0) = 0" +expected = "0" [[sin_tests]] a = "0.5235987755982988730771072305" b = "" -expected = "0.49999999999999999999999999995965723364237186253345" description = "sin(π/6) = 0.5" +expected = "0.49999999999999999999999999995965723364237186253345" [[sin_tests]] a = "0.7853981633974483096156608458" b = "" -expected = "0.70710678118654752440084436209079478214990911530509" description = "sin(π/4) = √2/2" +expected = "0.70710678118654752440084436209079478214990911530509" [[sin_tests]] a = "1.0471975511965977461542144611" b = "" -expected = "0.86602540378443864676372317075635236943854106034267" description = "sin(π/3) = √3/2" +expected = "0.86602540378443864676372317075635236943854106034267" [[sin_tests]] a = "1.5707963267948966192313216916" b = "" -expected = "1.0000000000000000000000000000000000000000000000000" description = "sin(π/2) = 1" +expected = "1.0000000000000000000000000000000000000000000000000" [[sin_tests]] a = "2.0943951023931954923084289221" b = "" -expected = "0.86602540378443864676372317079610381153712576003023" description = "sin(2π/3) = √3/2" +expected = "0.86602540378443864676372317079610381153712576003023" [[sin_tests]] a = "2.3561944901923449288469825375" b = "" -expected = "0.70710678118654752440084436207630113257096165239855" description = "sin(3π/4) = √2/2" +expected = "0.70710678118654752440084436207630113257096165239855" [[sin_tests]] a = "2.6179938779914943653855361833" b = "" -expected = "0.49999999999999999999999997352813139522743036701006" description = "sin(5π/6) = 0.5" +expected = "0.49999999999999999999999997352813139522743036701006" [[sin_tests]] a = "3.1415926535897932384626433833" b = "" -expected = "-2.0497115802830600624894179025055407692183593713791E-29" description = "sin(π) = 0" +expected = "-2.0497115802830600624894179025055407692183593713791E-29" [[sin_tests]] a = "4.7123889803846898576939650749" b = "" -expected = "-1.0000000000000000000000000000000000000000000000000" description = "sin(3π/2) = -1" +expected = "-1.0000000000000000000000000000000000000000000000000" [[sin_tests]] a = "6.2831853071795864769252867666" b = "" -expected = "4.0994231605661201249788358050110815384367187427582E-29" description = "sin(2π) = 0" +expected = "4.0994231605661201249788358050110815384367187427582E-29" [[sin_tests]] a = "-0.5235987755982988730771072305" b = "" -expected = "-0.49999999999999999999999999995965723364237186253345" description = "sin(-π/6) = -0.5" +expected = "-0.49999999999999999999999999995965723364237186253345" [[sin_tests]] a = "-1.5707963267948966192313216916" b = "" -expected = "-1.0000000000000000000000000000000000000000000000000" description = "sin(-π/2) = -1" +expected = "-1.0000000000000000000000000000000000000000000000000" [[sin_tests]] a = "-3.1415926535897932384626433833" b = "" -expected = "2.0497115802830600624894179025055407692183593713791E-29" description = "sin(-π) = 0" +expected = "2.0497115802830600624894179025055407692183593713791E-29" [[sin_tests]] a = "0.1" b = "" -expected = "0.099833416646828152306814198410622026989915388017982" description = "sin(0.1) - small positive value" +expected = "0.099833416646828152306814198410622026989915388017982" [[sin_tests]] a = "0.3" b = "" -expected = "0.29552020666133957510532074568502737367783211174262" description = "sin(0.3) - moderate small value" +expected = "0.29552020666133957510532074568502737367783211174262" [[sin_tests]] a = "1.0" b = "" -expected = "0.84147098480789650665250232163029899962256306079837" description = "sin(1) - one radian" +expected = "0.84147098480789650665250232163029899962256306079837" [[sin_tests]] a = "2.0" b = "" -expected = "0.90929742682568169539601986591174484270225497144789" description = "sin(2) - two radians" +expected = "0.90929742682568169539601986591174484270225497144789" [[sin_tests]] a = "10.0" b = "" -expected = "-0.54402111088936981340474766185137728168364301291622" description = "sin(10) - large value test" +expected = "-0.54402111088936981340474766185137728168364301291622" [[sin_tests]] a = "0.0001" b = "" -expected = "0.000099999999833333333416666666646825396828152557318973" description = "sin(0.0001) - very small value (linear approximation region)" +expected = "0.000099999999833333333416666666646825396828152557318973" # ===----------------------------------------------------------------------=== # # Test cases for cos @@ -129,20 +129,20 @@ description = "sin(0.0001) - very small value (linear approximation region)" [[cos_tests]] a = "0" b = "" -expected = "1" description = "cos(0) = 1" +expected = "1" [[cos_tests]] a = "0.5235987755982988730771072305" b = "" -expected = "0.86602540378443864676372317077622809048783341018645" description = "cos(π/6) = √3/2" +expected = "0.86602540378443864676372317077622809048783341018645" [[cos_tests]] a = "-1.2345678901234567890123456789012345678901234567890" b = "" -expected = "0.32992906977373266497821982544739832858011036857534" description = "negative value" +expected = "0.32992906977373266497821982544739832858011036857534" # ===----------------------------------------------------------------------=== # # Test cases for tan @@ -151,44 +151,44 @@ description = "negative value" [[tan_tests]] a = "1.5707963267948966192313216916397514420985846996876" b = "" -expected = "-2.1236151030692384854558538473739128298113204417314E+49" description = "tan(π/2) - very large or small value" +expected = "-2.1236151030692384854558538473739128298113204417314E+49" [[tan_tests]] a = "0" b = "" -expected = "0" description = "tan(0) = 0" +expected = "0" [[tan_tests]] a = "0.78539816339744830961566084581987572104929234984378" b = "" -expected = "1.0000000000000000000000000000000000000000000000000" description = "tan(π/4) = 1" +expected = "1.0000000000000000000000000000000000000000000000000" [[tan_tests]] a = "1.0471975511965977461542144610931676280657231331250" b = "" -expected = "1.7320508075688772935274463415058723669428052538102" description = "tan(π/3) = √3" +expected = "1.7320508075688772935274463415058723669428052538102" [[tan_tests]] a = "0.1" b = "" -expected = "0.10033467208545054505808004578111153681900480457644" description = "tan(0.1) - small positive value" +expected = "0.10033467208545054505808004578111153681900480457644" [[tan_tests]] a = "-0.3" b = "" -expected = "-0.30933624960962323303530367969829466725781590680046" description = "tan(-0.3) - small negative value" +expected = "-0.30933624960962323303530367969829466725781590680046" [[tan_tests]] a = "100" b = "" -expected = "-0.58721391515692907667780963564458789425876598687292" description = "tan(100) - very large value" +expected = "-0.58721391515692907667780963564458789425876598687292" # ===----------------------------------------------------------------------=== # # Test cases for cot @@ -197,20 +197,20 @@ description = "tan(100) - very large value" [[cot_tests]] a = "1" b = "" -expected = "0.64209261593433070300641998659426562023027811391817" description = "cot(1) - small positive value" +expected = "0.64209261593433070300641998659426562023027811391817" [[cot_tests]] a = "-3" b = "" -expected = "7.0152525514345334694285513795264765782931033520964" description = "cot(-3) - small negative value" +expected = "7.0152525514345334694285513795264765782931033520964" [[cot_tests]] a = "10" b = "" -expected = "1.5423510453569200482774693556824293113206672064020" description = "cot(10) - large positive value" +expected = "1.5423510453569200482774693556824293113206672064020" # ===----------------------------------------------------------------------=== # # Test cases for arctan @@ -219,125 +219,125 @@ description = "cot(10) - large positive value" [[arctan_tests]] a = "0" b = "" -expected = "0" description = "Arctan of 0" +expected = "0" [[arctan_tests]] a = "1" b = "" -expected = "0.78539816339744830961566084581987572104929234984378" description = "Arctan of 1 = π/4" +expected = "0.78539816339744830961566084581987572104929234984378" [[arctan_tests]] a = "-1" b = "" -expected = "-0.78539816339744830961566084581987572104929234984378" description = "Arctan of -1 = -π/4" +expected = "-0.78539816339744830961566084581987572104929234984378" [[arctan_tests]] a = "0.5" b = "" -expected = "0.46364760900080611621425623146121440202853705428612" description = "Arctan of 0.5" +expected = "0.46364760900080611621425623146121440202853705428612" [[arctan_tests]] a = "-0.5" b = "" -expected = "-0.46364760900080611621425623146121440202853705428612" description = "Arctan of -0.5" +expected = "-0.46364760900080611621425623146121440202853705428612" [[arctan_tests]] a = "0.2" b = "" -expected = "0.19739555984988075837004976519479029344758510378785" description = "Arctan of 0.2 (small positive value)" +expected = "0.19739555984988075837004976519479029344758510378785" [[arctan_tests]] a = "0.1" b = "" -expected = "0.099668652491162027378446119878020590243278322504315" description = "Arctan of 0.1 (very small value for good convergence)" +expected = "0.099668652491162027378446119878020590243278322504315" [[arctan_tests]] a = "0.6" b = "" -expected = "0.54041950027058415544357836460859991013514825146259" description = "Arctan of 0.6" +expected = "0.54041950027058415544357836460859991013514825146259" [[arctan_tests]] a = "0.7" b = "" -expected = "0.61072596438920861654375887649023609381850306612883" description = "Arctan of 0.7" +expected = "0.61072596438920861654375887649023609381850306612883" [[arctan_tests]] a = "0.8" b = "" -expected = "0.67474094222355266305652097360981361507400625484071" description = "Arctan of 0.8" +expected = "0.67474094222355266305652097360981361507400625484071" [[arctan_tests]] a = "0.9" b = "" -expected = "0.73281510178650659164079207273428025198575567935826" description = "Arctan of 0.9" +expected = "0.73281510178650659164079207273428025198575567935826" [[arctan_tests]] a = "2" b = "" -expected = "1.1071487177940905030170654601785370400700476454014" description = "Arctan of 2 (>1, tests convergence for larger values)" +expected = "1.1071487177940905030170654601785370400700476454014" [[arctan_tests]] a = "3" b = "" -expected = "1.2490457723982544258299170772810901230778294041299" description = "Arctan of 3" +expected = "1.2490457723982544258299170772810901230778294041299" [[arctan_tests]] a = "5" b = "" -expected = "1.3734007669450158608612719264449611486509995958997" description = "Arctan of 5 (large value)" +expected = "1.3734007669450158608612719264449611486509995958997" [[arctan_tests]] a = "-10" b = "" -expected = "-1.4711276743037345918528755717617308518553063771832" description = "Arctan of -10 (negative large value)" +expected = "-1.4711276743037345918528755717617308518553063771832" [[arctan_tests]] a = "-20" b = "" -expected = "-1.5208379310729538578213154046049065606073076192640" description = "Arctan of -20 (negative large value)" +expected = "-1.5208379310729538578213154046049065606073076192640" [[arctan_tests]] a = "0.2679491924311227064725536584405014305617238566135711746170850036962728620449831" b = "" -expected = "0.26179938779914943653855361522325797893391221422499" description = "Arctan of tan(π/12) should equal π/12" +expected = "0.26179938779914943653855361522325797893391221422499" [[arctan_tests]] a = "0.5773502691896257645091487805019574556476017512701268760186023264839776723054951" b = "" -expected = "0.52359877559829887307710723054658381403286156656252" description = "Arctan of tan(π/6) = √3/3 should equal π/6" +expected = "0.52359877559829887307710723054658381403286156656252" [[arctan_tests]] a = "-1.7320508075688772935274463415058723669428052538103806280558069794519330169088000" b = "" -expected = "-1.0471975511965977461542144610931676280657231331250" description = "Arctan of -√3 should equal -π/3" +expected = "-1.0471975511965977461542144610931676280657231331250" [[arctan_tests]] a = "0.00001" b = "" -expected = "9.9999999996666666666866666666652380952382063492063E-6" description = "Arctan of very small value (near linear approximation)" +expected = "9.9999999996666666666866666666652380952382063492063E-6" [[arctan_tests]] a = "100" b = "" -expected = "1.5607966601082313810249815754304718935372153471432" description = "Arctan of 100 (very large value, should approach π/2)" +expected = "1.5607966601082313810249815754304718935372153471432" diff --git a/tests/bigint/test_bigint_arithmetics.mojo b/tests/bigint/test_bigint_arithmetics.mojo index e632896..1be95ee 100644 --- a/tests/bigint/test_bigint_arithmetics.mojo +++ b/tests/bigint/test_bigint_arithmetics.mojo @@ -17,8 +17,8 @@ fn test_bigint_arithmetics() raises: var toml = parse_file(file_path_arithmetics) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigInt addition...") + # print("------------------------------------------------------") + # print("Testing BigInt addition...") test_cases = load_test_cases(toml, "addition_tests") for test_case in test_cases: var result = BigInt(test_case.a) + BigInt(test_case.b) @@ -27,10 +27,10 @@ fn test_bigint_arithmetics() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigInt addition tests passed!") + # print("BigInt addition tests passed!") - print("------------------------------------------------------") - print("Testing BigInt subtraction...") + # print("------------------------------------------------------") + # print("Testing BigInt subtraction...") test_cases = load_test_cases(toml, "subtraction_tests") for test_case in test_cases: var result = BigInt(test_case.a) - BigInt(test_case.b) @@ -39,10 +39,10 @@ fn test_bigint_arithmetics() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigInt subtraction tests passed!") + # print("BigInt subtraction tests passed!") - print("------------------------------------------------------") - print("Testing BigInt negation...") + # print("------------------------------------------------------") + # print("Testing BigInt negation...") test_cases = load_test_cases[unary=True](toml, "negation_tests") for test_case in test_cases: var result = -BigInt(test_case.a) @@ -51,10 +51,10 @@ fn test_bigint_arithmetics() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigInt negation tests passed!") + # print("BigInt negation tests passed!") - print("------------------------------------------------------") - print("Testing BigInt absolute value...") + # print("------------------------------------------------------") + # print("Testing BigInt absolute value...") test_cases = load_test_cases[unary=True](toml, "abs_tests") for test_case in test_cases: var result = abs(BigInt(test_case.a)) @@ -63,7 +63,7 @@ fn test_bigint_arithmetics() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigInt absolute value tests passed!") + # print("BigInt absolute value tests passed!") fn test_bigint_multiply() raises: @@ -71,8 +71,8 @@ fn test_bigint_multiply() raises: var toml = parse_file(file_path_multiply) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigInt multiplication...") + # print("------------------------------------------------------") + # print("Testing BigInt multiplication...") test_cases = load_test_cases(toml, "multiplication_tests") for test_case in test_cases: var result = BigInt(test_case.a) * BigInt(test_case.b) @@ -81,7 +81,7 @@ fn test_bigint_multiply() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigInt multiplication tests passed!") + # print("BigInt multiplication tests passed!") fn test_bigint_floor_divide() raises: @@ -89,8 +89,8 @@ fn test_bigint_floor_divide() raises: var toml = parse_file(file_path_floor_divide) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigInt floor division...") + # print("------------------------------------------------------") + # print("Testing BigInt floor division...") test_cases = load_test_cases(toml, "floor_divide_tests") for test_case in test_cases: var result = BigInt(test_case.a) // BigInt(test_case.b) @@ -99,7 +99,7 @@ fn test_bigint_floor_divide() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigInt floor division tests passed!") + # print("BigInt floor division tests passed!") fn test_bigint_truncate_divide() raises: @@ -107,8 +107,8 @@ fn test_bigint_truncate_divide() raises: var toml = parse_file(file_path_truncate_divide) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigInt truncate division...") + # print("------------------------------------------------------") + # print("Testing BigInt truncate division...") test_cases = load_test_cases(toml, "truncate_divide_tests") for test_case in test_cases: var result = BigInt(test_case.a).truncate_divide(BigInt(test_case.b)) @@ -117,13 +117,16 @@ fn test_bigint_truncate_divide() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigInt truncate division tests passed!") + # print("BigInt truncate division tests passed!") fn main() raises: - print("Running BigInt arithmetic tests") - test_bigint_arithmetics() - test_bigint_multiply() - test_bigint_floor_divide() - test_bigint_truncate_divide() - print("All BigInt arithmetic tests passed!") + # print("Running BigInt arithmetic tests") + + # test_bigint_arithmetics() + # test_bigint_multiply() + # test_bigint_floor_divide() + # test_bigint_truncate_divide() + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All BigInt arithmetic tests passed!") diff --git a/tests/bigint/test_bigint_to_int.mojo b/tests/bigint/test_bigint_to_int.mojo index e7eb737..24212bd 100644 --- a/tests/bigint/test_bigint_to_int.mojo +++ b/tests/bigint/test_bigint_to_int.mojo @@ -10,64 +10,64 @@ import decimojo.bigint.arithmetics as arithmetics fn test_int_conversion() raises: - print("------------------------------------------------------") - print("--- Testing BigInt to Int Conversion ---") + # print("------------------------------------------------------") + # print("--- Testing BigInt to Int Conversion ---") # Test positive integer var b1 = BigInt("123") var i1 = b1.to_int() - print("BigInt(123).to_int() =", i1) + # print("BigInt(123).to_int() =", i1) testing.assert_equal(i1, 123) # Test through __int__() operator var i1b = Int(b1) - print("Int(BigInt(123)) =", i1b) + # print("Int(BigInt(123)) =", i1b) testing.assert_equal(i1b, 123) # Test negative integer var b2 = BigInt("-456") var i2 = b2.to_int() - print("BigInt(-456).to_int() =", i2) + # print("BigInt(-456).to_int() =", i2) testing.assert_equal(i2, -456) # Test zero var b3 = BigInt("0") var i3 = b3.to_int() - print("BigInt(0).to_int() =", i3) + # print("BigInt(0).to_int() =", i3) testing.assert_equal(i3, 0) # Test large positive number within Int range var b4 = BigInt("9999999999") # 10 billion is within Int64 range var i4 = b4.to_int() - print("BigInt(9999999999).to_int() =", i4) + # print("BigInt(9999999999).to_int() =", i4) testing.assert_equal(i4, 9999999999) # Test large negative number within Int range var b5 = BigInt("-9999999999") var i5 = b5.to_int() - print("BigInt(-9999999999).to_int() =", i5) + # print("BigInt(-9999999999).to_int() =", i5) testing.assert_equal(i5, -9999999999) # Test Int.MAX edge case var b6 = BigInt(String(Int.MAX)) var i6 = b6.to_int() - print("BigInt(Int.MAX).to_int() =", i6) + # print("BigInt(Int.MAX).to_int() =", i6) testing.assert_equal(i6, Int.MAX) # Test Int.MIN edge case var b7 = BigInt(String(Int.MIN)) var i7 = b7.to_int() - print("BigInt(Int.MIN).to_int() =", i7) + # print("BigInt(Int.MIN).to_int() =", i7) testing.assert_equal(i7, Int.MIN) fn test_error_cases() raises: - print("------------------------------------------------------") - print("--- Testing Error Cases ---") + # print("------------------------------------------------------") + # print("--- Testing Error Cases ---") # Test number larger than Int.MAX var b1 = BigInt(String(Int.MAX)) + BigInt("1") - print("Testing conversion of:", b1, "(Int.MAX + 1)") + # print("Testing conversion of:", b1, "(Int.MAX + 1)") var exception_caught = False try: var _b1 = b1.to_int() @@ -79,7 +79,7 @@ fn test_error_cases() raises: # Test number smaller than Int.MIN var b2 = BigInt(String(Int.MIN)) - BigInt("1") - print("Testing conversion of:", b2, "(Int.MIN - 1)") + # print("Testing conversion of:", b2, "(Int.MIN - 1)") exception_caught = False try: var _b2 = b2.to_int() @@ -91,7 +91,7 @@ fn test_error_cases() raises: # Test very large number var b3 = BigInt("99999999999999999999999999999") # Way beyond Int64 range - print("Testing conversion of very large number:", b3) + # print("Testing conversion of very large number:", b3) exception_caught = False try: var _b3 = b3.to_int() @@ -103,10 +103,10 @@ fn test_error_cases() raises: fn main() raises: - print("Starting BigInt to Int conversion tests...") + # print("Starting BigInt to Int conversion tests...") - test_int_conversion() + # test_int_conversion() + # test_error_cases() + testing.TestSuite.discover_tests[__functions_in_module()]().run() - test_error_cases() - - print("\nAll tests completed!") + # print("\nAll tests completed!") diff --git a/tests/bigint/test_data/bigint_arithmetics.toml b/tests/bigint/test_data/bigint_arithmetics.toml index 77456a6..86bfa09 100644 --- a/tests/bigint/test_data/bigint_arithmetics.toml +++ b/tests/bigint/test_data/bigint_arithmetics.toml @@ -12,132 +12,132 @@ [[addition_tests]] a = "123" b = "456" -expected = "579" description = "Simple addition of positive numbers" +expected = "579" [[addition_tests]] a = "123" b = "-456" -expected = "-333" description = "Addition with negative numbers" +expected = "-333" [[addition_tests]] a = "-789" b = "456" -expected = "-333" description = "Addition resulting in negative" +expected = "-333" [[addition_tests]] a = "-123" b = "-456" -expected = "-579" description = "Addition of negative numbers" +expected = "-579" [[addition_tests]] a = "123" b = "0" -expected = "123" description = "Addition with zero" +expected = "123" [[addition_tests]] a = "123" b = "-123" -expected = "0" description = "Addition resulting in zero" +expected = "0" [[addition_tests]] a = "99999999999999999999" b = "1" -expected = "100000000000000000000" description = "Addition with large numbers" +expected = "100000000000000000000" [[addition_tests]] a = "9999999999" b = "1" -expected = "10000000000" description = "Addition causing multiple carries" +expected = "10000000000" [[addition_tests]] a = "12345" b = "9876543210" -expected = "9876555555" description = "Addition with numbers of different sizes" +expected = "9876555555" [[addition_tests]] a = "12345678901234567890123456789" b = "98765432109876543210987654321" -expected = "111111111011111111101111111110" description = "Addition with very large numbers spanning multiple words" +expected = "111111111011111111101111111110" [[addition_tests]] a = "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" b = "1" -expected = "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" description = "Adding numbers that require carry propagation through multiple words" +expected = "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" [[addition_tests]] a = "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" b = "50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" -expected = "150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" description = "Addition of very large numbers" +expected = "150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" [[addition_tests]] a = "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" b = "1" -expected = "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" description = "Addition with extensive carry propagation" +expected = "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" [[addition_tests]] a = "122222222222222222222222222222222222222222222222222" b = "-122222222222222222222222222222222222222222222222222" -expected = "0" description = "Adding opposite large numbers (should equal zero)" +expected = "0" # ===----------------------------------------------------------------------=== # # Test cases for BigInt negation # ===----------------------------------------------------------------------=== # [[negation_tests]] a = "123" -expected = "-123" description = "Negate positive number" +expected = "-123" [[negation_tests]] a = "-456" -expected = "456" description = "Negate negative number" +expected = "456" [[negation_tests]] a = "0" -expected = "0" description = "Negate zero (signed zero)" +expected = "0" [[negation_tests]] a = "999999999999999999999999999999999999999999999999999" -expected = "-999999999999999999999999999999999999999999999999999" description = "Negate large number" +expected = "-999999999999999999999999999999999999999999999999999" # ===----------------------------------------------------------------------=== # # Test cases for BigInt absolute value # ===----------------------------------------------------------------------=== # [[abs_tests]] a = "123" -expected = "123" description = "Absolute value of positive number" +expected = "123" [[abs_tests]] a = "-456" -expected = "456" description = "Absolute value of negative number" +expected = "456" [[abs_tests]] a = "0" -expected = "0" description = "Absolute value of zero" +expected = "0" [[abs_tests]] a = "-999999999999999999999999999999999999999999999999999" -expected = "999999999999999999999999999999999999999999999999999" description = "Absolute value of large negative number" +expected = "999999999999999999999999999999999999999999999999999" # ===----------------------------------------------------------------------=== # # Test cases for BigInt subtraction @@ -145,78 +145,77 @@ description = "Absolute value of large negative number" [[subtraction_tests]] a = "456" b = "123" -expected = "333" description = "Simple subtraction" +expected = "333" [[subtraction_tests]] a = "123" b = "456" -expected = "-333" description = "Subtraction resulting in negative" +expected = "-333" [[subtraction_tests]] a = "123" b = "-456" -expected = "579" description = "Subtracting negative number (essentially addition)" +expected = "579" [[subtraction_tests]] a = "-123" b = "456" -expected = "-579" description = "Negative minus positive" +expected = "-579" [[subtraction_tests]] a = "-456" b = "-123" -expected = "-333" description = "Negative minus negative" +expected = "-333" [[subtraction_tests]] a = "123" b = "0" -expected = "123" description = "Subtraction with zero" +expected = "123" [[subtraction_tests]] a = "0" b = "123" -expected = "-123" description = "Zero minus a number" +expected = "-123" [[subtraction_tests]] a = "123" b = "123" -expected = "0" description = "Subtraction resulting in zero" +expected = "0" [[subtraction_tests]] a = "10000" b = "1" -expected = "9999" description = "Subtraction with borrow" +expected = "9999" [[subtraction_tests]] a = "10000" b = "9999" -expected = "1" description = "Subtraction with multiple borrows" +expected = "1" [[subtraction_tests]] a = "999999999999999999999999999999999999999999999999999" b = "100000000000000000000000000000000000000000000000000" -expected = "899999999999999999999999999999999999999999999999999" description = "Subtraction of large numbers" +expected = "899999999999999999999999999999999999999999999999999" [[subtraction_tests]] a = "12345678901234567890" b = "12345678901234567890" -expected = "0" description = "Self subtraction should yield zero" +expected = "0" [[subtraction_tests]] a = "9876543210" b = "12345" -expected = "9876530865" description = "Subtraction with numbers of different sizes" - +expected = "9876530865" diff --git a/tests/bigint/test_data/bigint_floor_divide.toml b/tests/bigint/test_data/bigint_floor_divide.toml index 08e1d7a..faccaca 100644 --- a/tests/bigint/test_data/bigint_floor_divide.toml +++ b/tests/bigint/test_data/bigint_floor_divide.toml @@ -16,32 +16,32 @@ [[floor_divide_tests]] a = "10" b = "2" -expected = "5" description = "Simple division with no remainder: 10 // 2" +expected = "5" [[floor_divide_tests]] a = "10" b = "3" -expected = "3" description = "Division with remainder (floor towards negative infinity): 10 // 3" +expected = "3" [[floor_divide_tests]] a = "3" b = "10" -expected = "0" description = "Division results in zero (smaller // larger): 3 // 10" +expected = "0" [[floor_divide_tests]] a = "42" b = "1" -expected = "42" description = "Division by 1: 42 // 1" +expected = "42" [[floor_divide_tests]] a = "1000000000000" b = "1000000" -expected = "1000000" description = "Large number division: 1000000000000 // 1000000" +expected = "1000000" # ===----------------------------------------------------------------------=== # # Basic floor division with negative numbers @@ -49,32 +49,32 @@ description = "Large number division: 1000000000000 // 1000000" [[floor_divide_tests]] a = "-10" b = "2" -expected = "-5" description = "Negative dividend, positive divisor: -10 // 2" +expected = "-5" [[floor_divide_tests]] a = "-10" b = "-2" -expected = "5" description = "Negative dividend, negative divisor: -10 // -2" +expected = "5" [[floor_divide_tests]] a = "10" b = "-2" -expected = "-5" description = "Positive dividend, negative divisor: 10 // -2" +expected = "-5" [[floor_divide_tests]] a = "-7" b = "3" -expected = "-3" description = "Negative dividend with remainder (floor division special case): -7 // 3" +expected = "-3" [[floor_divide_tests]] a = "-5" b = "2" -expected = "-3" description = "Key test for floor division (negative numbers): -5 // 2" +expected = "-3" # ===----------------------------------------------------------------------=== # # Mixed sign floor division @@ -82,32 +82,32 @@ description = "Key test for floor division (negative numbers): -5 // 2" [[floor_divide_tests]] a = "-6" b = "3" -expected = "-2" description = "Negative // positive with exact division: -6 // 3" +expected = "-2" [[floor_divide_tests]] a = "-6" b = "-3" -expected = "2" description = "Negative // negative with exact division: -6 // -3" +expected = "2" [[floor_divide_tests]] a = "6" b = "-3" -expected = "-2" description = "Positive // negative with exact division: 6 // -3" +expected = "-2" [[floor_divide_tests]] a = "-7" b = "4" -expected = "-2" description = "Negative // positive with remainder (critical floor division case): -7 // 4" +expected = "-2" [[floor_divide_tests]] a = "7" b = "-4" -expected = "-2" description = "Positive // negative with remainder (critical floor division case): 7 // -4" +expected = "-2" # ===----------------------------------------------------------------------=== # # Zero handling cases @@ -115,14 +115,14 @@ description = "Positive // negative with remainder (critical floor division case [[floor_divide_tests]] a = "0" b = "5" -expected = "0" description = "Zero dividend, positive divisor: 0 // 5" +expected = "0" [[floor_divide_tests]] a = "0" b = "-5" -expected = "0" description = "Zero dividend, negative divisor: 0 // -5" +expected = "0" # Note: Division by zero cases are handled as exceptions in the test code @@ -132,50 +132,50 @@ description = "Zero dividend, negative divisor: 0 // -5" [[floor_divide_tests]] a = "100000000000000000000000000000000000000000000000000" b = "7" -expected = "14285714285714285714285714285714285714285714285714" description = "Large positive number divided by small number: 10^50 // 7" +expected = "14285714285714285714285714285714285714285714285714" [[floor_divide_tests]] a = "-100000000000000000000000000000000000000000000000000" b = "7" -expected = "-14285714285714285714285714285714285714285714285715" description = "Large negative number divided by small number: -10^50 // 7" +expected = "-14285714285714285714285714285714285714285714285715" [[floor_divide_tests]] a = "100000000000000000000000000000000000000000000000000" b = "-7" -expected = "-14285714285714285714285714285714285714285714285715" description = "Large positive // small negative: 10^50 // -7" +expected = "-14285714285714285714285714285714285714285714285715" [[floor_divide_tests]] a = "-100000000000000000000000000000000000000000000000000" b = "-7" -expected = "14285714285714285714285714285714285714285714285714" description = "Large negative // small negative: -10^50 // -7" +expected = "14285714285714285714285714285714285714285714285714" [[floor_divide_tests]] a = "999999999999999999999999999999" b = "999999999999999" -expected = "1000000000000001" description = "Large // large (same sign): 30 nines // 15 nines" +expected = "1000000000000001" [[floor_divide_tests]] a = "999999999999999999999999999999" b = "-999999999999999" -expected = "-1000000000000001" description = "Large // large (opposite sign): 30 nines // -15 nines" +expected = "-1000000000000001" [[floor_divide_tests]] a = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" b = "1000000000000000000000000000000000000000000" -expected = "10000000000000000000000000000000000000000000000000000000000" description = "Power of 10 division: 10^100 // 10^40" +expected = "10000000000000000000000000000000000000000000000000000000000" [[floor_divide_tests]] a = "-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" b = "1000000000000000000000000000000000000000000" -expected = "-10000000000000000000000000000000000000000000000000000000000" description = "Negative power of 10 division: -10^100 // 10^40" +expected = "-10000000000000000000000000000000000000000000000000000000000" # ===----------------------------------------------------------------------=== # # Floor division rounding behavior @@ -183,62 +183,62 @@ description = "Negative power of 10 division: -10^100 // 10^40" [[floor_divide_tests]] a = "7" b = "2" -expected = "3" description = "Positive // positive with remainder: 7 // 2" +expected = "3" [[floor_divide_tests]] a = "-7" b = "2" -expected = "-4" description = "Negative // positive with remainder (key floor division case): -7 // 2" +expected = "-4" [[floor_divide_tests]] a = "7" b = "-2" -expected = "-4" description = "Positive // negative with remainder (key floor division case): 7 // -2" +expected = "-4" [[floor_divide_tests]] a = "-7" b = "-2" -expected = "3" description = "Negative // negative with remainder: -7 // -2" +expected = "3" [[floor_divide_tests]] a = "1" b = "4" -expected = "0" description = "Small dividend // large divisor: 1 // 4" +expected = "0" [[floor_divide_tests]] a = "-1" b = "4" -expected = "-1" description = "Negative small // positive large: -1 // 4" +expected = "-1" [[floor_divide_tests]] a = "-9" b = "5" -expected = "-2" description = "Borderline case: -9 // 5" +expected = "-2" [[floor_divide_tests]] a = "9" b = "-5" -expected = "-2" description = "Another borderline case: 9 // -5" +expected = "-2" [[floor_divide_tests]] a = "-1" b = "3" -expected = "-1" description = "Close to zero negative: -1 // 3" +expected = "-1" [[floor_divide_tests]] a = "1" b = "-3" -expected = "-1" description = "Close to zero positive with negative divisor: 1 // -3" +expected = "-1" # ===----------------------------------------------------------------------=== # # Mathematical identity verification cases @@ -246,32 +246,32 @@ description = "Close to zero positive with negative divisor: 1 // -3" [[floor_divide_tests]] a = "17" b = "5" -expected = "3" description = "Identity test: positive dividend, positive divisor: 17 // 5" +expected = "3" [[floor_divide_tests]] a = "-17" b = "5" -expected = "-4" description = "Identity test: negative dividend, positive divisor: -17 // 5" +expected = "-4" [[floor_divide_tests]] a = "17" b = "-5" -expected = "-4" description = "Identity test: positive dividend, negative divisor: 17 // -5" +expected = "-4" [[floor_divide_tests]] a = "-17" b = "-5" -expected = "3" description = "Identity test: negative dividend, negative divisor: -17 // -5" +expected = "3" [[floor_divide_tests]] a = "12345678901234567890" b = "987654321" -expected = "12499999887" description = "Identity test with large numbers: 12345678901234567890 // 987654321" +expected = "12499999887" # ===----------------------------------------------------------------------=== # # Edge cases @@ -279,71 +279,71 @@ description = "Identity test with large numbers: 12345678901234567890 // 9876543 [[floor_divide_tests]] a = "1000" b = "999" -expected = "1" description = "Maximum divisor (just below dividend): 1000 // 999" +expected = "1" [[floor_divide_tests]] a = "1000" b = "-999" -expected = "-2" description = "Maximum negative divisor: 1000 // -999" +expected = "-2" [[floor_divide_tests]] a = "101" b = "100" -expected = "1" description = "Consecutive numbers (positive): 101 // 100" +expected = "1" [[floor_divide_tests]] a = "-101" b = "100" -expected = "-2" description = "Consecutive numbers (negative): -101 // 100" +expected = "-2" [[floor_divide_tests]] a = "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" b = "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" -expected = "1" description = "Equal large positive numbers: 100 nines // 100 nines" +expected = "1" [[floor_divide_tests]] a = "-999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" b = "-999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" -expected = "1" description = "Equal large negative numbers: -100 nines // -100 nines" +expected = "1" [[floor_divide_tests]] a = "10000000001" b = "10000000000" -expected = "1" description = "Very small remainder (positive numbers): 10000000001 // 10000000000" +expected = "1" [[floor_divide_tests]] a = "-10000000001" b = "10000000000" -expected = "-2" description = "Very small remainder (negative dividend): -10000000001 // 10000000000" +expected = "-2" [[floor_divide_tests]] a = "123" b = "45" -expected = "2" description = "Integer constructor test: 123 // 45" +expected = "2" [[floor_divide_tests]] a = "128" b = "2" -expected = "64" description = "Power of 2 divisions (positive): 128 // 2" +expected = "64" [[floor_divide_tests]] a = "-128" b = "2" -expected = "-64" description = "Power of 2 divisions (negative dividend): -128 // 2" +expected = "-64" [[floor_divide_tests]] a = "1000" b = "10" -expected = "100" description = "Power of 10 divisions: 1000 // 10" +expected = "100" diff --git a/tests/bigint/test_data/bigint_multiply.toml b/tests/bigint/test_data/bigint_multiply.toml index 06d64a4..9fcedfc 100644 --- a/tests/bigint/test_data/bigint_multiply.toml +++ b/tests/bigint/test_data/bigint_multiply.toml @@ -13,32 +13,32 @@ [[multiplication_tests]] a = "5" b = "3" -expected = "15" description = "Simple integer multiplication: 5 * 3" +expected = "15" [[multiplication_tests]] a = "125" b = "40" -expected = "5000" description = "Multiplication with larger numbers: 125 * 40" +expected = "5000" [[multiplication_tests]] a = "1234" b = "9876" -expected = "12186984" description = "Multiplication with different sized numbers: 1234 * 9876" +expected = "12186984" [[multiplication_tests]] a = "999999" b = "1001" -expected = "1000998999" description = "Larger numbers multiplication: 999999 * 1001" +expected = "1000998999" [[multiplication_tests]] a = "12345" b = "67" -expected = "827115" description = "Multiplication with a two-digit number: 12345 * 67" +expected = "827115" # ===----------------------------------------------------------------------=== # # Special cases (zero, one, negative one) @@ -46,32 +46,32 @@ description = "Multiplication with a two-digit number: 12345 * 67" [[multiplication_tests]] a = "12345" b = "0" -expected = "0" description = "Multiplication by zero: 12345 * 0" +expected = "0" [[multiplication_tests]] a = "12345" b = "1" -expected = "12345" description = "Multiplication by one: 12345 * 1" +expected = "12345" [[multiplication_tests]] a = "0" b = "9876" -expected = "0" description = "Multiplication of zero by any number: 0 * 9876" +expected = "0" [[multiplication_tests]] a = "12345" b = "-1" -expected = "-12345" description = "Multiplication by negative one: 12345 * -1" +expected = "-12345" [[multiplication_tests]] a = "100000000000000000000000000000000000000000000000000" b = "1" -expected = "100000000000000000000000000000000000000000000000000" description = "Multiplication of very large values by one" +expected = "100000000000000000000000000000000000000000000000000" # ===----------------------------------------------------------------------=== # # Negative number multiplication @@ -79,32 +79,32 @@ description = "Multiplication of very large values by one" [[multiplication_tests]] a = "-5" b = "3" -expected = "-15" description = "Negative * positive: -5 * 3" +expected = "-15" [[multiplication_tests]] a = "5" b = "-3" -expected = "-15" description = "Positive * negative: 5 * -3" +expected = "-15" [[multiplication_tests]] a = "-5" b = "-3" -expected = "15" description = "Negative * negative: -5 * -3" +expected = "15" [[multiplication_tests]] a = "-25000" b = "420" -expected = "-10500000" description = "Larger numbers with negative and positive: -25000 * 420" +expected = "-10500000" [[multiplication_tests]] a = "-99999" b = "-99999" -expected = "9999800001" description = "Two large negative numbers: -99999 * -99999" +expected = "9999800001" # ===----------------------------------------------------------------------=== # # Large number multiplication @@ -112,32 +112,32 @@ description = "Two large negative numbers: -99999 * -99999" [[multiplication_tests]] a = "12345678901234567890" b = "98765432109876543210" -expected = "1219326311370217952237463801111263526900" description = "Multiplication of large numbers" +expected = "1219326311370217952237463801111263526900" [[multiplication_tests]] a = "99999999999999999999" b = "99999999999999999999" -expected = "9999999999999999999800000000000000000001" description = "Multiplication resulting in a number with many digits (20 nines * 20 nines)" +expected = "9999999999999999999800000000000000000001" [[multiplication_tests]] a = "12345" b = "100000000000" -expected = "1234500000000000" description = "Multiplication by a power of 10: 12345 * 10^11" +expected = "1234500000000000" [[multiplication_tests]] a = "99999999999999999999999999999999999999999999999999" b = "2" -expected = "199999999999999999999999999999999999999999999999998" description = "Large * small multiplication: 50 nines * 2" +expected = "199999999999999999999999999999999999999999999999998" [[multiplication_tests]] a = "100000000000000000000" b = "1000000000000000000" -expected = "100000000000000000000000000000000000000" description = "Word-crossing multiplication: 10^20 * 10^18" +expected = "100000000000000000000000000000000000000" # ===----------------------------------------------------------------------=== # # Commutative property verification (a*b = b*a) @@ -145,59 +145,59 @@ description = "Word-crossing multiplication: 10^20 * 10^18" [[multiplication_tests]] a = "10" b = "20" -expected = "200" description = "Commutative property test: small integers 10 * 20" +expected = "200" [[multiplication_tests]] a = "20" b = "10" -expected = "200" description = "Commutative property test: small integers 20 * 10" +expected = "200" [[multiplication_tests]] a = "12345678901234567890" b = "42" -expected = "518518513851851851380" description = "Commutative property test: large * small 12345678901234567890 * 42" +expected = "518518513851851851380" [[multiplication_tests]] a = "42" b = "12345678901234567890" -expected = "518518513851851851380" description = "Commutative property test: small * large 42 * 12345678901234567890" +expected = "518518513851851851380" [[multiplication_tests]] a = "-500" b = "700" -expected = "-350000" description = "Commutative property test: negative * positive -500 * 700" +expected = "-350000" [[multiplication_tests]] a = "700" b = "-500" -expected = "-350000" description = "Commutative property test: positive * negative 700 * -500" +expected = "-350000" [[multiplication_tests]] a = "999999999999999" b = "888888888888" -expected = "888888888887999111111111112" description = "Commutative property test: large numbers 15 nines * 12 eights" +expected = "888888888887999111111111112" [[multiplication_tests]] a = "888888888888" b = "999999999999999" -expected = "888888888887999111111111112" description = "Commutative property test: large numbers 12 eights * 15 nines" +expected = "888888888887999111111111112" [[multiplication_tests]] a = "100000000000000000000000000000000000000000000000000" b = "0" -expected = "0" description = "Commutative property test: very large * zero" +expected = "0" [[multiplication_tests]] a = "0" b = "100000000000000000000000000000000000000000000000000" -expected = "0" description = "Commutative property test: zero * very large" +expected = "0" diff --git a/tests/bigint/test_data/bigint_truncate_divide.toml b/tests/bigint/test_data/bigint_truncate_divide.toml index e4df993..0b100e5 100644 --- a/tests/bigint/test_data/bigint_truncate_divide.toml +++ b/tests/bigint/test_data/bigint_truncate_divide.toml @@ -21,32 +21,32 @@ [[truncate_divide_tests]] a = "10" b = "2" -expected = "5" description = "Simple division with no remainder: 10 / 2" +expected = "5" [[truncate_divide_tests]] a = "10" b = "3" -expected = "3" description = "Division with remainder (truncate toward zero): 10 / 3" +expected = "3" [[truncate_divide_tests]] a = "3" b = "10" -expected = "0" description = "Division results in zero (smaller / larger): 3 / 10" +expected = "0" [[truncate_divide_tests]] a = "42" b = "1" -expected = "42" description = "Division by 1: 42 / 1" +expected = "42" [[truncate_divide_tests]] a = "1000000000000" b = "1000000" -expected = "1000000" description = "Large number division: 1000000000000 / 1000000" +expected = "1000000" # ===----------------------------------------------------------------------=== # # Basic truncate division with negative numbers @@ -54,32 +54,32 @@ description = "Large number division: 1000000000000 / 1000000" [[truncate_divide_tests]] a = "-10" b = "2" -expected = "-5" description = "Negative dividend, positive divisor: -10 / 2" +expected = "-5" [[truncate_divide_tests]] a = "-10" b = "-2" -expected = "5" description = "Negative dividend, negative divisor: -10 / -2" +expected = "5" [[truncate_divide_tests]] a = "10" b = "-2" -expected = "-5" description = "Positive dividend, negative divisor: 10 / -2" +expected = "-5" [[truncate_divide_tests]] a = "-7" b = "3" -expected = "-2" description = "Negative dividend with remainder (truncate division case): -7 / 3 = -2.33... → -2" +expected = "-2" [[truncate_divide_tests]] a = "-5" b = "2" -expected = "-2" description = "Key test for truncate division (negative numbers): -5 / 2 = -2.5 → -2" +expected = "-2" # ===----------------------------------------------------------------------=== # # Mixed sign truncate division @@ -87,32 +87,32 @@ description = "Key test for truncate division (negative numbers): -5 / 2 = -2.5 [[truncate_divide_tests]] a = "-6" b = "3" -expected = "-2" description = "Negative / positive with exact division: -6 / 3" +expected = "-2" [[truncate_divide_tests]] a = "-6" b = "-3" -expected = "2" description = "Negative / negative with exact division: -6 / -3" +expected = "2" [[truncate_divide_tests]] a = "6" b = "-3" -expected = "-2" description = "Positive / negative with exact division: 6 / -3" +expected = "-2" [[truncate_divide_tests]] a = "-7" b = "4" -expected = "-1" description = "Negative / positive with remainder (critical truncate case): -7 / 4 = -1.75 → -1" +expected = "-1" [[truncate_divide_tests]] a = "7" b = "-4" -expected = "-1" description = "Positive / negative with remainder (critical truncate case): 7 / -4 = -1.75 → -1" +expected = "-1" # ===----------------------------------------------------------------------=== # # Zero handling cases @@ -120,14 +120,14 @@ description = "Positive / negative with remainder (critical truncate case): 7 / [[truncate_divide_tests]] a = "0" b = "5" -expected = "0" description = "Zero dividend, positive divisor: 0 / 5" +expected = "0" [[truncate_divide_tests]] a = "0" b = "-5" -expected = "0" description = "Zero dividend, negative divisor: 0 / -5" +expected = "0" # Note: Division by zero cases are handled as exceptions in the test code @@ -137,38 +137,38 @@ description = "Zero dividend, negative divisor: 0 / -5" [[truncate_divide_tests]] a = "100000000000000000000000000000000000000000000000000" b = "7" -expected = "14285714285714285714285714285714285714285714285714" description = "Large positive number divided by small number: 10^50 / 7" +expected = "14285714285714285714285714285714285714285714285714" [[truncate_divide_tests]] a = "-100000000000000000000000000000000000000000000000000" b = "7" -expected = "-14285714285714285714285714285714285714285714285714" description = "Large negative number divided by small number: -10^50 / 7" +expected = "-14285714285714285714285714285714285714285714285714" [[truncate_divide_tests]] a = "100000000000000000000000000000000000000000000000000" b = "-7" -expected = "-14285714285714285714285714285714285714285714285714" description = "Large positive / small negative: 10^50 / -7" +expected = "-14285714285714285714285714285714285714285714285714" [[truncate_divide_tests]] a = "-100000000000000000000000000000000000000000000000000" b = "-7" -expected = "14285714285714285714285714285714285714285714285714" description = "Large negative / small negative: -10^50 / -7" +expected = "14285714285714285714285714285714285714285714285714" [[truncate_divide_tests]] a = "999999999999999999999999999999" b = "999999999999999" -expected = "1000000000000001" description = "Large / large (same sign): 30 nines / 15 nines" +expected = "1000000000000001" [[truncate_divide_tests]] a = "999999999999999999999999999999" b = "-999999999999999" -expected = "-1000000000000001" description = "Large / large (opposite sign): 30 nines / -15 nines" +expected = "-1000000000000001" # ===----------------------------------------------------------------------=== # # Truncate division rounding behavior (rounds toward zero) @@ -176,44 +176,44 @@ description = "Large / large (opposite sign): 30 nines / -15 nines" [[truncate_divide_tests]] a = "7" b = "2" -expected = "3" description = "Positive / positive with remainder: 7 / 2 = 3.5 → 3" +expected = "3" [[truncate_divide_tests]] a = "-7" b = "2" -expected = "-3" description = "Negative / positive with remainder (key truncate case): -7 / 2 = -3.5 → -3" +expected = "-3" [[truncate_divide_tests]] a = "7" b = "-2" -expected = "-3" description = "Positive / negative with remainder (key truncate case): 7 / -2 = -3.5 → -3" +expected = "-3" [[truncate_divide_tests]] a = "-7" b = "-2" -expected = "3" description = "Negative / negative with remainder: -7 / -2 = 3.5 → 3" +expected = "3" [[truncate_divide_tests]] a = "1" b = "4" -expected = "0" description = "Small dividend / large divisor: 1 / 4 = 0.25 → 0" +expected = "0" [[truncate_divide_tests]] a = "-1" b = "4" -expected = "0" description = "Negative small / positive large (truncate toward zero): -1 / 4 = -0.25 → 0" +expected = "0" [[truncate_divide_tests]] a = "-9" b = "5" -expected = "-1" description = "Truncate vs floor example: -9 / 5 = -1.8 → -1 (truncate), -2 (floor)" +expected = "-1" # ===----------------------------------------------------------------------=== # # Mathematical identity verification cases @@ -221,32 +221,32 @@ description = "Truncate vs floor example: -9 / 5 = -1.8 → -1 (truncate), -2 (f [[truncate_divide_tests]] a = "17" b = "5" -expected = "3" description = "Identity test: positive dividend, positive divisor: 17 / 5" +expected = "3" [[truncate_divide_tests]] a = "-17" b = "5" -expected = "-3" description = "Identity test: negative dividend, positive divisor: -17 / 5" +expected = "-3" [[truncate_divide_tests]] a = "17" b = "-5" -expected = "-3" description = "Identity test: positive dividend, negative divisor: 17 / -5" +expected = "-3" [[truncate_divide_tests]] a = "-17" b = "-5" -expected = "3" description = "Identity test: negative dividend, negative divisor: -17 / -5" +expected = "3" [[truncate_divide_tests]] a = "12345678901234567890" b = "987654321" -expected = "12499999887" description = "Identity test with large numbers: 12345678901234567890 / 987654321" +expected = "12499999887" # ===----------------------------------------------------------------------=== # # Edge cases @@ -254,50 +254,50 @@ description = "Identity test with large numbers: 12345678901234567890 / 98765432 [[truncate_divide_tests]] a = "1000" b = "999" -expected = "1" description = "Maximum divisor (just below dividend): 1000 / 999" +expected = "1" [[truncate_divide_tests]] a = "1000" b = "-999" -expected = "-1" description = "Maximum negative divisor: 1000 / -999" +expected = "-1" [[truncate_divide_tests]] a = "101" b = "100" -expected = "1" description = "Consecutive numbers (positive): 101 / 100" +expected = "1" [[truncate_divide_tests]] a = "-101" b = "100" -expected = "-1" description = "Consecutive numbers (negative): -101 / 100" +expected = "-1" [[truncate_divide_tests]] a = "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" b = "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" -expected = "1" description = "Equal large positive numbers: 100 nines / 100 nines" +expected = "1" [[truncate_divide_tests]] a = "-999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" b = "-999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" -expected = "1" description = "Equal large negative numbers: -100 nines / -100 nines" +expected = "1" [[truncate_divide_tests]] a = "-23" b = "5" -expected = "-4" description = "Truncate vs floor comparison: -23 / 5 = -4.6 → -4 (truncate), -5 (floor)" +expected = "-4" [[truncate_divide_tests]] a = "100000000000000000000" b = "100000" -expected = "1000000000000000" description = "Powers of 10 division: 10^20 / 10^5" +expected = "1000000000000000" # ===----------------------------------------------------------------------=== # # Python comparison cases (for verification) @@ -305,17 +305,17 @@ description = "Powers of 10 division: 10^20 / 10^5" [[truncate_divide_tests]] a = "42" b = "5" -expected = "8" description = "Python comparison: positive numbers (same as floor division): 42 / 5" +expected = "8" [[truncate_divide_tests]] a = "-42" b = "5" -expected = "-8" description = "Python comparison: negative dividend (differs from floor): -42 / 5 → -8 (truncate), -9 (floor)" +expected = "-8" [[truncate_divide_tests]] a = "999999999999999999999" b = "3" -expected = "333333333333333333333" description = "Python comparison: large positive numbers: 21 nines / 3" +expected = "333333333333333333333" diff --git a/tests/biguint/test_biguint_arithmetics.mojo b/tests/biguint/test_biguint_arithmetics.mojo index 968fed9..edfb667 100644 --- a/tests/biguint/test_biguint_arithmetics.mojo +++ b/tests/biguint/test_biguint_arithmetics.mojo @@ -6,6 +6,7 @@ BigUInt is an unsigned integer type, so it doesn't support negative values. from python import Python from random import random_ui64 +import testing from testing import assert_equal, assert_true from decimojo.biguint.biguint import BigUInt from decimojo.tests import TestCase, parse_file, load_test_cases @@ -19,8 +20,8 @@ fn test_biguint_arithmetics() raises: var toml = parse_file(file_path_arithmetics) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigUInt addition...") + # print("------------------------------------------------------") + # print("Testing BigUInt addition...") test_cases = load_test_cases(toml, "addition_tests") assert_true(len(test_cases) > 0, "No addition test cases found") for test_case in test_cases: @@ -30,10 +31,10 @@ fn test_biguint_arithmetics() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigUInt addition tests passed!") + # print("BigUInt addition tests passed!") - print("------------------------------------------------------") - print("Testing BigUInt inplace addition...") + # print("------------------------------------------------------") + # print("Testing BigUInt inplace addition...") test_cases = load_test_cases(toml, "addition_tests") assert_true(len(test_cases) > 0, "No inplace addition test cases found") for test_case in test_cases: @@ -44,10 +45,10 @@ fn test_biguint_arithmetics() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigUInt addition tests passed!") + # print("BigUInt addition tests passed!") - print("------------------------------------------------------") - print("Testing BigUInt subtraction...") + # print("------------------------------------------------------") + # print("Testing BigUInt subtraction...") test_cases = load_test_cases(toml, "subtraction_tests") assert_true(len(test_cases) > 0, "No subtraction test cases found") for test_case in test_cases: @@ -57,10 +58,10 @@ fn test_biguint_arithmetics() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigUInt subtraction tests passed!") + # print("BigUInt subtraction tests passed!") - print("------------------------------------------------------") - print("Testing BigUInt multiplication...") + # print("------------------------------------------------------") + # print("Testing BigUInt multiplication...") # Load test cases from TOML file test_cases = load_test_cases(toml, "multiplication_tests") @@ -72,10 +73,10 @@ fn test_biguint_arithmetics() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigUInt multiplication tests passed!") + # print("BigUInt multiplication tests passed!") # Special case: Test underflow handling - print("Testing underflow behavior (smaller - larger)...") + # print("Testing underflow behavior (smaller - larger)...") test_cases = load_test_cases(toml, "subtraction_underflow") assert_true(len(test_cases) > 0, "No underflow test cases found") for test_case in test_cases: @@ -86,7 +87,7 @@ fn test_biguint_arithmetics() raises: ) except: print("Implementation correctly throws error on underflow") - print("BigUInt multiplication tests passed!") + # print("BigUInt multiplication tests passed!") fn test_biguint_truncate_divide() raises: @@ -94,8 +95,8 @@ fn test_biguint_truncate_divide() raises: var toml = parse_file(file_path_truncate_divide) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigUInt truncate division...") + # print("------------------------------------------------------") + # print("Testing BigUInt truncate division...") test_cases = load_test_cases(toml, "truncate_divide_tests") assert_true(len(test_cases) > 0, "No truncate division test cases found") for test_case in test_cases: @@ -105,12 +106,12 @@ fn test_biguint_truncate_divide() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigUInt truncate division tests passed!") + # print("BigUInt truncate division tests passed!") fn test_biguint_truncate_divide_random_numbers_against_python() raises: - print("------------------------------------------------------") - print("Testing BigUInt truncate division on random numbers with python...") + # print("------------------------------------------------------") + # print("Testing BigUInt truncate division on random numbers with python...") var pysys = Python.import_module("sys") pysys.set_int_max_str_digits(500000) @@ -140,12 +141,13 @@ fn test_biguint_truncate_divide_random_numbers_against_python() raises: + "\n\nPython int division: \n" + python_result, ) - print("BigUInt truncate division tests passed!") + # print("BigUInt truncate division tests passed!") fn main() raises: - test_biguint_arithmetics() - test_biguint_truncate_divide() - test_biguint_truncate_divide_random_numbers_against_python() - print("All BigUInt arithmetic tests passed!") - print("------------------------------------------------------") + # test_biguint_arithmetics() + # test_biguint_truncate_divide() + # test_biguint_truncate_divide_random_numbers_against_python() + testing.TestSuite.discover_tests[__functions_in_module()]().run() + # print("All BigUInt arithmetic tests passed!") + # print("------------------------------------------------------") diff --git a/tests/biguint/test_biguint_exponential.mojo b/tests/biguint/test_biguint_exponential.mojo index 4a6f198..8c783d8 100644 --- a/tests/biguint/test_biguint_exponential.mojo +++ b/tests/biguint/test_biguint_exponential.mojo @@ -5,6 +5,7 @@ Test BigUInt exponential functions. from python import Python from random import random_ui64 +import testing from testing import assert_equal, assert_true from decimojo.biguint.biguint import BigUInt from decimojo.tests import TestCase, parse_file, load_test_cases @@ -17,8 +18,8 @@ fn test_biguint_sqrt() raises: var toml = parse_file(file_path_sqrt) var test_cases: List[TestCase] - print("------------------------------------------------------") - print("Testing BigUInt sqrt...") + # print("------------------------------------------------------") + # print("Testing BigUInt sqrt...") test_cases = load_test_cases[unary=True](toml, "sqrt_tests") assert_true(len(test_cases) > 0, "No sqrt test cases found") for test_case in test_cases: @@ -28,12 +29,12 @@ fn test_biguint_sqrt() raises: rhs=test_case.expected, msg=test_case.description, ) - print("BigUInt sqrt tests passed!") + # print("BigUInt sqrt tests passed!") fn test_biguint_sqrt_random_numbers_against_python() raises: - print("------------------------------------------------------") - print("Testing BigUInt sqrt on random numbers with python...") + # print("------------------------------------------------------") + # print("Testing BigUInt sqrt on random numbers with python...") var pysys = Python.import_module("sys") var pymath = Python.import_module("math") @@ -58,11 +59,12 @@ fn test_biguint_sqrt_random_numbers_against_python() raises: + "\n\nPython int sqrt: \n" + python_result, ) - print("BigUInt sqrt tests passed!") + # print("BigUInt sqrt tests passed!") fn main() raises: - test_biguint_sqrt() - test_biguint_sqrt_random_numbers_against_python() - print("All BigUInt exponential tests passed!") - print("------------------------------------------------------") + # test_biguint_sqrt() + # test_biguint_sqrt_random_numbers_against_python() + testing.TestSuite.discover_tests[__functions_in_module()]().run() + # print("All BigUInt exponential tests passed!") + # print("------------------------------------------------------") diff --git a/tests/biguint/test_data/biguint_arithmetics.toml b/tests/biguint/test_data/biguint_arithmetics.toml index 5dfaa50..5c38c47 100644 --- a/tests/biguint/test_data/biguint_arithmetics.toml +++ b/tests/biguint/test_data/biguint_arithmetics.toml @@ -13,50 +13,50 @@ [[addition_tests]] a = "123" b = "456" -expected = "579" description = "Simple addition of positive numbers" +expected = "579" [[addition_tests]] a = "123" b = "0" -expected = "123" description = "Addition with zero" +expected = "123" [[addition_tests]] a = "99999999999999999999" b = "1" -expected = "100000000000000000000" description = "Addition with large numbers" +expected = "100000000000000000000" [[addition_tests]] a = "9999999999" b = "1" -expected = "10000000000" description = "Addition causing multiple carries" +expected = "10000000000" [[addition_tests]] a = "12345" b = "9876543210" -expected = "9876555555" description = "Addition with numbers of different sizes" +expected = "9876555555" [[addition_tests]] a = "12345678901234567890123456789" b = "98765432109876543210987654321" -expected = "111111111011111111101111111110" description = "Addition with very large numbers" +expected = "111111111011111111101111111110" [[addition_tests]] a = "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" b = "1" -expected = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" description = "Addition with extensive carry propagation" +expected = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" [[addition_tests]] a = "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" b = "5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" -expected = "1005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" description = "Addition of very large numbers" +expected = "1005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" # ===----------------------------------------------------------------------=== # # Test cases for BigUInt subtraction @@ -64,44 +64,44 @@ description = "Addition of very large numbers" [[subtraction_tests]] a = "456" b = "123" -expected = "333" description = "Simple subtraction" +expected = "333" [[subtraction_tests]] a = "123" b = "0" -expected = "123" description = "Subtraction with zero" +expected = "123" [[subtraction_tests]] a = "123" b = "123" -expected = "0" description = "Subtraction resulting in zero" +expected = "0" [[subtraction_tests]] a = "10000" b = "1" -expected = "9999" description = "Subtraction with borrow" +expected = "9999" [[subtraction_tests]] a = "10000" b = "9999" -expected = "1" description = "Subtraction with multiple borrows" +expected = "1" [[subtraction_tests]] a = "12345678901234567890" b = "12345678901234567890" -expected = "0" description = "Self subtraction should yield zero" +expected = "0" [[extreme_subtraction_tests]] a = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" b = "1" -expected = "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" description = "Very large subtraction within range" +expected = "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" # ===----------------------------------------------------------------------=== # # Special test for subtraction underflow @@ -109,8 +109,8 @@ description = "Very large subtraction within range" [[subtraction_underflow]] a = "123" b = "456" -expected = "" description = "Underflow handling (smaller - larger)" +expected = "" # ===----------------------------------------------------------------------=== # # Test cases for BigUInt multiplication @@ -118,35 +118,35 @@ description = "Underflow handling (smaller - larger)" [[multiplication_tests]] a = "123" b = "456" -expected = "56088" description = "Simple multiplication" +expected = "56088" [[multiplication_tests]] a = "123456789" b = "0" -expected = "0" description = "Multiplication by zero" +expected = "0" [[multiplication_tests]] a = "123456789" b = "1" -expected = "123456789" description = "Multiplication by one" +expected = "123456789" [[multiplication_tests]] a = "12345" b = "67890" -expected = "838102050" description = "Multiplication of large numbers" +expected = "838102050" [[multiplication_tests]] a = "9999999999" b = "9999999999" -expected = "99999999980000000001" description = "Multiplication of very large numbers" +expected = "99999999980000000001" [[multiplication_tests]] a = "10000000000" b = "10000000000" -expected = "100000000000000000000" description = "Very large multiplication" +expected = "100000000000000000000" diff --git a/tests/biguint/test_data/biguint_sqrt.toml b/tests/biguint/test_data/biguint_sqrt.toml index 0148d0c..2ea7d4f 100644 --- a/tests/biguint/test_data/biguint_sqrt.toml +++ b/tests/biguint/test_data/biguint_sqrt.toml @@ -4,60 +4,60 @@ [[sqrt_tests]] a = "0" -expected = "0" description = "sqrt(0) = 0" +expected = "0" [[sqrt_tests]] a = "1" -expected = "1" description = "sqrt(1) = 1" +expected = "1" [[sqrt_tests]] a = "2" -expected = "1" description = "sqrt(2) = 1.414... → 1 (truncated)" +expected = "1" [[sqrt_tests]] a = "3" -expected = "1" description = "sqrt(3) = 1.732... → 1 (truncated)" +expected = "1" [[sqrt_tests]] a = "4" -expected = "2" description = "sqrt(4) = 2" +expected = "2" [[sqrt_tests]] a = "9" +description = "sqrt(9) = 3" expected = "3" -description = "sqrt(9) = 3" [[sqrt_tests]] a = "123" -expected = "11" description = "sqrt(123) = 11.090... → 11 (truncated)" +expected = "11" [[sqrt_tests]] a = "1000" -expected = "31" description = "sqrt(1000) = 31.622... → 31 (truncated)" +expected = "31" [[sqrt_tests]] a = "10000" -expected = "100" description = "sqrt(10000) = 100" +expected = "100" [[sqrt_tests]] a = "12345678901234567890" -expected = "3513641828" description = "sqrt(12345678901234567890) = 3513641828.820... → 3513641828 (truncated)" +expected = "3513641828" [[sqrt_tests]] a = "2134046123987508516283704689065901286490832650912368523046783496512308974908123650912364982165901236489037589016230894363274653012643028560123467389065012389640" -expected = "46195737075919770589653035762589470420235915593494302749617514351576404175199142" description = "Large number square root" +expected = "46195737075919770589653035762589470420235915593494302749617514351576404175199142" [[sqrt_tests]] a = "1440000000000000000000000000000000000000000" +description = "Square root of a large perfect square" expected = "1200000000000000000000" -description = "Square root of a large perfect square" \ No newline at end of file diff --git a/tests/biguint/test_data/biguint_truncate_divide.toml b/tests/biguint/test_data/biguint_truncate_divide.toml index 7ff3acc..070ea14 100644 --- a/tests/biguint/test_data/biguint_truncate_divide.toml +++ b/tests/biguint/test_data/biguint_truncate_divide.toml @@ -4,38 +4,38 @@ [[truncate_divide_tests]] a = "10" b = "2" -expected = "5" description = "Division with no remainder" +expected = "5" [[truncate_divide_tests]] a = "10" b = "3" -expected = "3" description = "Division with remainder (truncate toward zero)" +expected = "3" [[truncate_divide_tests]] a = "3" b = "10" -expected = "0" description = "Division results in zero (smaller / larger)" +expected = "0" [[truncate_divide_tests]] a = "42" b = "1" -expected = "42" description = "Division by 1" +expected = "42" [[truncate_divide_tests]] a = "1000000000000" b = "1000000" -expected = "1000000" description = "Large number division" +expected = "1000000" [[truncate_divide_tests]] a = "0" b = "5" -expected = "0" description = "Zero dividend" +expected = "0" # ===----------------------------------------------------------------------=== # # Large number division tests @@ -43,32 +43,32 @@ description = "Zero dividend" [[truncate_divide_tests]] a = "10000000000000000000000000000000000000000000000000000" b = "7" -expected = "1428571428571428571428571428571428571428571428571428" description = "Large number divided by small number" +expected = "1428571428571428571428571428571428571428571428571428" [[truncate_divide_tests]] a = "999999999999999999999999999999" b = "999999999999999" -expected = "1000000000000001" description = "Large number divided by large number" +expected = "1000000000000001" [[truncate_divide_tests]] a = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" b = "10000000000000000000000000000000000000000000" -expected = "1000000000000000000000000000000000000000000000000000000000" description = "Very large number divisible by power of 10" +expected = "1000000000000000000000000000000000000000000000000000000000" [[truncate_divide_tests]] a = "999999999999999999999999999999999999999999999999999999" b = "334999999999999999999999999999999999999994" -expected = "2985074626865" description = "Large number with large divisor resulting in small quotient" +expected = "2985074626865" [[truncate_divide_tests]] a = "123456789123456789123456789123456789123456789123456789123456789123456789123456789" b = "987654321987654321987654321987654321" -expected = "124999998860937500014238281249822021609377223" description = "Large number with very large divisor" +expected = "124999998860937500014238281249822021609377223" # ===----------------------------------------------------------------------=== # # Division rounding tests @@ -76,38 +76,38 @@ description = "Large number with very large divisor" [[truncate_divide_tests]] a = "7" b = "2" -expected = "3" description = "7/2 = 3.5 -> 3" +expected = "3" [[truncate_divide_tests]] a = "1" b = "3" -expected = "0" description = "1/3 = 0.333... -> 0" +expected = "0" [[truncate_divide_tests]] a = "5" b = "4" +description = "5/4 = 1.25 -> 1" expected = "1" -description = "5/4 = 1.25 -> 1" [[truncate_divide_tests]] a = "99" b = "100" -expected = "0" description = "99/100 = 0.99 -> 0" +expected = "0" [[truncate_divide_tests]] a = "17" b = "5" -expected = "3" description = "17/5 = 3.4 -> 3" +expected = "3" [[truncate_divide_tests]] a = "12345678901234567890" b = "987654321" -expected = "12499999887" description = "12345678901234567890/987654321 = 12499999887.34375 -> 12499999887" +expected = "12499999887" # ===----------------------------------------------------------------------=== # # Edge cases @@ -116,29 +116,29 @@ description = "12345678901234567890/987654321 = 12499999887.34375 -> 12499999887 [[truncate_divide_tests]] a = "1000" b = "999" -expected = "1" description = "Consecutive numbers" +expected = "1" [[truncate_divide_tests]] a = "101" b = "100" -expected = "1" description = "Consecutive numbers" +expected = "1" [[truncate_divide_tests]] a = "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" b = "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" -expected = "1" description = "Equal large numbers" +expected = "1" [[truncate_divide_tests]] a = "100000000000000000000" b = "10000000000" -expected = "10000000000" description = "Powers of 10" +expected = "10000000000" [[truncate_divide_tests]] a = "20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" b = "2" -expected = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" description = "Division resulting in large quotient" +expected = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" diff --git a/tests/decimal128/test_decimal128_arithmetics.mojo b/tests/decimal128/test_decimal128_arithmetics.mojo index 3d23d17..cbd09f2 100644 --- a/tests/decimal128/test_decimal128_arithmetics.mojo +++ b/tests/decimal128/test_decimal128_arithmetics.mojo @@ -7,8 +7,8 @@ import testing fn test_add() raises: - print("------------------------------------------------------") - print("Testing decimal addition...") + # print("------------------------------------------------------") + # print("Testing decimal addition...") # Test case 1: Simple addition with same scale var a1 = Decimal128(12345, scale=2) # 123.45 @@ -167,7 +167,7 @@ fn test_add() raises: "Addition with large and small values", ) - print("Decimal128 addition tests passed!") + # print("Decimal128 addition tests passed!") # Test case 18: Edge case with one equals 0 var a18 = Decimal128.from_uint128( @@ -182,12 +182,12 @@ fn test_add() raises: "Addition with zeros", ) - print("Decimal128 addition tests passed!") + # print("Decimal128 addition tests passed!") fn test_negation() raises: - print("------------------------------------------------------") - print("Testing decimal negation...") + # print("------------------------------------------------------") + # print("Testing decimal negation...") # Test case 1: Negate positive number var a1 = Decimal128(12345, 2) @@ -259,12 +259,12 @@ fn test_negation() raises: "Negating number with maximum precision", ) - print("Decimal128 negation tests passed!") + # print("Decimal128 negation tests passed!") fn test_abs() raises: - print("------------------------------------------------------") - print("Testing decimal absolute value...") + # print("------------------------------------------------------") + # print("Testing decimal absolute value...") # Test case 1: Absolute value of positive number var a1 = Decimal128(12345, 2) @@ -343,12 +343,12 @@ fn test_abs() raises: except: print("Maximum value test not applicable") - print("Decimal128 absolute value tests passed!") + # print("Decimal128 absolute value tests passed!") fn test_subtract() raises: - print("------------------------------------------------------") - print("Testing decimal subtraction...") + # print("------------------------------------------------------") + # print("Testing decimal subtraction...") # Test case 1: Simple subtraction with same scale var a1 = Decimal128(12345, 2) @@ -476,12 +476,12 @@ fn test_subtract() raises: String(result12a), String(result12b), "a - b should equal -(b - a)" ) - print("Decimal128 subtraction tests passed!") + # print("Decimal128 subtraction tests passed!") fn test_extreme_cases() raises: - print("------------------------------------------------------") - print("Testing extreme cases...") + # print("------------------------------------------------------") + # print("Testing extreme cases...") # Test case 1: Addition that results in exactly zero with high precision var a1 = Decimal128("0." + "1" * 28) # 0.1111...1 (28 digits) @@ -529,25 +529,27 @@ fn test_extreme_cases() raises: "Addition with extensive carry propagation", ) - print("Extreme case tests passed!") + # print("Extreme case tests passed!") fn main() raises: - print("Running decimal arithmetic tests") + # print("Running decimal arithmetic tests") - # Run addition tests - test_add() + # # Run addition tests + # test_add() - # Run negation tests - test_negation() + # # Run negation tests + # test_negation() - # Run absolute value tests - test_abs() + # # Run absolute value tests + # test_abs() - # Run subtraction tests - test_subtract() + # # Run subtraction tests + # test_subtract() - # Run extreme cases tests - test_extreme_cases() + # # Run extreme cases tests + # test_extreme_cases() - print("All decimal arithmetic tests passed!") + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All decimal arithmetic tests passed!") diff --git a/tests/decimal128/test_decimal128_comparison.mojo b/tests/decimal128/test_decimal128_comparison.mojo index f51c484..4617424 100644 --- a/tests/decimal128/test_decimal128_comparison.mojo +++ b/tests/decimal128/test_decimal128_comparison.mojo @@ -15,8 +15,8 @@ import testing fn test_equality() raises: - print("------------------------------------------------------") - print("Testing decimal equality...") + # print("------------------------------------------------------") + # print("Testing decimal equality...") # Test case 1: Equal decimals var a1 = Decimal128(12345, 2) @@ -57,12 +57,12 @@ fn test_equality() raises: "Same absolute value but different signs should not be equal", ) - print("Equality tests passed!") + # print("Equality tests passed!") fn test_inequality() raises: - print("------------------------------------------------------") - print("Testing decimal inequality...") + # print("------------------------------------------------------") + # print("Testing decimal inequality...") # Test case 1: Equal decimals var a1 = Decimal128(12345, 2) @@ -94,11 +94,11 @@ fn test_inequality() raises: "Same absolute value but different signs should be unequal", ) - print("Inequality tests passed!") + # print("Inequality tests passed!") fn test_greater() raises: - print("Testing greater than comparison...") + # print("Testing greater than comparison...") # Test case 1: Larger decimal var a1 = Decimal128(12346, 2) @@ -149,11 +149,11 @@ fn test_greater() raises: var b7 = Decimal128(12345, 2) testing.assert_true(greater(a7, b7), "123.5 should be greater than 123.45") - print("Greater than tests passed!") + # print("Greater than tests passed!") fn test_greater_equal() raises: - print("Testing greater than or equal comparison...") + # print("Testing greater than or equal comparison...") # Test case 1: Larger decimal var a1 = Decimal128("123.46") @@ -194,11 +194,11 @@ fn test_greater_equal() raises: "123.45 should not be greater than or equal to 123.46", ) - print("Greater than or equal tests passed!") + # print("Greater than or equal tests passed!") fn test_less() raises: - print("Testing less than comparison...") + # print("Testing less than comparison...") # Test case 1: Smaller decimal var a1 = Decimal128(12345, 2) @@ -225,11 +225,11 @@ fn test_less() raises: var b5 = Decimal128(12345, 2) testing.assert_true(less(a5, b5), "Zero should be less than positive") - print("Less than tests passed!") + # print("Less than tests passed!") fn test_less_equal() raises: - print("Testing less than or equal comparison...") + # print("Testing less than or equal comparison...") # Test case 1: Smaller decimal var a1 = Decimal128(12345, 2) @@ -267,11 +267,11 @@ fn test_less_equal() raises: less_equal(a5, b5), "123.46 should not be less than or equal to 123.45" ) - print("Less than or equal tests passed!") + # print("Less than or equal tests passed!") fn test_zero_comparison() raises: - print("Testing zero comparison cases...") + # print("Testing zero comparison cases...") var zero = Decimal128(0) var pos = Decimal128("0.0000000000000000001") # Very small positive @@ -346,11 +346,11 @@ fn test_zero_comparison() raises: less_equal(zero, neg_zero), "Zero should be <= negative zero" ) - print("Zero comparison cases passed!") + # print("Zero comparison cases passed!") fn test_edge_cases() raises: - print("Testing comparison edge cases...") + # print("Testing comparison edge cases...") # Test case 1: Very close values var a1 = Decimal128("1.000000000000000000000000001") @@ -388,11 +388,11 @@ fn test_edge_cases() raises: greater(pos_large, neg_large), "1000 > -1000 (transitivity)" ) - print("Edge case tests passed!") + # print("Edge case tests passed!") fn test_exact_comparison() raises: - print("Testing exact comparison with precision handling...") + # print("Testing exact comparison with precision handling...") # Test case 1: Scale handling with zeros var zero1 = Decimal128(0) @@ -419,11 +419,11 @@ fn test_exact_comparison() raises: testing.assert_false(equal(e1, e2), "1.2 != 1.20000001") testing.assert_true(less(e1, e2), "1.2 < 1.20000001") - print("Exact comparison tests passed!") + # print("Exact comparison tests passed!") fn test_comparison_operators() raises: - print("Testing comparison operators...") + # print("Testing comparison operators...") # Create test values var a = Decimal128(12345, 2) @@ -498,28 +498,30 @@ fn test_comparison_operators() raises: f != g, "f != g: Zero and negative zero should not be unequal" ) - print("Comparison operator tests passed!") + # print("Comparison operator tests passed!") fn main() raises: - print("Running decimal logic tests") + # print("Running decimal logic tests") - # Basic equality tests - test_equality() - test_inequality() + # # Basic equality tests + # test_equality() + # test_inequality() - # Comparison tests - test_greater() - test_greater_equal() - test_less() - test_less_equal() + # # Comparison tests + # test_greater() + # test_greater_equal() + # test_less() + # test_less_equal() - # Zero handling and edge cases - test_zero_comparison() - test_edge_cases() - test_exact_comparison() + # # Zero handling and edge cases + # test_zero_comparison() + # test_edge_cases() + # test_exact_comparison() - # Test operator overloads - test_comparison_operators() + # # Test operator overloads + # test_comparison_operators() - print("All decimal logic tests passed!") + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All decimal logic tests passed!") diff --git a/tests/decimal128/test_decimal128_divide.mojo b/tests/decimal128/test_decimal128_divide.mojo index 1b2c571..8d9f255 100644 --- a/tests/decimal128/test_decimal128_divide.mojo +++ b/tests/decimal128/test_decimal128_divide.mojo @@ -8,8 +8,8 @@ import testing fn test_basic_division() raises: - print("------------------------------------------------------") - print("Testing basic division cases...") + # print("------------------------------------------------------") + # print("Testing basic division cases...") # 1. Simple integer division testing.assert_equal( @@ -77,12 +77,12 @@ fn test_basic_division() raises: "Division with decimals, different scales", ) - print("✓ Basic division tests passed!") + # print("✓ Basic division tests passed!") fn test_repeating_decimals() raises: - print("------------------------------------------------------") - print("Testing division with repeating decimals...") + # print("------------------------------------------------------") + # print("Testing division with repeating decimals...") # 11. Division resulting in 1/3 var third = Decimal128(1) / Decimal128(3) @@ -154,12 +154,12 @@ fn test_repeating_decimals() raises: "Case 20: Division of 10 by 3 failed", ) - print("✓ Repeating decimal tests passed!") + # print("✓ Repeating decimal tests passed!") fn test_precision_rounding() raises: - print("------------------------------------------------------") - print("Testing division precision and rounding...") + # print("------------------------------------------------------") + # print("Testing division precision and rounding...") # 21. Rounding half even (banker's rounding) at precision limit var a21 = Decimal128(2) / Decimal128(3) # Should be ~0.6666...67 @@ -233,12 +233,12 @@ fn test_precision_rounding() raises: "Scale should not exceed MAX_SCALE", ) - print("✓ Precision and rounding tests passed!") + # print("✓ Precision and rounding tests passed!") fn test_scale_handling() raises: - print("------------------------------------------------------") - print("Testing scale handling in division...") + # print("------------------------------------------------------") + # print("Testing scale handling in division...") # 31. Division by power of 10 testing.assert_equal( @@ -310,12 +310,12 @@ fn test_scale_handling() raises: "Division where both have high scale and result needs more", ) - print("✓ Scale handling tests passed!") + # print("✓ Scale handling tests passed!") fn test_edge_cases() raises: - print("------------------------------------------------------") - print("Testing division edge cases...") + # print("------------------------------------------------------") + # print("Testing division edge cases...") # 41. Division by very small number close to zero var a41 = Decimal128(1) / Decimal128( @@ -392,12 +392,12 @@ fn test_edge_cases() raises: "Case 50: Division with value at maximum supported scale failed", ) - print("✓ Edge case tests passed!") + # print("✓ Edge case tests passed!") fn test_large_numbers() raises: - print("------------------------------------------------------") - print("Testing division with large numbers...") + # print("------------------------------------------------------") + # print("Testing division with large numbers...") # 51. Division of large number that results in small number testing.assert_equal( @@ -474,11 +474,11 @@ fn test_large_numbers() raises: except: print("Division overflows") - print("✓ Large number division tests passed!") + # print("✓ Large number division tests passed!") fn test_special_cases() raises: - print("Testing special division cases...") + # print("Testing special division cases...") # 61. Identical numbers should give 1 testing.assert_equal( @@ -554,11 +554,11 @@ fn test_special_cases() raises: "Case 70: Dividing number very close to zero by one failed", ) - print("✓ Special case tests passed!") + # print("✓ Special case tests passed!") fn test_mixed_precision() raises: - print("Testing mixed precision division cases...") + # print("Testing mixed precision division cases...") # 71. High precision / low precision testing.assert_equal( @@ -638,12 +638,12 @@ fn test_mixed_precision() raises: "Many trailing zeros in result", ) - print("✓ Mixed precision tests passed!") + # print("✓ Mixed precision tests passed!") fn test_rounding_behavior() raises: - print("------------------------------------------------------") - print("Testing division rounding behavior...") + # print("------------------------------------------------------") + # print("Testing division rounding behavior...") # 81. Banker's rounding at boundary (round to even) var a81 = Decimal128(1) / Decimal128( @@ -730,12 +730,12 @@ fn test_rounding_behavior() raises: "Case 90: Division with exactly MAX_SCALE digits failed", ) - print("✓ Rounding behavior tests passed!") + # print("✓ Rounding behavior tests passed!") fn test_error_cases() raises: - print("------------------------------------------------------") - print("Testing division error cases...") + # print("------------------------------------------------------") + # print("Testing division error cases...") # 91. Division by zero try: @@ -823,41 +823,42 @@ fn test_error_cases() raises: "Case 100: Division at the exact boundary of precision limit failed", ) - print("✓ Error case tests passed!") + # print("✓ Error case tests passed!") fn main() raises: - print("\n=== Running Comprehensive Decimal128 Division Tests ===\n") + # print("\n=== Running Comprehensive Decimal128 Division Tests ===\n") - # Run all test groups - test_basic_division() - print() + # test_basic_division() + # print() - test_repeating_decimals() - print() + # test_repeating_decimals() + # print() - test_precision_rounding() - print() + # test_precision_rounding() + # print() - test_scale_handling() - print() + # test_scale_handling() + # print() - test_edge_cases() - print() + # test_edge_cases() + # print() - test_large_numbers() - print() + # test_large_numbers() + # print() - test_special_cases() - print() + # test_special_cases() + # print() - test_mixed_precision() - print() + # test_mixed_precision() + # print() - test_rounding_behavior() - print() + # test_rounding_behavior() + # print() - test_error_cases() - print() + # test_error_cases() + # print() - print("✓✓✓ All 100 division tests passed! ✓✓✓") + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("✓✓✓ All 100 division tests passed! ✓✓✓") diff --git a/tests/decimal128/test_decimal128_exp.mojo b/tests/decimal128/test_decimal128_exp.mojo index 3e65ec3..8d45dda 100644 --- a/tests/decimal128/test_decimal128_exp.mojo +++ b/tests/decimal128/test_decimal128_exp.mojo @@ -11,7 +11,7 @@ from decimojo.decimal128.exponential import exp fn test_basic_exp_values() raises: """Test basic exponential function values.""" - print("Testing basic exponential values...") + # print("Testing basic exponential values...") # Test case 1: e^0 = 1 var zero = Decimal128(String("0")) @@ -76,12 +76,12 @@ fn test_basic_exp_values() raises: + String(result5), ) - print("✓ Basic exponential values tests passed!") + # print("✓ Basic exponential values tests passed!") fn test_negative_exponents() raises: """Test exponential function with negative exponents.""" - print("Testing exponential function with negative exponents...") + # print("Testing exponential function with negative exponents...") # Test case 1: e^(-1) = 1/e var neg_one = Decimal128(String("-1")) @@ -125,12 +125,12 @@ fn test_negative_exponents() raises: + String(result3), ) - print("✓ Negative exponents tests passed!") + # print("✓ Negative exponents tests passed!") fn test_fractional_exponents() raises: """Test exponential function with fractional exponents.""" - print("Testing exponential function with fractional exponents...") + # print("Testing exponential function with fractional exponents...") # Test case 1: e^0.5 var half = Decimal128(String("0.5")) @@ -188,12 +188,12 @@ fn test_fractional_exponents() raises: + String(result4), ) - print("✓ Fractional exponents tests passed!") + # print("✓ Fractional exponents tests passed!") fn test_high_precision_exponents() raises: """Test exponential function with high precision inputs.""" - print("Testing exponential function with high precision inputs...") + # print("Testing exponential function with high precision inputs...") # Test case 1: e^π (approximate) var pi = Decimal128(String("3.14159265358979323846264338327950288")) @@ -223,12 +223,12 @@ fn test_high_precision_exponents() raises: + String(result2), ) - print("✓ High precision exponents tests passed!") + # print("✓ High precision exponents tests passed!") fn test_mathematical_identities() raises: """Test mathematical identities related to the exponential function.""" - print("Testing mathematical identities for exponential function...") + # print("Testing mathematical identities for exponential function...") # Test case 1: e^(a+b) = e^a * e^b var a = Decimal128(String("2")) @@ -264,12 +264,12 @@ fn test_mathematical_identities() raises: var exp_zero = exp(zero) testing.assert_equal(String(exp_zero), String("1"), "e^0 should equal 1") - print("✓ Mathematical identities tests passed!") + # print("✓ Mathematical identities tests passed!") fn test_extreme_values() raises: """Test exponential function with extreme values.""" - print("Testing exponential function with extreme values...") + # print("Testing exponential function with extreme values...") # Test case 1: Very small positive input var small_input = Decimal128(String("0.0000001")) @@ -299,12 +299,12 @@ fn test_extreme_values() raises: + String(result3), ) - print("✓ Extreme values tests passed!") + # print("✓ Extreme values tests passed!") fn test_edge_cases() raises: """Test edge cases for exponential function.""" - print("Testing edge cases for exponential function...") + # print("Testing edge cases for exponential function...") # Test with very high precision input var high_precision = Decimal128(String("1.23456789012345678901234567")) @@ -314,7 +314,7 @@ fn test_edge_cases() raises: "Exp with high precision input should produce high precision output", ) - print("✓ Edge cases tests passed!") + # print("✓ Edge cases tests passed!") fn run_test_with_error_handling( @@ -335,26 +335,28 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running Exponential Function Tests") - print("=========================================") - - run_test_with_error_handling( - test_basic_exp_values, "Basic exponential values test" - ) - run_test_with_error_handling( - test_negative_exponents, "Negative exponents test" - ) - run_test_with_error_handling( - test_fractional_exponents, "Fractional exponents test" - ) - run_test_with_error_handling( - test_high_precision_exponents, "High precision exponents test" - ) - run_test_with_error_handling( - test_mathematical_identities, "Mathematical identities test" - ) - run_test_with_error_handling(test_extreme_values, "Extreme values test") - run_test_with_error_handling(test_edge_cases, "Edge cases test") - - print("All exponential function tests passed!") + # print("=========================================") + # print("Running Exponential Function Tests") + # print("=========================================") + + # run_test_with_error_handling( + # test_basic_exp_values, "Basic exponential values test" + # ) + # run_test_with_error_handling( + # test_negative_exponents, "Negative exponents test" + # ) + # run_test_with_error_handling( + # test_fractional_exponents, "Fractional exponents test" + # ) + # run_test_with_error_handling( + # test_high_precision_exponents, "High precision exponents test" + # ) + # run_test_with_error_handling( + # test_mathematical_identities, "Mathematical identities test" + # ) + # run_test_with_error_handling(test_extreme_values, "Extreme values test") + # run_test_with_error_handling(test_edge_cases, "Edge cases test") + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All exponential function tests passed!") diff --git a/tests/decimal128/test_decimal128_factorial.mojo b/tests/decimal128/test_decimal128_factorial.mojo index eba5bec..87264f2 100644 --- a/tests/decimal128/test_decimal128_factorial.mojo +++ b/tests/decimal128/test_decimal128_factorial.mojo @@ -12,7 +12,7 @@ from decimojo.decimal128.special import factorial, factorial_reciprocal fn test_basic_factorials() raises: """Test basic factorial calculations.""" - print("Testing basic factorial calculations...") + # print("Testing basic factorial calculations...") # Test case 1: 0! = 1 var result0 = factorial(0) @@ -50,12 +50,12 @@ fn test_basic_factorials() raises: String(result5), "120", "5! should be 120, got " + String(result5) ) - print("✓ Basic factorial tests passed!") + # print("✓ Basic factorial tests passed!") fn test_medium_factorials() raises: """Test medium-sized factorial calculations.""" - print("Testing medium-sized factorial calculations...") + # print("Testing medium-sized factorial calculations...") # Test case 7: 6! = 720 var result6 = factorial(6) @@ -91,12 +91,12 @@ fn test_medium_factorials() raises: "10! should be 3628800, got " + String(result10), ) - print("✓ Medium factorial tests passed!") + # print("✓ Medium factorial tests passed!") fn test_large_factorials() raises: """Test large factorial calculations.""" - print("Testing large factorial calculations...") + # print("Testing large factorial calculations...") # Test case 12: 12! = 479001600 var result12 = factorial(12) @@ -140,12 +140,12 @@ fn test_large_factorials() raises: "27! should be " + expected27 + ", got " + String(result27), ) - print("✓ Large factorial tests passed!") + # print("✓ Large factorial tests passed!") fn test_factorial_properties() raises: """Test mathematical properties of factorials.""" - print("Testing factorial mathematical properties...") + # print("Testing factorial mathematical properties...") # Test case: (n+1)! = (n+1) * n! # Only test up to 26 because 27 is our maximum supported value @@ -162,12 +162,12 @@ fn test_factorial_properties() raises: + String(n + 1), ) - print("✓ Factorial properties tests passed!") + # print("✓ Factorial properties tests passed!") fn test_factorial_edge_cases() raises: """Test edge cases for factorial function.""" - print("Testing factorial edge cases...") + # print("Testing factorial edge cases...") # Test case: Error for negative input var exception_caught = False @@ -193,18 +193,18 @@ fn test_factorial_edge_cases() raises: exception_caught = True testing.assert_equal(exception_caught, True) - print("✓ Factorial edge case tests passed!") + # print("✓ Factorial edge case tests passed!") fn test_factorial_of_zero() raises: """Special test for factorial of zero.""" - print("Testing special case: 0!...") + # print("Testing special case: 0!...") # Test case: Verify 0! = 1 (mathematical definition) var result = factorial(0) testing.assert_equal(String(result), "1", "0! should equal 1") - print("✓ Special case test for 0! passed!") + # print("✓ Special case test for 0! passed!") fn run_test_with_error_handling( @@ -226,7 +226,7 @@ fn run_test_with_error_handling( fn test_factorial_reciprocal() raises: """Test that factorial_reciprocal equals 1 divided by factorial.""" - print("Testing factorial_reciprocal function...") + # print("Testing factorial_reciprocal function...") # Test for all values in the supported range (0-27) var all_equal = True @@ -249,30 +249,32 @@ fn test_factorial_reciprocal() raises: ), ) - print("✓ Factorial reciprocal tests passed!") + # print("✓ Factorial reciprocal tests passed!") fn main() raises: - print("=========================================") - print("Running Factorial Function Tests (0-27)") - print("=========================================") - - run_test_with_error_handling(test_basic_factorials, "Basic factorials test") - run_test_with_error_handling( - test_medium_factorials, "Medium factorials test" - ) - run_test_with_error_handling(test_large_factorials, "Large factorials test") - run_test_with_error_handling( - test_factorial_properties, "Factorial properties test" - ) - run_test_with_error_handling( - test_factorial_edge_cases, "Factorial edge cases test" - ) - run_test_with_error_handling( - test_factorial_of_zero, "Factorial of zero test" - ) - run_test_with_error_handling( - test_factorial_reciprocal, "Factorial reciprocal test" - ) - - print("All factorial function tests passed!") + # print("=========================================") + # print("Running Factorial Function Tests (0-27)") + # print("=========================================") + + # run_test_with_error_handling(test_basic_factorials, "Basic factorials test") + # run_test_with_error_handling( + # test_medium_factorials, "Medium factorials test" + # ) + # run_test_with_error_handling(test_large_factorials, "Large factorials test") + # run_test_with_error_handling( + # test_factorial_properties, "Factorial properties test" + # ) + # run_test_with_error_handling( + # test_factorial_edge_cases, "Factorial edge cases test" + # ) + # run_test_with_error_handling( + # test_factorial_of_zero, "Factorial of zero test" + # ) + # run_test_with_error_handling( + # test_factorial_reciprocal, "Factorial reciprocal test" + # ) + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All factorial function tests passed!") diff --git a/tests/decimal128/test_decimal128_from_components.mojo b/tests/decimal128/test_decimal128_from_components.mojo index 91bb04a..d7575a4 100644 --- a/tests/decimal128/test_decimal128_from_components.mojo +++ b/tests/decimal128/test_decimal128_from_components.mojo @@ -91,4 +91,5 @@ fn test_decimal_from_components() raises: fn main() raises: - test_decimal_from_components() + # test_decimal_from_components() + testing.TestSuite.discover_tests[__functions_in_module()]().run() diff --git a/tests/decimal128/test_decimal128_from_float.mojo b/tests/decimal128/test_decimal128_from_float.mojo index 4e93398..1ffe007 100644 --- a/tests/decimal128/test_decimal128_from_float.mojo +++ b/tests/decimal128/test_decimal128_from_float.mojo @@ -14,7 +14,7 @@ from decimojo.prelude import dm, Decimal128, RoundingMode fn test_simple_integers() raises: """Test conversion of simple integer float values.""" - print("Testing simple integer float conversions...") + # print("Testing simple integer float conversions...") # Test case 1: Zero var zero = Decimal128.from_float(0.0) @@ -48,12 +48,12 @@ fn test_simple_integers() raises: "Float 1000.0 should convert to Decimal128 1000", ) - print("✓ Simple integer tests passed") + # print("✓ Simple integer tests passed") fn test_simple_decimals() raises: """Test conversion of simple decimal float values.""" - print("Testing simple decimal float conversions...") + # print("Testing simple decimal float conversions...") # Test case 6: 0.5 (exact representation) var half = Decimal128.from_float(0.5) @@ -87,12 +87,12 @@ fn test_simple_decimals() raises: "Float 2.71828 should convert to a Decimal128 starting with 2.7182", ) - print("✓ Simple decimal tests passed") + # print("✓ Simple decimal tests passed") fn test_negative_numbers() raises: """Test conversion of negative float values.""" - print("Testing negative float conversions...") + # print("Testing negative float conversions...") # Test case 11: -1.0 var neg_one = Decimal128.from_float(-1.0) @@ -126,12 +126,12 @@ fn test_negative_numbers() raises: "Float -999.999 should convert to a Decimal128 starting with -999.99", ) - print("✓ Negative number tests passed") + # print("✓ Negative number tests passed") fn test_very_large_numbers() raises: """Test conversion of very large float values.""" - print("Testing very large float conversions...") + # print("Testing very large float conversions...") # Test case 16: 1e10 var ten_billion = Decimal128.from_float(1e10) @@ -172,12 +172,12 @@ fn test_very_large_numbers() raises: "Large float should convert with appropriate precision", ) - print("✓ Very large number tests passed") + # print("✓ Very large number tests passed") fn test_very_small_numbers() raises: """Test conversion of very small float values.""" - print("Testing very small float conversions...") + # print("Testing very small float conversions...") # Test case 21: 1e-10 var tiny = Decimal128.from_float(1e-10) @@ -215,13 +215,13 @@ fn test_very_small_numbers() raises: "Denormalized float should convert to small Decimal128", ) - print("✓ Very small number tests passed") + # print("✓ Very small number tests passed") fn test_binary_to_decimal_conversion() raises: """Test conversion of float values that require binary to decimal conversion. """ - print("Testing binary to decimal conversion edge cases...") + # print("Testing binary to decimal conversion edge cases...") # Test case 26: 0.1 (known inexact in binary) var point_one = Decimal128.from_float(0.1) @@ -258,12 +258,12 @@ fn test_binary_to_decimal_conversion() raises: "Float with repeating binary fraction should convert properly", ) - print("✓ Binary to decimal conversion tests passed") + # print("✓ Binary to decimal conversion tests passed") fn test_rounding_behavior() raises: """Test rounding behavior during float to Decimal128 conversion.""" - print("Testing rounding behavior in float to Decimal128 conversion...") + # print("Testing rounding behavior in float to Decimal128 conversion...") # Test case 31: Pi with limited precision var pi = Decimal128.from_float(3.141592653589793) @@ -301,12 +301,12 @@ fn test_rounding_behavior() raises: "Float near precision boundary should convert appropriately", ) - print("✓ Rounding behavior tests passed") + # print("✓ Rounding behavior tests passed") fn test_special_values() raises: """Test handling of special float values.""" - print("Testing special float values...") + # print("Testing special float values...") # Test case 36: 0.0 (already covered but included for completeness) var zero = Decimal128.from_float(0.0) @@ -340,12 +340,12 @@ fn test_special_values() raises: "Float with many 9s should preserve precision appropriately", ) - print("✓ Special value tests passed") + # print("✓ Special value tests passed") fn test_scientific_notation() raises: """Test handling of scientific notation values.""" - print("Testing scientific notation float values...") + # print("Testing scientific notation float values...") # Test case 41: Simple scientific notation var sci1 = Decimal128.from_float(1.23e5) @@ -387,12 +387,12 @@ fn test_scientific_notation() raises: "Float with low precision but high exponent should convert properly", ) - print("✓ Scientific notation tests passed") + # print("✓ Scientific notation tests passed") fn test_boundary_cases() raises: """Test boundary cases for float to Decimal128 conversion.""" - print("Testing boundary cases...") + # print("Testing boundary cases...") # Test case 46: Exact power of 10 var pow10 = Decimal128.from_float(1000.0) @@ -433,7 +433,7 @@ fn test_boundary_cases() raises: ), ) - print("✓ Boundary case tests passed") + # print("✓ Boundary case tests passed") fn run_test_with_error_handling( @@ -454,29 +454,31 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running 50 tests for Decimal128.from_float()") - print("=========================================") - - run_test_with_error_handling(test_simple_integers, "Simple integers test") - run_test_with_error_handling(test_simple_decimals, "Simple decimals test") - run_test_with_error_handling(test_negative_numbers, "Negative numbers test") - run_test_with_error_handling( - test_very_large_numbers, "Very large numbers test" - ) - run_test_with_error_handling( - test_very_small_numbers, "Very small numbers test" - ) - run_test_with_error_handling( - test_binary_to_decimal_conversion, "Binary to decimal conversion test" - ) - run_test_with_error_handling( - test_rounding_behavior, "Rounding behavior test" - ) - run_test_with_error_handling(test_special_values, "Special values test") - run_test_with_error_handling( - test_scientific_notation, "Scientific notation test" - ) - run_test_with_error_handling(test_boundary_cases, "Boundary cases test") - - print("All 50 Decimal128.from_float() tests passed!") + # print("=========================================") + # print("Running 50 tests for Decimal128.from_float()") + # print("=========================================") + + # run_test_with_error_handling(test_simple_integers, "Simple integers test") + # run_test_with_error_handling(test_simple_decimals, "Simple decimals test") + # run_test_with_error_handling(test_negative_numbers, "Negative numbers test") + # run_test_with_error_handling( + # test_very_large_numbers, "Very large numbers test" + # ) + # run_test_with_error_handling( + # test_very_small_numbers, "Very small numbers test" + # ) + # run_test_with_error_handling( + # test_binary_to_decimal_conversion, "Binary to decimal conversion test" + # ) + # run_test_with_error_handling( + # test_rounding_behavior, "Rounding behavior test" + # ) + # run_test_with_error_handling(test_special_values, "Special values test") + # run_test_with_error_handling( + # test_scientific_notation, "Scientific notation test" + # ) + # run_test_with_error_handling(test_boundary_cases, "Boundary cases test") + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All 50 Decimal128.from_float() tests passed!") diff --git a/tests/decimal128/test_decimal128_from_int.mojo b/tests/decimal128/test_decimal128_from_int.mojo index c35c27d..f5d660b 100644 --- a/tests/decimal128/test_decimal128_from_int.mojo +++ b/tests/decimal128/test_decimal128_from_int.mojo @@ -9,7 +9,7 @@ from decimojo.prelude import dm, Decimal128, RoundingMode fn test_basic_integers() raises: """Test conversion of basic integers.""" - print("Testing basic integer conversions...") + # print("Testing basic integer conversions...") # Test case 1: Zero var result1 = Decimal128.from_int(0) @@ -45,12 +45,12 @@ fn test_basic_integers() raises: "10 + 5 should be 15, got " + String(sum_result), ) - print("✓ Basic integer conversion tests passed!") + # print("✓ Basic integer conversion tests passed!") fn test_large_integers() raises: """Test conversion of large integers.""" - print("Testing large integer conversions...") + # print("Testing large integer conversions...") # Test case 1: Large positive integer var large_pos = Decimal128.from_int(1000000000) # 1 billion @@ -92,12 +92,12 @@ fn test_large_integers() raises: "from_int(INT64_MAX) conversion failed", ) - print("✓ Large integer conversion tests passed!") + # print("✓ Large integer conversion tests passed!") fn test_operations_with_from_int() raises: """Test arithmetic operations using from_int results.""" - print("Testing operations with from_int results...") + # print("Testing operations with from_int results...") # Test case 1: Addition var a1 = Decimal128.from_int(100) @@ -141,12 +141,12 @@ fn test_operations_with_from_int() raises: "10 * 3.5 should be 35.0, got " + String(result5), ) - print("✓ Operations with from_int results tests passed!") + # print("✓ Operations with from_int results tests passed!") fn test_comparison_with_from_int() raises: """Test comparison operations using from_int results.""" - print("Testing comparisons with from_int results...") + # print("Testing comparisons with from_int results...") # Test case 1: Equality with same value var a1 = Decimal128.from_int(100) @@ -181,12 +181,12 @@ fn test_comparison_with_from_int() raises: a5 == b5, "from_int(-500) should equal Decimal128('-500')" ) - print("✓ Comparison with from_int results tests passed!") + # print("✓ Comparison with from_int results tests passed!") fn test_properties() raises: """Test properties of from_int results.""" - print("Testing properties of from_int results...") + # print("Testing properties of from_int results...") # Test case 1: Sign of positive var pos = Decimal128.from_int(100) @@ -220,12 +220,12 @@ fn test_properties() raises: "Coefficient should match the input integer value", ) - print("✓ Properties of from_int results tests passed!") + # print("✓ Properties of from_int results tests passed!") fn test_edge_cases() raises: """Test edge cases for from_int.""" - print("Testing edge cases for from_int...") + # print("Testing edge cases for from_int...") # Test case 1: Zero remains zero var zero = Decimal128.from_int(0) @@ -265,12 +265,12 @@ fn test_edge_cases() raises: var power10 = Decimal128.from_int(10**9) # 1 billion testing.assert_equal(String(power10), "1000000000", "from_int(10^9) failed") - print("✓ Edge cases for from_int tests passed!") + # print("✓ Edge cases for from_int tests passed!") fn test_from_int_with_scale() raises: """Test from_int with scale argument.""" - print("Testing from_int with scale argument...") + # print("Testing from_int with scale argument...") # Test case 1: Positive integer with positive scale var result1 = Decimal128.from_int(123, 2) @@ -341,7 +341,7 @@ fn test_from_int_with_scale() raises: a8 != b8, "from_int(123, 0) should not equal from_int(123, 2)" ) - print("✓ from_int with scale tests passed!") + # print("✓ from_int with scale tests passed!") fn run_test_with_error_handling( @@ -362,28 +362,30 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running Decimal128.from_int() Tests") - print("=========================================") - - run_test_with_error_handling( - test_basic_integers, "Basic integer conversion test" - ) - run_test_with_error_handling( - test_large_integers, "Large integer conversion test" - ) - run_test_with_error_handling( - test_operations_with_from_int, "Operations with from_int test" - ) - run_test_with_error_handling( - test_comparison_with_from_int, "Comparison with from_int test" - ) - run_test_with_error_handling( - test_properties, "Properties of from_int results test" - ) - run_test_with_error_handling(test_edge_cases, "Edge cases test") - run_test_with_error_handling( - test_from_int_with_scale, "from_int with scale test" - ) - - print("All Decimal128.from_int() tests passed!") + # print("=========================================") + # print("Running Decimal128.from_int() Tests") + # print("=========================================") + + # run_test_with_error_handling( + # test_basic_integers, "Basic integer conversion test" + # ) + # run_test_with_error_handling( + # test_large_integers, "Large integer conversion test" + # ) + # run_test_with_error_handling( + # test_operations_with_from_int, "Operations with from_int test" + # ) + # run_test_with_error_handling( + # test_comparison_with_from_int, "Comparison with from_int test" + # ) + # run_test_with_error_handling( + # test_properties, "Properties of from_int results test" + # ) + # run_test_with_error_handling(test_edge_cases, "Edge cases test") + # run_test_with_error_handling( + # test_from_int_with_scale, "from_int with scale test" + # ) + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All Decimal128.from_int() tests passed!") diff --git a/tests/decimal128/test_decimal128_from_string.mojo b/tests/decimal128/test_decimal128_from_string.mojo index 4608cd0..0347133 100644 --- a/tests/decimal128/test_decimal128_from_string.mojo +++ b/tests/decimal128/test_decimal128_from_string.mojo @@ -9,7 +9,7 @@ from decimojo.prelude import dm, Decimal128, RoundingMode fn test_basic_integers() raises: """Test conversion of basic integer strings.""" - print("Testing basic integer string conversions...") + # print("Testing basic integer string conversions...") # Test case 1: Zero var zero = Decimal128.from_string("0") @@ -44,12 +44,12 @@ fn test_basic_integers() raises: exception_caught = True testing.assert_equal(exception_caught, True) - print("✓ Basic integer tests passed") + # print("✓ Basic integer tests passed") fn test_basic_decimals() raises: """Test conversion of basic decimal strings.""" - print("Testing basic decimal string conversions...") + # print("Testing basic decimal string conversions...") # Test case 6: Simple decimal var simple_dec = Decimal128.from_string("123.45") @@ -75,12 +75,12 @@ fn test_basic_decimals() raises: String(high_precision), "0.1234567890123456789012345679" ) - print("✓ Basic decimal tests passed") + # print("✓ Basic decimal tests passed") fn test_negative_numbers() raises: """Test conversion of negative number strings.""" - print("Testing negative number string conversions...") + # print("Testing negative number string conversions...") # Test case 11: Negative integer var neg_int = Decimal128.from_string("-123") @@ -108,12 +108,12 @@ fn test_negative_numbers() raises: var neg_small = Decimal128.from_string("-0.001") testing.assert_equal(String(neg_small), "-0.001") - print("✓ Negative number tests passed") + # print("✓ Negative number tests passed") fn test_zeros_variants() raises: """Test conversion of various zero representations.""" - print("Testing zero variants string conversions...") + # print("Testing zero variants string conversions...") # Test case 16: Single zero var single_zero = Decimal128.from_string("0") @@ -141,12 +141,12 @@ fn test_zeros_variants() raises: var leading_zeros_decimal = Decimal128.from_string("000.000") testing.assert_equal(String(leading_zeros_decimal), "0.000") - print("✓ Zero variants tests passed") + # print("✓ Zero variants tests passed") fn test_scientific_notation() raises: """Test conversion of strings with scientific notation.""" - print("Testing scientific notation string conversions...") + # print("Testing scientific notation string conversions...") # Test case 21: Simple positive exponent var simple_pos_exp = Decimal128.from_string("1.23e2") @@ -168,12 +168,12 @@ fn test_scientific_notation() raises: var large_exp = Decimal128.from_string("1.23e20") testing.assert_equal(String(large_exp), "123000000000000000000") - print("✓ Scientific notation tests passed") + # print("✓ Scientific notation tests passed") fn test_formatting_variants() raises: """Test conversion of strings with various formatting variations.""" - print("Testing string formatting variants...") + # print("Testing string formatting variants...") # Test case 26: Leading zeros with integer var leading_zeros_int = Decimal128.from_string("00123") @@ -203,12 +203,12 @@ fn test_formatting_variants() raises: "Decimal128 point with no preceding digits should add leading 0", ) - print("✓ Formatting variants tests passed") + # print("✓ Formatting variants tests passed") fn test_special_characters() raises: """Test conversion of strings with special characters.""" - print("Testing strings with special characters...") + # print("Testing strings with special characters...") # Test case 31: Positive sign var positive_sign = Decimal128.from_string("+123.45") @@ -230,12 +230,12 @@ fn test_special_characters() raises: var multi_digit_exp = Decimal128.from_string("1.23e+12") testing.assert_equal(String(multi_digit_exp), "1230000000000") - print("✓ Special character tests passed") + # print("✓ Special character tests passed") fn test_invalid_inputs() raises: """Test handling of invalid input strings.""" - print("Testing invalid input strings...") + # print("Testing invalid input strings...") # Test case 36: Empty string var exception_caught = False @@ -290,12 +290,12 @@ fn test_invalid_inputs() raises: exception_caught = True testing.assert_equal(exception_caught, True) - print("✓ Invalid input tests passed") + # print("✓ Invalid input tests passed") fn test_boundary_cases() raises: """Test boundary cases for string conversion.""" - print("Testing boundary cases...") + # print("Testing boundary cases...") # Test case 41: Value at maximum precision var max_precision = Decimal128.from_string("0." + "1" * 28) @@ -318,12 +318,12 @@ fn test_boundary_cases() raises: var max_value = Decimal128.from_string(max_value_str) testing.assert_equal(String(max_value), max_value_str) - print("✓ Boundary case tests passed") + # print("✓ Boundary case tests passed") fn test_special_cases() raises: """Test special cases for string conversion.""" - print("Testing special cases...") + # print("Testing special cases...") # Test case 46: Very long decimal var long_decimal = Decimal128.from_string( @@ -350,7 +350,7 @@ fn test_special_cases() raises: var pattern = Decimal128.from_string("123.456789012345678901234567") testing.assert_equal(String(pattern), "123.456789012345678901234567") - print("✓ Special case tests passed") + # print("✓ Special case tests passed") fn run_test_with_error_handling( @@ -371,25 +371,27 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running 50 tests for Decimal128.from_string()") - print("=========================================") - - run_test_with_error_handling(test_basic_integers, "Basic integers test") - run_test_with_error_handling(test_basic_decimals, "Basic decimals test") - run_test_with_error_handling(test_negative_numbers, "Negative numbers test") - run_test_with_error_handling(test_zeros_variants, "Zero variants test") - run_test_with_error_handling( - test_scientific_notation, "Scientific notation test" - ) - run_test_with_error_handling( - test_formatting_variants, "Formatting variants test" - ) - run_test_with_error_handling( - test_special_characters, "Special characters test" - ) - run_test_with_error_handling(test_invalid_inputs, "Invalid inputs test") - run_test_with_error_handling(test_boundary_cases, "Boundary cases test") - run_test_with_error_handling(test_special_cases, "Special cases test") - - print("All 50 Decimal128.from_string() tests passed!") + # print("=========================================") + # print("Running 50 tests for Decimal128.from_string()") + # print("=========================================") + + # run_test_with_error_handling(test_basic_integers, "Basic integers test") + # run_test_with_error_handling(test_basic_decimals, "Basic decimals test") + # run_test_with_error_handling(test_negative_numbers, "Negative numbers test") + # run_test_with_error_handling(test_zeros_variants, "Zero variants test") + # run_test_with_error_handling( + # test_scientific_notation, "Scientific notation test" + # ) + # run_test_with_error_handling( + # test_formatting_variants, "Formatting variants test" + # ) + # run_test_with_error_handling( + # test_special_characters, "Special characters test" + # ) + # run_test_with_error_handling(test_invalid_inputs, "Invalid inputs test") + # run_test_with_error_handling(test_boundary_cases, "Boundary cases test") + # run_test_with_error_handling(test_special_cases, "Special cases test") + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All 50 Decimal128.from_string() tests passed!") diff --git a/tests/decimal128/test_decimal128_ln.mojo b/tests/decimal128/test_decimal128_ln.mojo index c6e9291..89ccc7f 100644 --- a/tests/decimal128/test_decimal128_ln.mojo +++ b/tests/decimal128/test_decimal128_ln.mojo @@ -11,7 +11,7 @@ from decimojo.decimal128.exponential import ln fn test_basic_ln_values() raises: """Test basic natural logarithm values.""" - print("Testing basic natural logarithm values...") + # print("Testing basic natural logarithm values...") # Test case 1: ln(1) = 0 var one = Decimal128(1) @@ -47,12 +47,12 @@ fn test_basic_ln_values() raises: + String(result_tenth), ) - print("✓ Basic natural logarithm values tests passed!") + # print("✓ Basic natural logarithm values tests passed!") fn test_fractional_ln_values() raises: """Test natural logarithm values with fractional inputs.""" - print("Testing natural logarithm values with fractional inputs...") + # print("Testing natural logarithm values with fractional inputs...") # Test case 5: ln(0.5) var half = Decimal128("0.5") @@ -82,12 +82,12 @@ fn test_fractional_ln_values() raises: + String(result_five), ) - print("✓ Fractional natural logarithm values tests passed!") + # print("✓ Fractional natural logarithm values tests passed!") fn test_mathematical_identities() raises: """Test mathematical identities related to the natural logarithm.""" - print("Testing mathematical identities for natural logarithm...") + # print("Testing mathematical identities for natural logarithm...") # Test case 8: ln(a * b) = ln(a) + ln(b) var a = Decimal128(2) @@ -115,12 +115,12 @@ fn test_mathematical_identities() raises: "ln(e^x) should equal x within tolerance", ) - print("✓ Mathematical identities tests passed!") + # print("✓ Mathematical identities tests passed!") fn test_edge_cases() raises: """Test edge cases for natural logarithm function.""" - print("Testing edge cases for natural logarithm function...") + # print("Testing edge cases for natural logarithm function...") # Test case 11: ln(0) should raise an exception var zero = Decimal128(0) @@ -165,12 +165,12 @@ fn test_edge_cases() raises: ).format(result_large), ) - print("✓ Edge cases tests passed!") + # print("✓ Edge cases tests passed!") fn test_precision() raises: """Test precision of natural logarithm calculations.""" - print("Testing precision of natural logarithm calculations...") + # print("Testing precision of natural logarithm calculations...") # Test case 15: ln(2) with high precision var two = Decimal128(2) @@ -191,12 +191,12 @@ fn test_precision() raises: ).format(result_ten), ) - print("✓ Precision tests passed!") + # print("✓ Precision tests passed!") fn test_range_of_values() raises: """Test natural logarithm function across a range of values.""" - print("Testing natural logarithm function across a range of values...") + # print("Testing natural logarithm function across a range of values...") # Test case 17: ln(x) for x in range (3, 10) testing.assert_true( @@ -218,12 +218,12 @@ fn test_range_of_values() raises: "ln(x) should be negative for x < 1", ) - print("✓ Range of values tests passed!") + # print("✓ Range of values tests passed!") fn test_special_cases() raises: """Test special cases for natural logarithm function.""" - print("Testing special cases for natural logarithm function...") + # print("Testing special cases for natural logarithm function...") # Test case 19: ln(1) = 0 (revisited) var one = Decimal128(1) @@ -238,7 +238,7 @@ fn test_special_cases() raises: "ln(e) should be very close to 1", ) - print("✓ Special cases tests passed!") + # print("✓ Special cases tests passed!") fn run_test_with_error_handling( @@ -259,20 +259,22 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running Natural Logarithm Function Tests") - print("=========================================") - - run_test_with_error_handling(test_basic_ln_values, "Basic ln values test") - run_test_with_error_handling( - test_fractional_ln_values, "Fractional ln values test" - ) - run_test_with_error_handling( - test_mathematical_identities, "Mathematical identities test" - ) - run_test_with_error_handling(test_edge_cases, "Edge cases test") - run_test_with_error_handling(test_precision, "Precision test") - run_test_with_error_handling(test_range_of_values, "Range of values test") - run_test_with_error_handling(test_special_cases, "Special cases test") - - print("All natural logarithm function tests passed!") + # print("=========================================") + # print("Running Natural Logarithm Function Tests") + # print("=========================================") + + # run_test_with_error_handling(test_basic_ln_values, "Basic ln values test") + # run_test_with_error_handling( + # test_fractional_ln_values, "Fractional ln values test" + # ) + # run_test_with_error_handling( + # test_mathematical_identities, "Mathematical identities test" + # ) + # run_test_with_error_handling(test_edge_cases, "Edge cases test") + # run_test_with_error_handling(test_precision, "Precision test") + # run_test_with_error_handling(test_range_of_values, "Range of values test") + # run_test_with_error_handling(test_special_cases, "Special cases test") + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All natural logarithm function tests passed!") diff --git a/tests/decimal128/test_decimal128_log.mojo b/tests/decimal128/test_decimal128_log.mojo index 3355701..cd94c82 100644 --- a/tests/decimal128/test_decimal128_log.mojo +++ b/tests/decimal128/test_decimal128_log.mojo @@ -9,7 +9,7 @@ from decimojo.prelude import dm, Decimal128, RoundingMode fn test_basic_log() raises: """Test basic logarithm calculations with common bases.""" - print("Testing basic logarithm calculations...") + # print("Testing basic logarithm calculations...") # Test case 1: log_2(8) = 3 var val1 = Decimal128(8) @@ -55,12 +55,12 @@ fn test_basic_log() raises: String(result5), "1", "log_e(e) should be 1, got " + String(result5) ) - print("✓ Basic logarithm calculations tests passed!") + # print("✓ Basic logarithm calculations tests passed!") fn test_non_integer_results() raises: """Test logarithm calculations that result in non-integer values.""" - print("Testing logarithm calculations with non-integer results...") + # print("Testing logarithm calculations with non-integer results...") # Test case 1: log_2(10) var val1 = Decimal128(10) @@ -109,12 +109,12 @@ fn test_non_integer_results() raises: + String(result5), ) - print("✓ Non-integer result logarithm tests passed!") + # print("✓ Non-integer result logarithm tests passed!") fn test_fractional_inputs() raises: """Test logarithm calculations with fractional inputs.""" - print("Testing logarithm calculations with fractional inputs...") + # print("Testing logarithm calculations with fractional inputs...") # Test case 1: log_2(0.5) = -1 var val1 = Decimal128("0.5") @@ -162,12 +162,12 @@ fn test_fractional_inputs() raises: + String(result5), ) - print("✓ Fractional input logarithm tests passed!") + # print("✓ Fractional input logarithm tests passed!") fn test_edge_cases() raises: """Test edge cases for the logarithm function.""" - print("Testing logarithm edge cases...") + # print("Testing logarithm edge cases...") # Test case 1: log of a negative number (should raise error) var val1 = Decimal128(-10) @@ -258,12 +258,12 @@ fn test_edge_cases() raises: "log_b(b) should be 1 for any base, got " + String(result7), ) - print("✓ Edge cases tests passed!") + # print("✓ Edge cases tests passed!") fn test_precision() raises: """Test precision of logarithm calculations.""" - print("Testing logarithm precision...") + # print("Testing logarithm precision...") # Test case 1: High precision logarithm var val1 = Decimal128( @@ -307,12 +307,12 @@ fn test_precision() raises: + String(result4), ) - print("✓ Precision tests passed!") + # print("✓ Precision tests passed!") fn test_mathematical_properties() raises: """Test mathematical properties of logarithms.""" - print("Testing mathematical properties of logarithms...") + # print("Testing mathematical properties of logarithms...") # Test case 1: log_a(x*y) = log_a(x) + log_a(y) var x1 = Decimal128(3) @@ -368,12 +368,12 @@ fn test_mathematical_properties() raises: "log_a(b) should equal log_c(b) / log_c(a)", ) - print("✓ Mathematical properties tests passed!") + # print("✓ Mathematical properties tests passed!") fn test_consistency_with_other_logarithms() raises: """Test consistency between log(base) and other logarithm functions.""" - print("Testing consistency with other logarithm functions...") + # print("Testing consistency with other logarithm functions...") # Test case 1: log_10(x) == log10(x) var val1 = Decimal128(7) @@ -393,7 +393,7 @@ fn test_consistency_with_other_logarithms() raises: "log(x, e) should equal ln(x)", ) - print("✓ Consistency with other logarithms tests passed!") + # print("✓ Consistency with other logarithms tests passed!") fn run_test_with_error_handling( @@ -414,25 +414,27 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running log() Function Tests") - print("=========================================") - - run_test_with_error_handling(test_basic_log, "Basic logarithm test") - run_test_with_error_handling( - test_non_integer_results, "Non-integer results test" - ) - run_test_with_error_handling( - test_fractional_inputs, "Fractional inputs test" - ) - run_test_with_error_handling(test_edge_cases, "Edge cases test") - run_test_with_error_handling(test_precision, "Precision test") - run_test_with_error_handling( - test_mathematical_properties, "Mathematical properties test" - ) - run_test_with_error_handling( - test_consistency_with_other_logarithms, - "Consistency with other logarithms test", - ) - - print("All log() function tests passed!") + # print("=========================================") + # print("Running log() Function Tests") + # print("=========================================") + + # run_test_with_error_handling(test_basic_log, "Basic logarithm test") + # run_test_with_error_handling( + # test_non_integer_results, "Non-integer results test" + # ) + # run_test_with_error_handling( + # test_fractional_inputs, "Fractional inputs test" + # ) + # run_test_with_error_handling(test_edge_cases, "Edge cases test") + # run_test_with_error_handling(test_precision, "Precision test") + # run_test_with_error_handling( + # test_mathematical_properties, "Mathematical properties test" + # ) + # run_test_with_error_handling( + # test_consistency_with_other_logarithms, + # "Consistency with other logarithms test", + # ) + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All log() function tests passed!") diff --git a/tests/decimal128/test_decimal128_log10.mojo b/tests/decimal128/test_decimal128_log10.mojo index 28daa1a..1088f4d 100644 --- a/tests/decimal128/test_decimal128_log10.mojo +++ b/tests/decimal128/test_decimal128_log10.mojo @@ -9,7 +9,7 @@ from decimojo.prelude import dm, Decimal128, RoundingMode fn test_basic_log10() raises: """Test basic logarithm base 10 calculations.""" - print("Testing basic log10 calculations...") + # print("Testing basic log10 calculations...") # Test case 1: log10(1) = 0 var val1 = Decimal128(1) @@ -55,12 +55,12 @@ fn test_basic_log10() raises: "log10(0.01) should be -2, got " + String(result6), ) - print("✓ Basic log10 calculations tests passed!") + # print("✓ Basic log10 calculations tests passed!") fn test_non_powers_of_ten() raises: """Test logarithm base 10 of numbers that are not exact powers of 10.""" - print("Testing log10 of non-powers of 10...") + # print("Testing log10 of non-powers of 10...") # Test case 1: log10(2) var val1 = Decimal128(2) @@ -107,12 +107,12 @@ fn test_non_powers_of_ten() raises: + String(result5), ) - print("✓ Non-powers of 10 log10 calculations tests passed!") + # print("✓ Non-powers of 10 log10 calculations tests passed!") fn test_edge_cases() raises: """Test edge cases for logarithm base 10.""" - print("Testing log10 edge cases...") + # print("Testing log10 edge cases...") # Test case 1: log10 of a negative number (should raise error) var val1 = Decimal128(-10) @@ -166,12 +166,12 @@ fn test_edge_cases() raises: "log10(10^-20) should be -20, got " + String(result5), ) - print("✓ Edge cases tests passed!") + # print("✓ Edge cases tests passed!") fn test_precision() raises: """Test precision of logarithm base 10 calculations.""" - print("Testing log10 precision...") + # print("Testing log10 precision...") # Test case 1: High precision decimal var val1 = Decimal128("3.14159265358979323846") @@ -207,12 +207,12 @@ fn test_precision() raises: "log10(9.999999999) should be precise, got " + String(result4), ) - print("✓ Precision tests passed!") + # print("✓ Precision tests passed!") fn test_mathematical_properties() raises: """Test mathematical properties of logarithm base 10.""" - print("Testing mathematical properties of log10...") + # print("Testing mathematical properties of log10...") # Test case 1: log10(a*b) = log10(a) + log10(b) var a1 = Decimal128(2) @@ -257,12 +257,12 @@ fn test_mathematical_properties() raises: "log10(1/a) should equal -log10(a)", ) - print("✓ Mathematical properties tests passed!") + # print("✓ Mathematical properties tests passed!") fn test_consistency_with_other_logarithms() raises: """Test consistency between log10 and other logarithm functions.""" - print("Testing consistency with other logarithm functions...") + # print("Testing consistency with other logarithm functions...") # Test case 1: log10(x) = ln(x) / ln(10) var val1 = Decimal128(7) @@ -284,7 +284,7 @@ fn test_consistency_with_other_logarithms() raises: "log10(x) should equal log(x, 10)", ) - print("✓ Consistency with other logarithms tests passed!") + # print("✓ Consistency with other logarithms tests passed!") fn run_test_with_error_handling( @@ -305,24 +305,26 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running log10() Function Tests") - print("=========================================") - - run_test_with_error_handling( - test_basic_log10, "Basic log10 calculations test" - ) - run_test_with_error_handling( - test_non_powers_of_ten, "Non-powers of 10 test" - ) - run_test_with_error_handling(test_edge_cases, "Edge cases test") - run_test_with_error_handling(test_precision, "Precision test") - run_test_with_error_handling( - test_mathematical_properties, "Mathematical properties test" - ) - run_test_with_error_handling( - test_consistency_with_other_logarithms, - "Consistency with other logarithms test", - ) - - print("All log10() function tests passed!") + # print("=========================================") + # print("Running log10() Function Tests") + # print("=========================================") + + # run_test_with_error_handling( + # test_basic_log10, "Basic log10 calculations test" + # ) + # run_test_with_error_handling( + # test_non_powers_of_ten, "Non-powers of 10 test" + # ) + # run_test_with_error_handling(test_edge_cases, "Edge cases test") + # run_test_with_error_handling(test_precision, "Precision test") + # run_test_with_error_handling( + # test_mathematical_properties, "Mathematical properties test" + # ) + # run_test_with_error_handling( + # test_consistency_with_other_logarithms, + # "Consistency with other logarithms test", + # ) + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All log10() function tests passed!") diff --git a/tests/decimal128/test_decimal128_modulo.mojo b/tests/decimal128/test_decimal128_modulo.mojo index 18c6c05..c2d5035 100644 --- a/tests/decimal128/test_decimal128_modulo.mojo +++ b/tests/decimal128/test_decimal128_modulo.mojo @@ -9,7 +9,7 @@ from decimojo.prelude import dm, Decimal128, RoundingMode fn test_basic_modulo() raises: """Test basic modulo operations with positive integers.""" - print("Testing basic modulo operations...") + # print("Testing basic modulo operations...") # Test case 1: Simple modulo with remainder var a1 = Decimal128(10) @@ -55,12 +55,12 @@ fn test_basic_modulo() raises: String(result5), "3", "3 % 10 should equal 3, got " + String(result5) ) - print("✓ Basic modulo operations tests passed!") + # print("✓ Basic modulo operations tests passed!") fn test_negative_modulo() raises: """Test modulo operations involving negative numbers.""" - print("Testing modulo with negative numbers...") + # print("Testing modulo with negative numbers...") # Test case 1: Negative dividend, positive divisor var a1 = Decimal128(-10) @@ -118,12 +118,12 @@ fn test_negative_modulo() raises: "10.5 % -3 should equal 1.5, got " + String(result6), ) - print("✓ Negative number modulo tests passed!") + # print("✓ Negative number modulo tests passed!") fn test_edge_cases() raises: """Test edge cases for modulo operation.""" - print("Testing modulo edge cases...") + # print("Testing modulo edge cases...") # Test case 1: Modulo by 1 var a1 = Decimal128(10) @@ -192,12 +192,12 @@ fn test_edge_cases() raises: "7.5 % 7.5 should equal 0.0, got " + String(result7), ) - print("✓ Edge cases tests passed!") + # print("✓ Edge cases tests passed!") fn test_mathematical_relationships() raises: """Test mathematical relationships involving modulo.""" - print("Testing mathematical relationships...") + # print("Testing mathematical relationships...") # Test case 1: a = (a // b) * b + (a % b) var a1 = Decimal128(10) @@ -250,12 +250,12 @@ fn test_mathematical_relationships() raises: String(mod_once), String(mod_twice), "(a % b) % b should equal a % b" ) - print("✓ Mathematical relationships tests passed!") + # print("✓ Mathematical relationships tests passed!") fn test_consistency_with_floor_division() raises: """Test consistency between modulo and floor division operations.""" - print("Testing consistency with floor division...") + # print("Testing consistency with floor division...") # Test case 1: a % b and a - (a // b) * b var a1 = Decimal128(10) @@ -305,7 +305,7 @@ fn test_consistency_with_floor_division() raises: "a % b should equal a - (a // b) * b with mixed signs", ) - print("✓ Consistency with floor division tests passed!") + # print("✓ Consistency with floor division tests passed!") fn run_test_with_error_handling( @@ -326,23 +326,25 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running Decimal128 Modulo Tests") - print("=========================================") - - run_test_with_error_handling( - test_basic_modulo, "Basic modulo operations test" - ) - run_test_with_error_handling( - test_negative_modulo, "Negative number modulo test" - ) - run_test_with_error_handling(test_edge_cases, "Edge cases test") - run_test_with_error_handling( - test_mathematical_relationships, "Mathematical relationships test" - ) - run_test_with_error_handling( - test_consistency_with_floor_division, - "Consistency with floor division test", - ) - - print("All modulo tests passed!") + # print("=========================================") + # print("Running Decimal128 Modulo Tests") + # print("=========================================") + + # run_test_with_error_handling( + # test_basic_modulo, "Basic modulo operations test" + # ) + # run_test_with_error_handling( + # test_negative_modulo, "Negative number modulo test" + # ) + # run_test_with_error_handling(test_edge_cases, "Edge cases test") + # run_test_with_error_handling( + # test_mathematical_relationships, "Mathematical relationships test" + # ) + # run_test_with_error_handling( + # test_consistency_with_floor_division, + # "Consistency with floor division test", + # ) + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All modulo tests passed!") diff --git a/tests/decimal128/test_decimal128_multiply.mojo b/tests/decimal128/test_decimal128_multiply.mojo index b9a9418..a41b975 100644 --- a/tests/decimal128/test_decimal128_multiply.mojo +++ b/tests/decimal128/test_decimal128_multiply.mojo @@ -8,7 +8,7 @@ from decimojo.prelude import dm, Decimal128, RoundingMode fn test_basic_multiplication() raises: """Test basic integer and decimal multiplication.""" - print("Testing basic multiplication...") + # print("Testing basic multiplication...") # Test case 1: Simple integer multiplication var a1 = Decimal128(5) @@ -58,12 +58,12 @@ fn test_basic_multiplication() raises: "0.125 * 0.4 should equal 0.0500, got " + String(result5), ) - print("✓ Basic multiplication tests passed!") + # print("✓ Basic multiplication tests passed!") fn test_special_cases() raises: """Test multiplication with special cases like zero and one.""" - print("Testing multiplication with special cases...") + # print("Testing multiplication with special cases...") # Test case 1: Multiplication by zero var a1 = Decimal128("123.45") @@ -114,12 +114,12 @@ fn test_special_cases() raises: "small * 1 should equal small, got " + String(result5), ) - print("✓ Special cases multiplication tests passed!") + # print("✓ Special cases multiplication tests passed!") fn test_negative_multiplication() raises: """Test multiplication involving negative numbers.""" - print("Testing multiplication with negative numbers...") + # print("Testing multiplication with negative numbers...") # Test case 1: Negative * positive var a1 = Decimal128(-5) @@ -169,12 +169,12 @@ fn test_negative_multiplication() raises: "-0 * 123.45 should equal -0.00, got " + String(result5), ) - print("✓ Negative number multiplication tests passed!") + # print("✓ Negative number multiplication tests passed!") fn test_precision_scale() raises: """Test multiplication precision and scale handling.""" - print("Testing multiplication precision and scale...") + # print("Testing multiplication precision and scale...") # Test case 1: Addition of scales var a1 = Decimal128("0.5") # scale 1 @@ -220,12 +220,12 @@ fn test_precision_scale() raises: result5.scale(), 28, "Scale should be correctly adjusted with rounding" ) - print("✓ Precision and scale tests passed!") + # print("✓ Precision and scale tests passed!") fn test_boundary_cases() raises: """Test multiplication with boundary values.""" - print("Testing multiplication with boundary values...") + # print("Testing multiplication with boundary values...") # Test case 1: Multiplication near max value var near_max = Decimal128("38614081257132168796771975168") # ~half max @@ -275,12 +275,12 @@ fn test_boundary_cases() raises: + String(result5), ) - print("✓ Boundary cases tests passed!") + # print("✓ Boundary cases tests passed!") fn test_commutative_property() raises: """Test the commutative property of multiplication (a*b = b*a).""" - print("Testing commutative property of multiplication...") + # print("Testing commutative property of multiplication...") # Test pair 1: Integers var a1 = Decimal128(10) @@ -337,7 +337,7 @@ fn test_commutative_property() raises: "Commutative property failed for " + String(a5) + " and " + String(b5), ) - print("✓ Commutative property tests passed!") + # print("✓ Commutative property tests passed!") fn run_test_with_error_handling( @@ -358,23 +358,25 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running Decimal128 Multiplication Tests") - print("=========================================") - - run_test_with_error_handling( - test_basic_multiplication, "Basic multiplication test" - ) - run_test_with_error_handling(test_special_cases, "Special cases test") - run_test_with_error_handling( - test_negative_multiplication, "Negative number multiplication test" - ) - run_test_with_error_handling( - test_precision_scale, "Precision and scale test" - ) - run_test_with_error_handling(test_boundary_cases, "Boundary cases test") - run_test_with_error_handling( - test_commutative_property, "Commutative property test" - ) - - print("All multiplication tests passed!") + # print("=========================================") + # print("Running Decimal128 Multiplication Tests") + # print("=========================================") + + # run_test_with_error_handling( + # test_basic_multiplication, "Basic multiplication test" + # ) + # run_test_with_error_handling(test_special_cases, "Special cases test") + # run_test_with_error_handling( + # test_negative_multiplication, "Negative number multiplication test" + # ) + # run_test_with_error_handling( + # test_precision_scale, "Precision and scale test" + # ) + # run_test_with_error_handling(test_boundary_cases, "Boundary cases test") + # run_test_with_error_handling( + # test_commutative_property, "Commutative property test" + # ) + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All multiplication tests passed!") diff --git a/tests/decimal128/test_decimal128_power.mojo b/tests/decimal128/test_decimal128_power.mojo index 2df14e7..288de2c 100644 --- a/tests/decimal128/test_decimal128_power.mojo +++ b/tests/decimal128/test_decimal128_power.mojo @@ -9,7 +9,7 @@ from decimojo.decimal128.exponential import power fn test_integer_powers() raises: """Test raising a Decimal128 to an integer power.""" - print("Testing integer powers...") + # print("Testing integer powers...") # Test case 1: Positive base, positive exponent var base1 = Decimal128(2) @@ -51,12 +51,12 @@ fn test_integer_powers() raises: String(result5), "2", "0.5^-1 should be 2, got " + String(result5) ) - print("✓ Integer powers tests passed!") + # print("✓ Integer powers tests passed!") fn test_decimal_powers() raises: """Test raising a Decimal128 to a Decimal128 power.""" - print("Testing decimal powers...") + # print("Testing decimal powers...") # Test case 1: Positive base, simple fractional exponent (0.5) var base1 = Decimal128(9) @@ -94,12 +94,12 @@ fn test_decimal_powers() raises: String(result4), "0.5", "4^-0.5 should be 0.5, got " + String(result4) ) - print("✓ Decimal128 powers tests passed!") + # print("✓ Decimal128 powers tests passed!") fn test_edge_cases() raises: """Test edge cases for the power function.""" - print("Testing power edge cases...") + # print("Testing power edge cases...") # Test case 1: Zero base, positive exponent var base1 = Decimal128(0) @@ -147,7 +147,7 @@ fn test_edge_cases() raises: exception_caught, True, "(-2)^0.5 should raise an exception" ) - print("✓ Edge cases tests passed!") + # print("✓ Edge cases tests passed!") fn run_test_with_error_handling( @@ -168,12 +168,14 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running Decimal128 Power Function Tests") - print("=========================================") + # print("=========================================") + # print("Running Decimal128 Power Function Tests") + # print("=========================================") - run_test_with_error_handling(test_integer_powers, "Integer powers test") - run_test_with_error_handling(test_decimal_powers, "Decimal128 powers test") - run_test_with_error_handling(test_edge_cases, "Edge cases test") + # run_test_with_error_handling(test_integer_powers, "Integer powers test") + # run_test_with_error_handling(test_decimal_powers, "Decimal128 powers test") + # run_test_with_error_handling(test_edge_cases, "Edge cases test") - print("All power function tests passed!") + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All power function tests passed!") diff --git a/tests/decimal128/test_decimal128_quantize.mojo b/tests/decimal128/test_decimal128_quantize.mojo index 89c8a27..bfbf91c 100644 --- a/tests/decimal128/test_decimal128_quantize.mojo +++ b/tests/decimal128/test_decimal128_quantize.mojo @@ -11,7 +11,7 @@ from decimojo.prelude import dm, Decimal128, RoundingMode fn test_basic_quantization() raises: """Test basic quantization with different scales.""" - print("Testing basic quantization...") + # print("Testing basic quantization...") var pydecimal = Python.import_module("decimal") pydecimal.getcontext().prec = 28 # Match DeciMojo's precision @@ -82,12 +82,12 @@ fn test_basic_quantization() raises: "Quantizing 9.876 to 1.00 gave incorrect result: " + String(result5), ) - print("✓ Basic quantization tests passed!") + # print("✓ Basic quantization tests passed!") fn test_rounding_modes() raises: """Test quantization with different rounding modes.""" - print("Testing quantization with different rounding modes...") + # print("Testing quantization with different rounding modes...") var pydecimal = Python.import_module("decimal") pydecimal.getcontext().prec = 28 @@ -159,12 +159,12 @@ fn test_rounding_modes() raises: "ROUND_UP with negative gave incorrect result: " + String(result6), ) - print("✓ Rounding mode tests passed!") + # print("✓ Rounding mode tests passed!") fn test_edge_cases() raises: """Test edge cases for quantization.""" - print("Testing quantization edge cases...") + # print("Testing quantization edge cases...") var pydecimal = Python.import_module("decimal") pydecimal.getcontext().prec = 28 @@ -238,12 +238,12 @@ fn test_edge_cases() raises: + String(result5), ) - print("✓ Edge cases tests passed!") + # print("✓ Edge cases tests passed!") fn test_special_cases() raises: """Test special cases for quantization.""" - print("Testing special quantization cases...") + # print("Testing special quantization cases...") var pydecimal = Python.import_module("decimal") pydecimal.getcontext().prec = 28 @@ -316,12 +316,12 @@ fn test_special_cases() raises: "Quantizing to integer gave incorrect result: " + String(result5), ) - print("✓ Special cases tests passed!") + # print("✓ Special cases tests passed!") fn test_quantize_exceptions() raises: """Test exception conditions for quantize().""" - print("Testing quantize exceptions...") + # print("Testing quantize exceptions...") var pydecimal = Python.import_module("decimal") pydecimal.getcontext().prec = 28 @@ -351,13 +351,13 @@ fn test_quantize_exceptions() raises: ), ) - print("✓ Exception tests passed!") + # print("✓ Exception tests passed!") fn test_comprehensive_comparison() raises: """Test a wide range of values to ensure compatibility with Python's decimal. """ - print("Testing comprehensive comparison with Python's decimal...") + # print("Testing comprehensive comparison with Python's decimal...") # Set up Python decimal var pydecimal = Python.import_module("decimal") @@ -376,171 +376,169 @@ fn test_comprehensive_comparison() raises: # Instead of looping through lists, test each case explicitly # Test case 1: Zero with integer quantizer - test_single_quantize_case( + run_single_quantize_case( "0", "1", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "0", "1", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "0", "1", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case("0", "1", mojo_round_up, py_round_up, pydecimal) + run_single_quantize_case("0", "1", mojo_round_up, py_round_up, pydecimal) # Test case 2: Decimal128 with 2 decimal places quantizer - test_single_quantize_case( + run_single_quantize_case( "1.23456", "0.01", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "1.23456", "0.01", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "1.23456", "0.01", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "1.23456", "0.01", mojo_round_up, py_round_up, pydecimal ) # Test case 3: Decimal128 with 1 decimal place quantizer - test_single_quantize_case( + run_single_quantize_case( "9.999", "0.1", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "9.999", "0.1", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "9.999", "0.1", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "9.999", "0.1", mojo_round_up, py_round_up, pydecimal ) # Test case 4: Negative value with integer quantizer - test_single_quantize_case( + run_single_quantize_case( "-0.5", "1", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "-0.5", "1", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "-0.5", "1", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( - "-0.5", "1", mojo_round_up, py_round_up, pydecimal - ) + run_single_quantize_case("-0.5", "1", mojo_round_up, py_round_up, pydecimal) # Test case 5: Small value with larger precision - test_single_quantize_case( + run_single_quantize_case( "0.0001", "0.01", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "0.0001", "0.01", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "0.0001", "0.01", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "0.0001", "0.01", mojo_round_up, py_round_up, pydecimal ) # Test case 6: Large value with integer quantizer - test_single_quantize_case( + run_single_quantize_case( "1234.5678", "1", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "1234.5678", "1", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "1234.5678", "1", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "1234.5678", "1", mojo_round_up, py_round_up, pydecimal ) # Test case 7: Rounding to larger precision - test_single_quantize_case( + run_single_quantize_case( "99.99", "100", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "99.99", "100", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "99.99", "100", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "99.99", "100", mojo_round_up, py_round_up, pydecimal ) # Test case 8: Very small value with small precision - test_single_quantize_case( + run_single_quantize_case( "0.0000001", "0.00001", mojo_round_half_even, py_round_half_even, pydecimal, ) - test_single_quantize_case( + run_single_quantize_case( "0.0000001", "0.00001", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "0.0000001", "0.00001", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "0.0000001", "0.00001", mojo_round_up, py_round_up, pydecimal ) # Test case 9: Large value with 1 decimal place - test_single_quantize_case( + run_single_quantize_case( "987654.321", "0.1", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "987654.321", "0.1", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "987654.321", "0.1", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "987654.321", "0.1", mojo_round_up, py_round_up, pydecimal ) # Test case 10: Testing banker's rounding - test_single_quantize_case( + run_single_quantize_case( "1.5", "1", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "2.5", "1", mojo_round_half_even, py_round_half_even, pydecimal ) # Test case 11: Testing rounding to thousands - test_single_quantize_case( + run_single_quantize_case( "10000", "1000", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "10000", "1000", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "10000", "1000", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "10000", "1000", mojo_round_up, py_round_up, pydecimal ) # Test case 12: Rounding up very close value - test_single_quantize_case( + run_single_quantize_case( "0.999999", "1", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "0.999999", "1", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "0.999999", "1", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "0.999999", "1", mojo_round_up, py_round_up, pydecimal ) # Test case 13: Pi with very high precision - test_single_quantize_case( + run_single_quantize_case( "3.14159265358979323", "0.00000000001", mojo_round_half_even, @@ -549,33 +547,33 @@ fn test_comprehensive_comparison() raises: ) # Test case 14: Negative value rounding - test_single_quantize_case( + run_single_quantize_case( "-999.9", "1", mojo_round_half_even, py_round_half_even, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "-999.9", "1", mojo_round_half_up, py_round_half_up, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "-999.9", "1", mojo_round_down, py_round_down, pydecimal ) - test_single_quantize_case( + run_single_quantize_case( "-999.9", "1", mojo_round_up, py_round_up, pydecimal ) # Test case 15: Zero with trailing zeros - test_single_quantize_case( + run_single_quantize_case( "0.0", "0.0000", mojo_round_half_even, py_round_half_even, pydecimal ) # Test case 16: Integer to integer - test_single_quantize_case( + run_single_quantize_case( "123", "1", mojo_round_half_even, py_round_half_even, pydecimal ) - print("✓ Comprehensive comparison tests passed!") + # print("✓ Comprehensive comparison tests passed!") -fn test_single_quantize_case( +fn run_single_quantize_case( value_str: String, quant_str: String, mojo_mode: RoundingMode, @@ -627,21 +625,23 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running Decimal128.quantize() Tests") - print("=========================================") - - run_test_with_error_handling( - test_basic_quantization, "Basic quantization test" - ) - run_test_with_error_handling(test_rounding_modes, "Rounding modes test") - run_test_with_error_handling(test_edge_cases, "Edge cases test") - run_test_with_error_handling(test_special_cases, "Special cases test") - run_test_with_error_handling( - test_quantize_exceptions, "Exception handling test" - ) - run_test_with_error_handling( - test_comprehensive_comparison, "Comprehensive comparison test" - ) - - print("All Decimal128.quantize() tests passed!") + # print("=========================================") + # print("Running Decimal128.quantize() Tests") + # print("=========================================") + + # run_test_with_error_handling( + # test_basic_quantization, "Basic quantization test" + # ) + # run_test_with_error_handling(test_rounding_modes, "Rounding modes test") + # run_test_with_error_handling(test_edge_cases, "Edge cases test") + # run_test_with_error_handling(test_special_cases, "Special cases test") + # run_test_with_error_handling( + # test_quantize_exceptions, "Exception handling test" + # ) + # run_test_with_error_handling( + # test_comprehensive_comparison, "Comprehensive comparison test" + # ) + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All Decimal128.quantize() tests passed!") diff --git a/tests/decimal128/test_decimal128_root.mojo b/tests/decimal128/test_decimal128_root.mojo index 70d2f94..01f02f6 100644 --- a/tests/decimal128/test_decimal128_root.mojo +++ b/tests/decimal128/test_decimal128_root.mojo @@ -11,7 +11,7 @@ from decimojo.decimal128.exponential import root fn test_basic_root_calculations() raises: """Test basic root calculations for common values.""" - print("Testing basic root calculations...") + # print("Testing basic root calculations...") # Test case 1: Square root (n=2) var num1 = Decimal128(9) @@ -50,12 +50,12 @@ fn test_basic_root_calculations() raises: "∛10 should be approximately 2.154..., got " + String(result5), ) - print("✓ Basic root calculations tests passed!") + # print("✓ Basic root calculations tests passed!") fn test_fractional_inputs() raises: """Test root calculations with fractional inputs.""" - print("Testing root calculations with fractional inputs...") + # print("Testing root calculations with fractional inputs...") # Test case 1: Square root of decimal var num1 = Decimal128("0.25") @@ -87,12 +87,12 @@ fn test_fractional_inputs() raises: "√0.5 should be approximately 0.7071..., got " + String(result4), ) - print("✓ Fractional input tests passed!") + # print("✓ Fractional input tests passed!") fn test_edge_cases() raises: """Test edge cases for the root function.""" - print("Testing root edge cases...") + # print("Testing root edge cases...") # Test case 1: Root of 0 var zero = Decimal128(0) @@ -129,12 +129,12 @@ fn test_edge_cases() raises: + String(result4), ) - print("✓ Edge cases tests passed!") + # print("✓ Edge cases tests passed!") fn test_error_conditions() raises: """Test error conditions for the root function.""" - print("Testing root error conditions...") + # print("Testing root error conditions...") # Test case 1: 0th root (should raise error) var num1 = Decimal128(10) @@ -181,12 +181,12 @@ fn test_error_conditions() raises: String(result4), "-2", "∛-8 should be -2, got " + String(result4) ) - print("✓ Error conditions tests passed!") + # print("✓ Error conditions tests passed!") fn test_precision() raises: """Test precision of root calculations.""" - print("Testing precision of root calculations...") + # print("Testing precision of root calculations...") # Test case 1: High precision square root var num1 = Decimal128(2) @@ -212,12 +212,12 @@ fn test_precision() raises: "√5 should match known value starting with 2.236067977499789696...", ) - print("✓ Precision tests passed!") + # print("✓ Precision tests passed!") fn test_mathematical_identities() raises: """Test mathematical identities involving roots.""" - print("Testing mathematical identities involving roots...") + # print("Testing mathematical identities involving roots...") # Test case 1: (√x)^2 = x var x1 = Decimal128(7) @@ -257,7 +257,7 @@ fn test_mathematical_identities() raises: "x^(1/n) should equal nth root of x within tolerance", ) - print("✓ Mathematical identities tests passed!") + # print("✓ Mathematical identities tests passed!") fn run_test_with_error_handling( @@ -278,21 +278,23 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running Root Function Tests") - print("=========================================") - - run_test_with_error_handling( - test_basic_root_calculations, "Basic root calculations test" - ) - run_test_with_error_handling( - test_fractional_inputs, "Fractional inputs test" - ) - run_test_with_error_handling(test_edge_cases, "Edge cases test") - run_test_with_error_handling(test_error_conditions, "Error conditions test") - run_test_with_error_handling(test_precision, "Precision test") - run_test_with_error_handling( - test_mathematical_identities, "Mathematical identities test" - ) - - print("All root function tests passed!") + # print("=========================================") + # print("Running Root Function Tests") + # print("=========================================") + + # run_test_with_error_handling( + # test_basic_root_calculations, "Basic root calculations test" + # ) + # run_test_with_error_handling( + # test_fractional_inputs, "Fractional inputs test" + # ) + # run_test_with_error_handling(test_edge_cases, "Edge cases test") + # run_test_with_error_handling(test_error_conditions, "Error conditions test") + # run_test_with_error_handling(test_precision, "Precision test") + # run_test_with_error_handling( + # test_mathematical_identities, "Mathematical identities test" + # ) + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All root function tests passed!") diff --git a/tests/decimal128/test_decimal128_round.mojo b/tests/decimal128/test_decimal128_round.mojo index 0fd9b2e..66a92c0 100644 --- a/tests/decimal128/test_decimal128_round.mojo +++ b/tests/decimal128/test_decimal128_round.mojo @@ -6,7 +6,7 @@ import testing fn test_basic_rounding() raises: - print("Testing basic decimal rounding...") + # print("Testing basic decimal rounding...") # Test case 1: Round to 2 decimal places (banker's rounding) var d1 = Decimal128("123.456") @@ -34,11 +34,11 @@ fn test_basic_rounding() raises: String(result4), "123.45", "Rounding to same precision" ) - print("Basic decimal rounding tests passed!") + # print("Basic decimal rounding tests passed!") fn test_different_rounding_modes() raises: - print("Testing different rounding modes...") + # print("Testing different rounding modes...") var test_value = Decimal128("123.456") @@ -58,11 +58,11 @@ fn test_different_rounding_modes() raises: var result4 = test_value.round(2, RoundingMode.half_even()) testing.assert_equal(String(result4), "123.46", "Rounding half even") - print("Rounding mode tests passed!") + # print("Rounding mode tests passed!") fn test_edge_cases() raises: - print("Testing edge cases for rounding...") + # print("Testing edge cases for rounding...") # Test case 1: Rounding exactly 0.5 with different modes var half_value = Decimal128("123.5") @@ -147,11 +147,11 @@ fn test_edge_cases() raises: "Rounding from maximum precision", ) - print("Edge case tests passed!") + # print("Edge case tests passed!") fn test_rounding_consistency() raises: - print("Testing rounding consistency...") + # print("Testing rounding consistency...") # Test case: Verify that rounding is consistent across different ways of # constructing the same value @@ -179,22 +179,24 @@ fn test_rounding_consistency() raises: "Consistency with sequential rounding", ) - print("Rounding consistency tests passed!") + # print("Rounding consistency tests passed!") fn main() raises: - print("Running decimal rounding tests") + # print("Running decimal rounding tests") - # Run basic rounding tests - test_basic_rounding() + # # Run basic rounding tests + # test_basic_rounding() - # Run tests with different rounding modes - test_different_rounding_modes() + # # Run tests with different rounding modes + # test_different_rounding_modes() - # Run edge case tests - test_edge_cases() + # # Run edge case tests + # test_edge_cases() - # Run rounding consistency tests - test_rounding_consistency() + # # Run rounding consistency tests + # test_rounding_consistency() - print("All decimal rounding tests passed!") + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All decimal rounding tests passed!") diff --git a/tests/decimal128/test_decimal128_sqrt.mojo b/tests/decimal128/test_decimal128_sqrt.mojo index 6de0488..cc430ae 100644 --- a/tests/decimal128/test_decimal128_sqrt.mojo +++ b/tests/decimal128/test_decimal128_sqrt.mojo @@ -6,7 +6,7 @@ import testing fn test_perfect_squares() raises: - print("Testing square root of perfect squares...") + # print("Testing square root of perfect squares...") # Test case 1: sqrt(1) = 1 try: @@ -212,11 +212,11 @@ fn test_perfect_squares() raises: print("Exception: " + String(e)) raise e - print("Perfect square tests passed!") + # print("Perfect square tests passed!") fn test_non_perfect_squares() raises: - print("Testing square root of non-perfect squares...") + # print("Testing square root of non-perfect squares...") # Test case 1 try: @@ -327,11 +327,11 @@ fn test_non_perfect_squares() raises: + result_str7, ) - print("Non-perfect square tests passed!") + # print("Non-perfect square tests passed!") fn test_decimal_values() raises: - print("Testing square root of decimal values...") + # print("Testing square root of decimal values...") # Test case 1 try: @@ -407,11 +407,11 @@ fn test_decimal_values() raises: "sqrt(" + String(d7) + ") should be " + expected7, ) - print("Decimal128 value tests passed!") + # print("Decimal128 value tests passed!") fn test_edge_cases() raises: - print("Testing edge cases...") + # print("Testing edge cases...") # Test sqrt(0) = 0 try: @@ -485,11 +485,11 @@ fn test_edge_cases() raises: ) raise e - print("Edge cases tests passed!") + # print("Edge cases tests passed!") fn test_precision() raises: - print("Testing precision of square root calculations...") + # print("Testing precision of square root calculations...") var expected_sqrt2 = ( "1.414213562373095048801688724" # First 10 decimal places of sqrt(2) ) @@ -526,11 +526,11 @@ fn test_precision() raises: ), ) - print("Precision tests passed!") + # print("Precision tests passed!") fn test_mathematical_identities() raises: - print("Testing mathematical identities...") + # print("Testing mathematical identities...") # Test that sqrt(x)² = x - Expanded for each test number # Test number 1 @@ -724,11 +724,11 @@ fn test_mathematical_identities() raises: + ")", ) - print("Mathematical identity tests passed!") + # print("Mathematical identity tests passed!") fn test_sqrt_performance() raises: - print("Testing square root performance and convergence...") + # print("Testing square root performance and convergence...") # Test case 1 try: @@ -907,7 +907,7 @@ fn test_sqrt_performance() raises: ) raise e - print("Performance and convergence tests passed!") + # print("Performance and convergence tests passed!") fn run_test_with_error_handling( @@ -928,21 +928,23 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running comprehensive Decimal128 square root tests") - - run_test_with_error_handling(test_perfect_squares, "Perfect squares test") - run_test_with_error_handling( - test_non_perfect_squares, "Non-perfect squares test" - ) - run_test_with_error_handling(test_decimal_values, "Decimal128 values test") - run_test_with_error_handling(test_edge_cases, "Edge cases test") - run_test_with_error_handling(test_precision, "Precision test") - run_test_with_error_handling( - test_mathematical_identities, "Mathematical identities test" - ) - run_test_with_error_handling( - test_sqrt_performance, "Performance and convergence test" - ) - - print("All square root tests passed!") + # print("=========================================") + # print("Running comprehensive Decimal128 square root tests") + + # run_test_with_error_handling(test_perfect_squares, "Perfect squares test") + # run_test_with_error_handling( + # test_non_perfect_squares, "Non-perfect squares test" + # ) + # run_test_with_error_handling(test_decimal_values, "Decimal128 values test") + # run_test_with_error_handling(test_edge_cases, "Edge cases test") + # run_test_with_error_handling(test_precision, "Precision test") + # run_test_with_error_handling( + # test_mathematical_identities, "Mathematical identities test" + # ) + # run_test_with_error_handling( + # test_sqrt_performance, "Performance and convergence test" + # ) + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All square root tests passed!") diff --git a/tests/decimal128/test_decimal128_to_float.mojo b/tests/decimal128/test_decimal128_to_float.mojo index ff67c36..5328bc0 100644 --- a/tests/decimal128/test_decimal128_to_float.mojo +++ b/tests/decimal128/test_decimal128_to_float.mojo @@ -9,7 +9,7 @@ from decimojo.prelude import dm, Decimal128, RoundingMode fn test_basic_integer_conversions() raises: """Test conversion of basic integers to float.""" - print("Testing basic integer conversions to float...") + # print("Testing basic integer conversions to float...") # Test case 1: Zero var zero = Decimal128(0) @@ -37,12 +37,12 @@ fn test_basic_integer_conversions() raises: var large_int_float = Float64(large_int) testing.assert_equal(large_int_float, 123456.0) - print("✓ Basic integer conversions to float passed!") + # print("✓ Basic integer conversions to float passed!") fn test_decimal_conversions() raises: """Test conversion of decimal values to float.""" - print("Testing decimal conversions to float...") + # print("Testing decimal conversions to float...") # Test case 5: Simple decimal var simple_dec = Decimal128("3.14") @@ -69,12 +69,12 @@ fn test_decimal_conversions() raises: var repeating_float = Float64(repeating) testing.assert_true(abs(repeating_float - 0.33333333333333) < 1e-14) - print("✓ Decimal128 conversions to float passed!") + # print("✓ Decimal128 conversions to float passed!") fn test_negative_conversions() raises: """Test conversion of negative values to float.""" - print("Testing negative value conversions to float...") + # print("Testing negative value conversions to float...") # Test case 9: Negative integer var neg_int = Decimal128("-123") @@ -93,12 +93,12 @@ fn test_negative_conversions() raises: neg_zero_float, 0.0 ) # Note: -0.0 equals 0.0 in most comparisons - print("✓ Negative value conversions to float passed!") + # print("✓ Negative value conversions to float passed!") fn test_edge_cases() raises: """Test edge cases for conversion to float.""" - print("Testing edge cases for float conversion...") + # print("Testing edge cases for float conversion...") # Test case 12: Very small positive number var very_small = Decimal128("0." + "0" * 20 + "1") # 0.00000000000000000001 @@ -131,12 +131,12 @@ fn test_edge_cases() raises: "Large number should be converted with expected float precision loss", ) - print("✓ Edge case conversions to float passed!") + # print("✓ Edge case conversions to float passed!") fn test_special_values() raises: """Test special values for conversion to float.""" - print("Testing special values for float conversion...") + # print("Testing special values for float conversion...") # Test case 16: Decimal128 with trailing zeros var trailing_zeros = Decimal128("5.0000") @@ -177,7 +177,7 @@ fn test_special_values() raises: "Binary float approximation of decimal 0.1 should be very close", ) - print("✓ Special value conversions to float passed!") + # print("✓ Special value conversions to float passed!") fn run_test_with_error_handling( @@ -198,20 +198,22 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running 20 tests for Decimal128.__float__()") - print("=========================================") - - run_test_with_error_handling( - test_basic_integer_conversions, "Basic integer conversions" - ) - run_test_with_error_handling( - test_decimal_conversions, "Decimal128 conversions" - ) - run_test_with_error_handling( - test_negative_conversions, "Negative value conversions" - ) - run_test_with_error_handling(test_edge_cases, "Edge cases") - run_test_with_error_handling(test_special_values, "Special values") - - print("All 20 Decimal128.__float__() tests passed!") + # print("=========================================") + # print("Running 20 tests for Decimal128.__float__()") + # print("=========================================") + + # run_test_with_error_handling( + # test_basic_integer_conversions, "Basic integer conversions" + # ) + # run_test_with_error_handling( + # test_decimal_conversions, "Decimal128 conversions" + # ) + # run_test_with_error_handling( + # test_negative_conversions, "Negative value conversions" + # ) + # run_test_with_error_handling(test_edge_cases, "Edge cases") + # run_test_with_error_handling(test_special_values, "Special values") + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All 20 Decimal128.__float__() tests passed!") diff --git a/tests/decimal128/test_decimal128_to_int.mojo b/tests/decimal128/test_decimal128_to_int.mojo index f2bf4b7..9c4b41f 100644 --- a/tests/decimal128/test_decimal128_to_int.mojo +++ b/tests/decimal128/test_decimal128_to_int.mojo @@ -9,49 +9,51 @@ import time fn test_int_conversion() raises: - print("------------------------------------------------------") - print("--- Testing Int Conversion ---") + # print("------------------------------------------------------") + # print("--- Testing Int Conversion ---") # Test positive integer var d1 = Decimal128(123) var i1 = Int(d1) - print("Int(123) =", i1) + # print("Int(123) =", i1) testing.assert_equal(i1, 123) # Test negative integer var d2 = Decimal128(-456) var i2 = Int(d2) - print("Int(-456) =", i2) + # print("Int(-456) =", i2) testing.assert_equal(i2, -456) # Test zero var d3 = Decimal128(0) var i3 = Int(d3) - print("Int(0) =", i3) + # print("Int(0) =", i3) testing.assert_equal(i3, 0) # Test decimal truncation var d4 = Decimal128(789987, 3) var i4 = Int(d4) - print("Int(789.987) =", i4) + # print("Int(789.987) =", i4) testing.assert_equal(i4, 789) # Test negative decimal truncation var d5 = Decimal128(-123456, 3) var i5 = Int(d5) - print("Int(-123.456) =", i5) + # print("Int(-123.456) =", i5) testing.assert_equal(i5, -123) # Test large number var d6 = Decimal128(9999999999) var i6 = Int(d6) - print("Int(9999999999) =", i6) + # print("Int(9999999999) =", i6) testing.assert_equal(i6, 9999999999) fn main() raises: - print("Starting Decimal128 conversion __int__ tests...") + # print("Starting Decimal128 conversion __int__ tests...") - test_int_conversion() + # test_int_conversion() - print("\nAll tests completed!") + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("\nAll tests completed!") diff --git a/tests/decimal128/test_decimal128_to_string.mojo b/tests/decimal128/test_decimal128_to_string.mojo index 0253d09..e717296 100644 --- a/tests/decimal128/test_decimal128_to_string.mojo +++ b/tests/decimal128/test_decimal128_to_string.mojo @@ -9,43 +9,45 @@ import time fn test_str_conversion() raises: - print("------------------------------------------------------") - print("--- Testing String Conversion ---") + # print("------------------------------------------------------") + # print("--- Testing String Conversion ---") # Test positive number var d1 = Decimal128("123.456") var s1 = String(d1) - print("String(123.456) =", s1) + # print("String(123.456) =", s1) testing.assert_equal(s1, "123.456") # Test negative number var d2 = Decimal128("-789.012") var s2 = String(d2) - print("String(-789.012) =", s2) + # print("String(-789.012) =", s2) testing.assert_equal(s2, "-789.012") # Test zero var d3 = Decimal128(0) var s3 = String(d3) - print("String(0) =", s3) + # print("String(0) =", s3) testing.assert_equal(s3, "0") # Test large number with precision var d4 = Decimal128("9876543210.0123456789") var s4 = String(d4) - print("String(9876543210.0123456789) =", s4) + # print("String(9876543210.0123456789) =", s4) testing.assert_equal(s4, "9876543210.0123456789") # Test small number var d5 = Decimal128("0.0000000001") var s5 = String(d5) - print("String(0.0000000001) =", s5) + # print("String(0.0000000001) =", s5) testing.assert_equal(s5, "0.0000000001") fn main() raises: - print("Starting Decimal128 conversion __str__ tests...") + # print("Starting Decimal128 conversion __str__ tests...") - test_str_conversion() + # test_str_conversion() - print("\nAll tests completed!") + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("\nAll tests completed!") diff --git a/tests/decimal128/test_decimal128_truncate_divide.mojo b/tests/decimal128/test_decimal128_truncate_divide.mojo index 966caa6..00e98e9 100644 --- a/tests/decimal128/test_decimal128_truncate_divide.mojo +++ b/tests/decimal128/test_decimal128_truncate_divide.mojo @@ -9,7 +9,7 @@ from decimojo.prelude import dm, Decimal128, RoundingMode fn test_basic_floor_division() raises: """Test basic integer floor division.""" - print("Testing basic floor division...") + # print("Testing basic floor division...") # Test case 1: Simple integer division with no remainder var a1 = Decimal128(10) @@ -55,12 +55,12 @@ fn test_basic_floor_division() raises: "10.75 // 1.5 should equal 7, got " + String(result5), ) - print("✓ Basic floor division tests passed!") + # print("✓ Basic floor division tests passed!") fn test_negative_floor_division() raises: """Test floor division involving negative numbers.""" - print("Testing floor division with negative numbers...") + # print("Testing floor division with negative numbers...") # Test case 1: Negative // Positive var a1 = Decimal128(-10) @@ -120,12 +120,12 @@ fn test_negative_floor_division() raises: "-10.5 // -3.5 should equal 3, got " + String(result6), ) - print("✓ Negative number floor division tests passed!") + # print("✓ Negative number floor division tests passed!") fn test_edge_cases() raises: """Test edge cases for floor division.""" - print("Testing floor division edge cases...") + # print("Testing floor division edge cases...") # Test case 1: Division by 1 var a1 = Decimal128(10) @@ -190,12 +190,12 @@ fn test_edge_cases() raises: String(result7), "0", "0.0000001 // 0.0000002 should equal 0" ) - print("✓ Edge cases tests passed!") + # print("✓ Edge cases tests passed!") fn test_mathematical_relationships() raises: """Test mathematical relationships involving floor division.""" - print("Testing mathematical relationships...") + # print("Testing mathematical relationships...") # Test case 1: a = (a // b) * b + (a % b) var a1 = Decimal128(10) @@ -243,7 +243,7 @@ fn test_mathematical_relationships() raises: "Relationship (a // b) * b ≤ a < (a // b + 1) * b should hold", ) - print("✓ Mathematical relationships tests passed!") + # print("✓ Mathematical relationships tests passed!") fn run_test_with_error_handling( @@ -264,19 +264,21 @@ fn run_test_with_error_handling( fn main() raises: - print("=========================================") - print("Running Decimal128 Floor Division Tests") - print("=========================================") - - run_test_with_error_handling( - test_basic_floor_division, "Basic floor division test" - ) - run_test_with_error_handling( - test_negative_floor_division, "Negative number floor division test" - ) - run_test_with_error_handling(test_edge_cases, "Edge cases test") - run_test_with_error_handling( - test_mathematical_relationships, "Mathematical relationships test" - ) - - print("All floor division tests passed!") + # print("=========================================") + # print("Running Decimal128 Floor Division Tests") + # print("=========================================") + + # run_test_with_error_handling( + # test_basic_floor_division, "Basic floor division test" + # ) + # run_test_with_error_handling( + # test_negative_floor_division, "Negative number floor division test" + # ) + # run_test_with_error_handling(test_edge_cases, "Edge cases test") + # run_test_with_error_handling( + # test_mathematical_relationships, "Mathematical relationships test" + # ) + + testing.TestSuite.discover_tests[__functions_in_module()]().run() + + # print("All floor division tests passed!") diff --git a/tests/decimal128/test_decimal128_utility.mojo b/tests/decimal128/test_decimal128_utility.mojo index 79d7507..de86534 100644 --- a/tests/decimal128/test_decimal128_utility.mojo +++ b/tests/decimal128/test_decimal128_utility.mojo @@ -2,6 +2,7 @@ Tests for the utility functions in the decimojo.utility module. """ +import testing from testing import assert_equal, assert_true from decimojo.prelude import dm, Decimal128, RoundingMode @@ -15,7 +16,7 @@ from decimojo.decimal128.utility import ( fn test_number_of_digits() raises: """Tests for number_of_digits function.""" - print("Testing number_of_digits...") + # print("Testing number_of_digits...") # Test with simple UInt128 values assert_equal(number_of_digits(UInt128(0)), 0) @@ -42,12 +43,12 @@ fn test_number_of_digits() raises: var very_large = UInt256(Decimal128.MAX_AS_UINT128) * UInt256(10) assert_equal(number_of_digits(very_large), 30) - print("✓ All number_of_digits tests passed!") + # print("✓ All number_of_digits tests passed!") fn test_truncate_to_max_below_max() raises: """Test truncate_to_max with values below MAX_AS_UINT128.""" - print("Testing truncate_to_max with values below MAX...") + # print("Testing truncate_to_max with values below MAX...") # Test with values that should remain unchanged var small_value = UInt128(123456) @@ -65,12 +66,12 @@ fn test_truncate_to_max_below_max() raises: var max_value_256 = UInt256(Decimal128.MAX_AS_UINT128) assert_equal(truncate_to_max(max_value_256), max_value_256) - print("✓ All truncate_to_max tests with values below MAX passed!") + # print("✓ All truncate_to_max tests with values below MAX passed!") fn test_truncate_to_max_above_max() raises: """Test truncate_to_max with values above MAX_AS_UINT128.""" - print("Testing truncate_to_max with values above MAX...") + # print("Testing truncate_to_max with values above MAX...") # Test with value MAX + 1 (should round appropriately) var max_plus_1 = UInt256(Decimal128.MAX_AS_UINT128) + UInt256(1) @@ -120,13 +121,13 @@ fn test_truncate_to_max_above_max() raises: truncate_to_max(much_larger) <= UInt256(Decimal128.MAX_AS_UINT128) ) - print("✓ All truncate_to_max tests with values above MAX passed!") + # print("✓ All truncate_to_max tests with values above MAX passed!") fn test_truncate_to_max_banker_rounding() raises: """Test the banker's rounding aspect of truncate_to_max particularly carefully. """ - print("Testing truncate_to_max banker's rounding...") + # print("Testing truncate_to_max banker's rounding...") # For testing larger numbers, we'll use direct numeric literals where possible @@ -164,7 +165,7 @@ fn test_truncate_to_max_banker_rounding() raises: var case4_expected = UInt256(79228162514264337593543950332) assert_equal(truncate_to_max(case4), case4_expected) - print("✓ All truncate_to_max banker's rounding tests passed!") + # print("✓ All truncate_to_max banker's rounding tests passed!") fn test_round_to_keep_first_n_digits() raises: @@ -221,12 +222,12 @@ fn test_round_to_keep_first_n_digits() raises: var case9_expected = UInt256(987654321098765432) assert_equal(round_to_keep_first_n_digits(case9, 18), case9_expected) - print("✓ All round_to_keep_first_n_digits tests passed!") + # print("✓ All round_to_keep_first_n_digits tests passed!") fn test_bitcast() raises: """Test the bitcast utility function for direct memory bit conversion.""" - print("Testing utility.bitcast...") + # print("Testing utility.bitcast...") # Test case 1: Basic decimal with fractional part var original = Decimal128("123.456") @@ -264,33 +265,11 @@ fn test_bitcast() raises: var test_bits = bitcast[DType.uint128](test_decimal) assert_equal(test_coef, test_bits) - print("✓ All bitcast tests passed!") - - -fn test_all() raises: - """Run all tests for the utility module.""" - print("\n=== Running Utility Module Tests ===\n") - - test_number_of_digits() - print() - - test_truncate_to_max_below_max() - print() - - test_truncate_to_max_above_max() - print() - - test_truncate_to_max_banker_rounding() - print() - - test_bitcast() - print() - - test_round_to_keep_first_n_digits() - print() - - print("✓✓✓ All utility module tests passed! ✓✓✓") + # print("✓ All bitcast tests passed!") fn main() raises: - test_all() + """Run all tests for the utility module.""" + # test_all() + testing.TestSuite.discover_tests[__functions_in_module()]().run() + # print("✓✓✓ All utility module tests passed! ✓✓✓") diff --git a/tests/test_all.sh b/tests/test_all.sh new file mode 100644 index 0000000..0e457e7 --- /dev/null +++ b/tests/test_all.sh @@ -0,0 +1,5 @@ +for dir in bigdecimal bigint biguint decimal128; do + for f in tests/$dir/*.mojo; do + pixi run mojo run -I src -D ASSERT=all "$f" + done +done \ No newline at end of file diff --git a/tests/test_big.sh b/tests/test_big.sh new file mode 100644 index 0000000..03594cd --- /dev/null +++ b/tests/test_big.sh @@ -0,0 +1,5 @@ +for dir in bigdecimal bigint biguint; do + for f in tests/$dir/*.mojo; do + pixi run mojo run -I src -D ASSERT=all "$f" + done +done \ No newline at end of file