diff --git a/src/decimojo/__init__.mojo b/src/decimojo/__init__.mojo index 5b917c3..414cbbb 100644 --- a/src/decimojo/__init__.mojo +++ b/src/decimojo/__init__.mojo @@ -29,7 +29,14 @@ from .decimal.decimal import Decimal, Dec from .bigint.bigint import BigInt, BInt from .biguint.biguint import BigUInt, BUInt from .bigdecimal.bigdecimal import BigDecimal, BigDec, BDec -from .rounding_mode import RoundingMode, RM +from .rounding_mode import ( + RoundingMode, + RM, + ROUND_DOWN, + ROUND_HALF_UP, + ROUND_HALF_EVEN, + ROUND_UP, +) # Core functions from .decimal.arithmetics import ( diff --git a/src/decimojo/bigdecimal/bigdecimal.mojo b/src/decimojo/bigdecimal/bigdecimal.mojo index 3013312..9c7d744 100644 --- a/src/decimojo/bigdecimal/bigdecimal.mojo +++ b/src/decimojo/bigdecimal/bigdecimal.mojo @@ -739,9 +739,30 @@ struct BigDecimal( return decimojo.bigdecimal.exponential.power(self, exponent, precision) @always_inline - fn round(self, ndigits: Int, rounding_mode: RoundingMode) raises -> Self: - """Rounds the number to the specified precision. - See `bigdecimal.rounding.round()` for more information. + fn round( + self, + ndigits: Int, + rounding_mode: RoundingMode = RoundingMode.ROUND_HALF_EVEN, + ) raises -> Self: + """Rounds the number to the specified number of decimal places. + + Args: + ndigits: Number of decimal places to round to. + rounding_mode: Rounding mode to use. Default is `ROUND_HALF_EVEN`. + RoundingMode.ROUND_DOWN: Round down. + RoundingMode.ROUND_UP: Round up. + RoundingMode.ROUND_HALF_UP: Round half up. + RoundingMode.ROUND_HALF_EVEN: Round half even. + + Notes: + If `ndigits` is negative, the last `ndigits` digits of the integer part of + the number will be dropped and the scale will be `ndigits`. + Examples: + round(123.456, 2) -> 123.46 + round(123.456, -1) -> 12E+1 + round(123.456, -2) -> 1E+2 + round(123.456, -3) -> 0E+3 + round(678.890, -3) -> 1E+3 """ return decimojo.bigdecimal.rounding.round(self, ndigits, rounding_mode) diff --git a/src/decimojo/bigdecimal/rounding.mojo b/src/decimojo/bigdecimal/rounding.mojo index 01f921f..cdf3b36 100644 --- a/src/decimojo/bigdecimal/rounding.mojo +++ b/src/decimojo/bigdecimal/rounding.mojo @@ -42,15 +42,14 @@ fn round( RoundingMode.ROUND_HALF_EVEN: Round half even. Notes: - - If `ndigits` is negative, the last `ndigits` digits of the integer part of - the number will be dropped and the scale will be `ndigits`. - Example: - round(123.456, 2) -> 123.46 - round(123.456, -1) -> 12E+1 - round(123.456, -2) -> 1E+2 - round(123.456, -3) -> 0E+3 - round(678.890, -3) -> 1E+3 + If `ndigits` is negative, the last `ndigits` digits of the integer part of + the number will be dropped and the scale will be `ndigits`. + Examples: + round(123.456, 2) -> 123.46 + round(123.456, -1) -> 12E+1 + round(123.456, -2) -> 1E+2 + round(123.456, -3) -> 0E+3 + round(678.890, -3) -> 1E+3 """ var ndigits_to_remove = number.scale - ndigits if ndigits_to_remove == 0: diff --git a/src/decimojo/prelude.mojo b/src/decimojo/prelude.mojo index 910dd26..f04c69a 100644 --- a/src/decimojo/prelude.mojo +++ b/src/decimojo/prelude.mojo @@ -30,4 +30,11 @@ from decimojo.decimal.decimal import Decimal, Dec from decimojo.bigdecimal.bigdecimal import BigDecimal, BDec from decimojo.biguint.biguint import BigUInt, BUInt from decimojo.bigint.bigint import BigInt, BInt -from decimojo.rounding_mode import RoundingMode, RM +from decimojo.rounding_mode import ( + RoundingMode, + RM, + ROUND_DOWN, + ROUND_HALF_UP, + ROUND_HALF_EVEN, + ROUND_UP, +) diff --git a/src/decimojo/rounding_mode.mojo b/src/decimojo/rounding_mode.mojo index d9ff0e0..c05300e 100644 --- a/src/decimojo/rounding_mode.mojo +++ b/src/decimojo/rounding_mode.mojo @@ -18,6 +18,10 @@ """ alias RM = RoundingMode +alias ROUND_DOWN = RoundingMode.ROUND_DOWN +alias ROUND_HALF_UP = RoundingMode.ROUND_HALF_UP +alias ROUND_HALF_EVEN = RoundingMode.ROUND_HALF_EVEN +alias ROUND_UP = RoundingMode.ROUND_UP struct RoundingMode(Stringable): diff --git a/src/decimojo/tests.mojo b/src/decimojo/tests.mojo index c6a7a3a..cb12cbc 100644 --- a/src/decimojo/tests.mojo +++ b/src/decimojo/tests.mojo @@ -79,32 +79,18 @@ struct TestCase(Copyable, Movable, Stringable, Writable): writer.write(" description: " + self.description + "\n") -fn load_test_cases( - file_path: String, table_name: String, has_expected_value: Bool = True -) raises -> List[TestCase]: - """Load test cases from a TOML file for a specific table.""" - var toml = tomlmojo.parse_file(file_path) - var test_cases = List[TestCase]() - - # Get array of test cases - var cases_array = toml.get_array_of_tables(table_name) - - for i in range(len(cases_array)): - var case_table = cases_array[i] - var expected_value = case_table[ - "expected" - ].as_string() if has_expected_value else String("") - test_cases.append( - TestCase( - case_table["a"].as_string(), - case_table["b"].as_string(), - expected_value, - case_table["description"].as_string(), - ) +fn parse_file(file_path: String) raises -> tomlmojo.parser.TOMLDocument: + """Parse a TOML file and return the TOMLDocument.""" + try: + return tomlmojo.parse_file(file_path) + except e: + raise Error( + "tests.parse_file(): Failed to parse TOML file:", + file_path, + "\nTraceback:", + e, ) - return test_cases - fn load_test_cases( toml: tomlmojo.parser.TOMLDocument, table_name: String diff --git a/tests/bigdecimal/test_bigdecimal_arithmetics.mojo b/tests/bigdecimal/test_bigdecimal_arithmetics.mojo index 6061a56..e16444e 100644 --- a/tests/bigdecimal/test_bigdecimal_arithmetics.mojo +++ b/tests/bigdecimal/test_bigdecimal_arithmetics.mojo @@ -1,81 +1,43 @@ """ -Test BigDecimal arithmetic operations including addition, subtraction, multiplication and division. +Test BigDecimal arithmetic operations including: + +1. addition +2. subtraction +3. multiplication +4. division """ from python import Python import testing -from decimojo import BigDecimal, RoundingMode -from decimojo.tests import TestCase -from tomlmojo import parse_file +from decimojo import BDec, RM +from decimojo.tests import TestCase, parse_file, load_test_cases alias file_path = "tests/bigdecimal/test_data/bigdecimal_arithmetics.toml" -fn load_test_cases( - file_path: String, table_name: String -) raises -> List[TestCase]: - """Load test cases from a TOML file for a specific table.""" +fn test_bigdecimal_arithmetics() raises: + # Load test cases from TOML file + var pydecimal = Python.import_module("decimal") var toml = parse_file(file_path) - var test_cases = List[TestCase]() - - # Get array of test cases - var cases_array = toml.get_array_of_tables(table_name) - - for i in range(len(cases_array)): - var case_table = cases_array[i] - test_cases.append( - TestCase( - case_table["a"].as_string(), - case_table["b"].as_string(), - case_table["expected"].as_string(), - case_table["description"].as_string(), - ) - ) + var test_cases: List[TestCase] - return test_cases - - -fn test_add() raises: - """Test BigDecimal addition with various test cases.""" print("------------------------------------------------------") print("Testing BigDecimal addition...") + print("------------------------------------------------------") - var pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases(file_path, "addition_tests") - print("Loaded", len(test_cases), "test cases for addition") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = BigDecimal(test_case.expected) - var result = a + b - + test_cases = load_test_cases(toml, "addition_tests") + for test_case in test_cases: + var result = BDec(test_case.a) + BDec(test_case.b) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - # print("✓ Case", i + 1, ":", test_case.description) - passed += 1 except e: print( - "✗ Case", - i + 1, - "failed:", test_case.description, - "\n Input:", - test_case.a, - "+", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", @@ -86,68 +48,23 @@ fn test_add() raises: + pydecimal.Decimal(test_case.b) ), ) - failed += 1 - - print("BigDecimal addition tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All addition tests should pass") - -fn test_subtract() raises: - """Test BigDecimal subtraction with various test cases.""" print("------------------------------------------------------") print("Testing BigDecimal subtraction...") + print("------------------------------------------------------") - var pydecimal = Python.import_module("decimal") - - # Debug TOML parsing - var toml = parse_file(file_path) - print("TOML file loaded successfully") - - # Check what root keys are available - print("Available root keys:") - for key in toml.root.keys(): - print(" - " + key) - - # Try to access the specific section - try: - var section = toml.get_array_of_tables("subtraction_tests") - print("Found subtraction_tests with", len(section), "entries") - except e: - print("Error accessing subtraction_tests:", String(e)) - - # Load test cases from TOML file - var test_cases = load_test_cases(file_path, "subtraction_tests") - print("Loaded", len(test_cases), "test cases for subtraction") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = BigDecimal(test_case.expected) - var result = a - b - + test_cases = load_test_cases(toml, "subtraction_tests") + for test_case in test_cases: + var result = BDec(test_case.a) - BDec(test_case.b) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - # print("✓ Case", i + 1, ":", test_case.description) - passed += 1 except e: print( - "✗ Case", - i + 1, - "failed:", test_case.description, - "\n Input:", - test_case.a, - "-", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", @@ -158,51 +75,23 @@ fn test_subtract() raises: - pydecimal.Decimal(test_case.b) ), ) - failed += 1 - - print("BigDecimal subtraction tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All subtraction tests should pass") - -fn test_multiply() raises: - """Test BigDecimal multiplication with various test cases.""" print("------------------------------------------------------") print("Testing BigDecimal multiplication...") + print("------------------------------------------------------") - var pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases(file_path, "multiplication_tests") - print("Loaded", len(test_cases), "test cases for multiplication") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = BigDecimal(test_case.expected) - var result = a * b - + test_cases = load_test_cases(toml, "multiplication_tests") + for test_case in test_cases: + var result = BDec(test_case.a) * BDec(test_case.b) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - passed += 1 except e: print( - "✗ Case", - i + 1, - "failed:", test_case.description, - "\n Input:", - test_case.a, - "*", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", @@ -213,24 +102,38 @@ fn test_multiply() raises: * pydecimal.Decimal(test_case.b) ), ) - failed += 1 - print( - "BigDecimal multiplication tests:", passed, "passed,", failed, "failed" - ) - testing.assert_equal(failed, 0, "All multiplication tests should pass") + print("------------------------------------------------------") + print("Testing BigDecimal division...") + print("------------------------------------------------------") + + test_cases = load_test_cases(toml, "division_tests") + for test_case in test_cases: + var result = BDec(test_case.a) / BDec(test_case.b) + try: + testing.assert_equal( + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, + ) + except e: + print( + test_case.description, + "\n Expected:", + test_case.expected, + "\n Got:", + String(result), + "\n Python decimal result (for reference):", + String( + pydecimal.Decimal(test_case.a) + / pydecimal.Decimal(test_case.b) + ), + ) fn main() raises: print("Running BigDecimal arithmetic tests") - # Run addition tests - test_add() - - # Run subtraction tests - test_subtract() - - # Run multiplication tests - test_multiply() + test_bigdecimal_arithmetics() print("All BigDecimal arithmetic tests passed!") diff --git a/tests/bigdecimal/test_bigdecimal_compare.mojo b/tests/bigdecimal/test_bigdecimal_compare.mojo index 0e72fce..3dc7564 100644 --- a/tests/bigdecimal/test_bigdecimal_compare.mojo +++ b/tests/bigdecimal/test_bigdecimal_compare.mojo @@ -3,332 +3,109 @@ Test BigDecimal comparison operations. """ import testing -from python import PythonObject -from tomlmojo import parse_file -from decimojo import BigDecimal + +from decimojo import BDec from decimojo.bigdecimal.comparison import compare_absolute, compare -from decimojo.tests import TestCase -from collections import List +from decimojo.tests import TestCase, parse_file, load_test_cases alias file_path = "tests/bigdecimal/test_data/bigdecimal_compare.toml" -fn load_test_cases( - file_path: String, table_name: String -) raises -> List[TestCase]: - """Load test cases from a TOML file for a specific table.""" +fn test_bigdecimal_compare() raises: + # Load test cases from TOML file var toml = parse_file(file_path) - var test_cases = List[TestCase]() - - # Get array of test cases - var cases_array = toml.get_array_of_tables(table_name) - - for i in range(len(cases_array)): - var case_table = cases_array[i] - test_cases.append( - TestCase( - case_table["a"].as_string(), - case_table["b"].as_string(), - case_table["expected"].as_string(), - case_table["description"].as_string(), - ) - ) - - return test_cases + var test_cases: List[TestCase] - -fn test_compare_absolute() raises: - """Test the compare_absolute function for BigDecimal.""" print("------------------------------------------------------") print("Testing BigDecimal compare_absolute...") + print("------------------------------------------------------") - # Load test cases from TOML file - var test_cases = load_test_cases(file_path, "compare_absolute_tests") - print("Loaded", len(test_cases), "test cases for compare_absolute") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = Int8(Int(test_case.expected)) - var result = compare_absolute(a, b) - - try: - testing.assert_equal(result, expected, test_case.description) - passed += 1 - except e: - print( - "✗ Case", - i + 1, - "failed:", - test_case.description, - "\n Input: |", - test_case.a, - "| compare |", - test_case.b, - "|", - "\n Expected:", - expected, - "\n Got:", - result, - ) - failed += 1 - - print( - "BigDecimal compare_absolute tests:", - passed, - "passed,", - failed, - "failed", - ) - testing.assert_equal(failed, 0, "All compare_absolute tests should pass") - + test_cases = load_test_cases(toml, "compare_absolute_tests") + for test_case in test_cases: + var result = compare_absolute(BDec(test_case.a), BDec(test_case.b)) + testing.assert_equal( + lhs=result, + rhs=Int8(Int(test_case.expected)), + msg=test_case.description, + ) -fn test_greater_than() raises: - """Test the > operator for BigDecimal.""" print("------------------------------------------------------") print("Testing BigDecimal > operator...") - var test_cases = load_test_cases(file_path, "greater_than_tests") - var passed = 0 - var failed = 0 - - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = test_case.expected == "true" - var result = a > b - try: - testing.assert_equal(result, expected, test_case.description) - passed += 1 - except e: - print( - "✗ Case", - i + 1, - "failed:", - test_case.description, - "\n Input:", - test_case.a, - ">", - test_case.b, - "\n Expected:", - expected, - "\n Got:", - result, - ) - failed += 1 - - print("BigDecimal > tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All > tests should pass") - + 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) + testing.assert_equal( + lhs=result, + rhs=Bool(Int(test_case.expected)), + msg=test_case.description, + ) -fn test_less_than() raises: - """Test the < operator for BigDecimal.""" print("------------------------------------------------------") print("Testing BigDecimal < operator...") - var test_cases = load_test_cases(file_path, "less_than_tests") - var passed = 0 - var failed = 0 - - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = test_case.expected == "true" - var result = a < b - try: - testing.assert_equal(result, expected, test_case.description) - passed += 1 - except e: - print( - "✗ Case", - i + 1, - "failed:", - test_case.description, - "\n Input:", - test_case.a, - "<", - test_case.b, - "\n Expected:", - expected, - "\n Got:", - result, - ) - failed += 1 - - print("BigDecimal < tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All < tests should pass") - + 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) + testing.assert_equal( + lhs=result, + rhs=Bool(Int(test_case.expected)), + msg=test_case.description, + ) -fn test_greater_than_or_equal() raises: - """Test the >= operator for BigDecimal.""" print("------------------------------------------------------") print("Testing BigDecimal >= operator...") - var test_cases = load_test_cases(file_path, "greater_than_or_equal_tests") - var passed = 0 - var failed = 0 - - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = test_case.expected == "true" - var result = a >= b - try: - testing.assert_equal(result, expected, test_case.description) - passed += 1 - except e: - print( - "✗ Case", - i + 1, - "failed:", - test_case.description, - "\n Input:", - test_case.a, - ">=", - test_case.b, - "\n Expected:", - expected, - "\n Got:", - result, - ) - failed += 1 - - print("BigDecimal >= tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All >= tests should pass") - + 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) + testing.assert_equal( + lhs=result, + rhs=Bool(Int(test_case.expected)), + msg=test_case.description, + ) -fn test_less_than_or_equal() raises: - """Test the <= operator for BigDecimal.""" print("------------------------------------------------------") print("Testing BigDecimal <= operator...") - var test_cases = load_test_cases(file_path, "less_than_or_equal_tests") - var passed = 0 - var failed = 0 - - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = test_case.expected == "true" - var result = a <= b - try: - testing.assert_equal(result, expected, test_case.description) - passed += 1 - except e: - print( - "✗ Case", - i + 1, - "failed:", - test_case.description, - "\n Input:", - test_case.a, - "<=", - test_case.b, - "\n Expected:", - expected, - "\n Got:", - result, - ) - failed += 1 - - print("BigDecimal <= tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All <= tests should pass") - + 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) + testing.assert_equal( + lhs=result, + rhs=Bool(Int(test_case.expected)), + msg=test_case.description, + ) -fn test_equal() raises: - """Test the == operator for BigDecimal.""" print("------------------------------------------------------") print("Testing BigDecimal == operator...") - var test_cases = load_test_cases(file_path, "equal_tests") - var passed = 0 - var failed = 0 - - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = test_case.expected == "true" - var result = a == b - try: - testing.assert_equal(result, expected, test_case.description) - passed += 1 - except e: - print( - "✗ Case", - i + 1, - "failed:", - test_case.description, - "\n Input:", - test_case.a, - "==", - test_case.b, - "\n Expected:", - expected, - "\n Got:", - result, - ) - failed += 1 - - print("BigDecimal == tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All == tests should pass") - + 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) + testing.assert_equal( + lhs=result, + rhs=Bool(Int(test_case.expected)), + msg=test_case.description, + ) -fn test_not_equal() raises: - """Test the != operator for BigDecimal.""" print("------------------------------------------------------") print("Testing BigDecimal != operator...") - var test_cases = load_test_cases(file_path, "not_equal_tests") - var passed = 0 - var failed = 0 - - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = test_case.expected == "true" - var result = a != b - try: - testing.assert_equal(result, expected, test_case.description) - passed += 1 - except e: - print( - "✗ Case", - i + 1, - "failed:", - test_case.description, - "\n Input:", - test_case.a, - "!=", - test_case.b, - "\n Expected:", - expected, - "\n Got:", - result, - ) - failed += 1 - - print("BigDecimal != tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All != tests should pass") + 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) + testing.assert_equal( + lhs=result, + rhs=Bool(Int(test_case.expected)), + msg=test_case.description, + ) fn main() raises: print("Running BigDecimal comparison tests") # Run compare_absolute tests - test_compare_absolute() - - # Run comparison operator tests - test_greater_than() - test_less_than() - test_greater_than_or_equal() - test_less_than_or_equal() - test_equal() - test_not_equal() + test_bigdecimal_compare() print("All BigDecimal comparison tests passed!") diff --git a/tests/bigdecimal/test_bigdecimal_divide.mojo b/tests/bigdecimal/test_bigdecimal_divide.mojo deleted file mode 100644 index e2775ea..0000000 --- a/tests/bigdecimal/test_bigdecimal_divide.mojo +++ /dev/null @@ -1,131 +0,0 @@ -""" -Test BigDecimal arithmetic operations including addition, subtraction, multiplication and division. -""" - -from python import Python -import testing - -from decimojo import BigDecimal, RoundingMode -from decimojo.tests import TestCase -from tomlmojo import parse_file - -alias division_file_path = "tests/bigdecimal/test_data/bigdecimal_divide.toml" - - -fn load_test_cases( - file_path: String, table_name: String -) raises -> List[TestCase]: - """Load test cases from a TOML file for a specific table.""" - var toml = parse_file(file_path) - var test_cases = List[TestCase]() - - # Get array of test cases - var cases_array = toml.get_array_of_tables(table_name) - - for i in range(len(cases_array)): - var case_table = cases_array[i] - test_cases.append( - TestCase( - case_table["a"].as_string(), - case_table["b"].as_string(), - case_table["expected"].as_string(), - case_table["description"].as_string(), - ) - ) - - return test_cases - - -fn test_true_divide() raises: - """Test BigDecimal division with various test cases.""" - print("------------------------------------------------------") - print("Testing BigDecimal division...") - - var pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases(division_file_path, "division_tests") - print("Loaded", len(test_cases), "test cases for division") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var a = BigDecimal(test_case.a) - var b = BigDecimal(test_case.b) - var expected = BigDecimal(test_case.expected) - - # Special case: Check if divisor is zero - if String(b) == "0": - print("Skipping division by zero test (would cause error)") - continue - - var result = a / b - - try: - # Using String comparison for easier debugging - testing.assert_equal( - String(result), String(expected), test_case.description - ) - passed += 1 - except e: - print( - "=" * 50, - "\n", - i + 1, - "failed:", - test_case.description, - "\n Input:", - test_case.a, - "/", - test_case.b, - "\n Expected:", - test_case.expected, - "\n Got:", - String(result), - "\n Python decimal result (for reference):", - String( - pydecimal.Decimal(test_case.a) - / pydecimal.Decimal(test_case.b) - ), - ) - failed += 1 - - print("BigDecimal division tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All division tests should pass") - - -fn test_division_by_zero() raises: - """Test that division by zero raises an error.""" - print("------------------------------------------------------") - print("Testing BigDecimal division by zero...") - - var a = BigDecimal("1") - var b = BigDecimal("0") - - var exception_caught: Bool - try: - _ = a / b - exception_caught = False - except: - exception_caught = True - - testing.assert_true( - exception_caught, "Division by zero should raise an error" - ) - print("✓ Division by zero correctly raises an error") - - -fn main() raises: - print("Running BigDecimal arithmetic tests") - - # Run division tests - test_true_divide() - - # Test division by zero - test_division_by_zero() - - print("All BigDecimal arithmetic tests passed!") diff --git a/tests/bigdecimal/test_bigdecimal_exponential.mojo b/tests/bigdecimal/test_bigdecimal_exponential.mojo index 3cea59b..153f6aa 100644 --- a/tests/bigdecimal/test_bigdecimal_exponential.mojo +++ b/tests/bigdecimal/test_bigdecimal_exponential.mojo @@ -5,111 +5,119 @@ Test BigDecimal exponential operations including square root and natural logarit from python import Python import testing -from decimojo import BigDecimal, RoundingMode -from decimojo.tests import TestCase -from tomlmojo import parse_file +from decimojo import BDec +from decimojo.tests import TestCase, parse_file, load_test_cases -alias exponential_file_path = "tests/bigdecimal/test_data/bigdecimal_exponential.toml" +alias file_path = "tests/bigdecimal/test_data/bigdecimal_exponential.toml" -fn load_test_cases_one_argument( - file_path: String, table_name: String -) raises -> List[TestCase]: - """Load test cases from a TOML file for a specific table.""" +fn test_bigdecimal_exponential() raises: + # Load test cases from TOML file + var pydecimal = Python.import_module("decimal") var toml = parse_file(file_path) - var test_cases = List[TestCase]() - - # Get array of test cases - var cases_array = toml.get_array_of_tables(table_name) - - for i in range(len(cases_array)): - var case_table = cases_array[i] - test_cases.append( - TestCase( - case_table["input"].as_string(), - "", # No second input for sqrt - case_table["expected"].as_string(), - case_table["description"].as_string(), - ) - ) - return test_cases^ + var test_cases: List[TestCase] + print("------------------------------------------------------") + print("Testing BigDecimal square root...") + print("------------------------------------------------------") -fn load_test_cases_two_arguments( - file_path: String, table_name: String -) raises -> List[TestCase]: - """Load test cases from a TOML file for a specific table.""" - var toml = parse_file(file_path) - var test_cases = List[TestCase]() - - # Get array of test cases - var cases_array = toml.get_array_of_tables(table_name) - - for i in range(len(cases_array)): - var case_table = cases_array[i] - test_cases.append( - TestCase( - case_table["a"].as_string(), - case_table["b"].as_string(), - case_table["expected"].as_string(), - case_table["description"].as_string(), + test_cases = load_test_cases(toml, "sqrt_tests") + for test_case in test_cases: + var result = BDec(test_case.a).sqrt(precision=28) + try: + testing.assert_equal( + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, + ) + except e: + print( + test_case.description, + "\n Expected:", + test_case.expected, + "\n Got:", + String(result), + "\n Python decimal result (for reference):", + String(pydecimal.Decimal(test_case.a).sqrt()), ) - ) - return test_cases^ - -fn test_sqrt() raises: - """Test BigDecimal square root with various test cases.""" print("------------------------------------------------------") - print("Testing BigDecimal square root...") - - var pydecimal = Python.import_module("decimal") + print("Testing BigDecimal natural logarithm (ln)...") + print("------------------------------------------------------") - # Load test cases from TOML file - var test_cases = load_test_cases_one_argument( - exponential_file_path, "sqrt_tests" - ) - print("Loaded", len(test_cases), "test cases for square root") + test_cases = load_test_cases(toml, "ln_tests") + for test_case in test_cases: + var result = BDec(test_case.a).ln(precision=28) + try: + testing.assert_equal( + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, + ) + except e: + print( + test_case.description, + "\n Expected:", + test_case.expected, + "\n Got:", + String(result), + "\n Python decimal result (for reference):", + String(pydecimal.Decimal(test_case.a).ln()), + ) - # Track test results - var passed = 0 - var failed = 0 + print("------------------------------------------------------") + print("Testing BigDecimal root function...") + print("------------------------------------------------------") - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var input_value = BigDecimal(test_case.a) - var expected = BigDecimal(test_case.expected) + test_cases = load_test_cases(toml, "root_tests") + for test_case in test_cases: + var result = BDec(test_case.a).root(BDec(test_case.b), precision=28) + try: + testing.assert_equal( + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, + ) + except e: + print( + test_case.description, + "\n Expected:", + test_case.expected, + "\n Got:", + String(result), + "\n Python decimal result (for reference):", + String( + pydecimal.Decimal(test_case.a) + ** (pydecimal.Decimal(1) / pydecimal.Decimal(test_case.b)) + ), + ) - # Calculate square root - var result = input_value.sqrt(precision=28) + print("------------------------------------------------------") + print("Testing BigDecimal power function...") + print("------------------------------------------------------") + test_cases = load_test_cases(toml, "power_tests") + for test_case in test_cases: + var result = BDec(test_case.a).power(BDec(test_case.b), precision=28) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - passed += 1 except e: print( - "=" * 50, - "\n", - i + 1, - "failed:", test_case.description, - "\n Input:", - test_case.a, "\n Expected:", test_case.expected, "\n Got:", String(result), "\n Python decimal result (for reference):", - String(pydecimal.Decimal(test_case.a).sqrt()), + String( + pydecimal.Decimal(test_case.a) + ** pydecimal.Decimal(test_case.b) + ), ) - failed += 1 - - print("BigDecimal sqrt tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All square root tests should pass") fn test_negative_sqrt() raises: @@ -117,7 +125,7 @@ fn test_negative_sqrt() raises: print("------------------------------------------------------") print("Testing BigDecimal square root with negative input...") - var negative_number = BigDecimal("-1") + var negative_number = BDec("-1") var exception_caught: Bool try: @@ -132,60 +140,6 @@ fn test_negative_sqrt() raises: print("✓ Square root of negative number correctly raises an error") -fn test_ln() raises: - """Test BigDecimal natural logarithm with various test cases.""" - print("------------------------------------------------------") - print("Testing BigDecimal natural logarithm (ln)...") - - var pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases_one_argument( - exponential_file_path, "ln_tests" - ) - print("Loaded", len(test_cases), "test cases for natural logarithm") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var input_value = BigDecimal(test_case.a) - var expected = BigDecimal(test_case.expected) - - # Calculate natural logarithm - var result = input_value.ln() - - try: - # Using String comparison for easier debugging - testing.assert_equal( - String(result), String(expected), test_case.description - ) - passed += 1 - except e: - print( - "=" * 50, - "\n", - i + 1, - "failed:", - test_case.description, - "\n Input:", - test_case.a, - "\n Expected:", - test_case.expected, - "\n Got:", - String(result), - "\n Python decimal result (for reference):", - String(pydecimal.Decimal(test_case.a).ln()), - ) - failed += 1 - - print("BigDecimal ln tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All natural logarithm tests should pass") - - fn test_ln_invalid_inputs() raises: """Test that natural logarithm with invalid inputs raises appropriate errors. """ @@ -193,7 +147,7 @@ fn test_ln_invalid_inputs() raises: print("Testing BigDecimal natural logarithm with invalid inputs...") # Test 1: ln of zero should raise an error - var zero = BigDecimal("0") + var zero = BDec("0") var exception_caught: Bool try: _ = zero.ln() @@ -204,7 +158,7 @@ fn test_ln_invalid_inputs() raises: print("✓ ln(0) correctly raises an error") # Test 2: ln of negative number should raise an error - var negative = BigDecimal("-1") + var negative = BDec("-1") try: _ = negative.ln() exception_caught = False @@ -216,74 +170,14 @@ fn test_ln_invalid_inputs() raises: print("✓ ln of negative number correctly raises an error") -fn test_root() raises: - """Test BigDecimal nth root with various test cases.""" - print("------------------------------------------------------") - print("Testing BigDecimal root function...") - - var pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases_two_arguments( - exponential_file_path, "root_tests" - ) - print("Loaded", len(test_cases), "test cases for root function") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var base_value = BigDecimal(test_case.a) - var root_value = BigDecimal(test_case.b) - var expected = BigDecimal(test_case.expected) - - # Calculate nth root - var result = base_value.root(root_value, precision=28) - - try: - # Using String comparison for easier debugging - testing.assert_equal( - String(result), String(expected), test_case.description - ) - passed += 1 - except e: - print( - "=" * 50, - "\n", - i + 1, - "failed:", - test_case.description, - "\n Base:", - test_case.a, - "\n Root:", - test_case.b, - "\n Expected:", - test_case.expected, - "\n Got:", - String(result), - "\n Python decimal result (for reference):", - String( - pydecimal.Decimal(test_case.a) - ** (pydecimal.Decimal(1) / pydecimal.Decimal(test_case.b)) - ), - ) - failed += 1 - - print("BigDecimal root tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All root function tests should pass") - - fn test_root_invalid_inputs() raises: """Test that root function with invalid inputs raises appropriate errors.""" print("------------------------------------------------------") print("Testing BigDecimal root with invalid inputs...") # Test 1: 0th root should raise an error - var a1 = BigDecimal("16") - var n1 = BigDecimal("0") + var a1 = BDec("16") + var n1 = BDec("0") var exception_caught: Bool try: _ = a1.root(n1, precision=28) @@ -294,8 +188,8 @@ fn test_root_invalid_inputs() raises: print("✓ 0th root correctly raises an error") # Test 2: Even root of negative number should raise an error - var a2 = BigDecimal("-16") - var n2 = BigDecimal("2") + var a2 = BDec("-16") + var n2 = BDec("2") try: _ = a2.root(n2, precision=28) exception_caught = False @@ -307,8 +201,8 @@ fn test_root_invalid_inputs() raises: 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 = BigDecimal("-16") - var n3 = BigDecimal("2.5") # 5/2, denominator is even + var a3 = BDec("-16") + var n3 = BDec("2.5") # 5/2, denominator is even try: _ = a3.root(n3, precision=28) exception_caught = False @@ -327,66 +221,6 @@ fn test_root_invalid_inputs() raises: ) -fn test_power() raises: - """Test BigDecimal power function with various test cases.""" - print("------------------------------------------------------") - print("Testing BigDecimal power function...") - - var pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases_two_arguments( - exponential_file_path, "power_tests" - ) - print("Loaded", len(test_cases), "test cases for power function") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var base_value = BigDecimal(test_case.a) - var exponent = BigDecimal(test_case.b) - var expected = BigDecimal(test_case.expected) - - # Calculate power - var result = base_value.power(exponent, precision=28) - - try: - # Using String comparison for easier debugging - testing.assert_equal( - String(result), String(expected), test_case.description - ) - passed += 1 - except e: - print( - "=" * 50, - "\n", - i + 1, - "failed:", - test_case.description, - "\n Base:", - test_case.a, - "\n Exponent:", - test_case.b, - "\n Expected:", - test_case.expected, - "\n Got:", - String(result), - "\n Python decimal result (for reference):", - String( - pydecimal.Decimal(test_case.a) - ** pydecimal.Decimal(test_case.b) - ), - ) - failed += 1 - - print("BigDecimal power tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All power function tests should pass") - - fn test_power_invalid_inputs() raises: """Test that power function with invalid inputs raises appropriate errors. """ @@ -394,8 +228,8 @@ fn test_power_invalid_inputs() raises: print("Testing BigDecimal power with invalid inputs...") # Test 1: 0^0 should raise an error (undefined) - var base1 = BigDecimal("0") - var exp1 = BigDecimal("0") + var base1 = BDec("0") + var exp1 = BDec("0") var exception_caught: Bool try: _ = base1.power(exp1, precision=28) @@ -406,8 +240,8 @@ fn test_power_invalid_inputs() raises: print("✓ 0^0 correctly raises an error") # Test 2: 0^-1 should raise an error (division by zero) - var base2 = BigDecimal("0") - var exp2 = BigDecimal("-1") + var base2 = BDec("0") + var exp2 = BDec("-1") try: _ = base2.power(exp2, precision=28) exception_caught = False @@ -419,8 +253,8 @@ fn test_power_invalid_inputs() raises: 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 = BigDecimal("-2") - var exp3 = BigDecimal("0.5") + var base3 = BDec("-2") + var exp3 = BDec("0.5") try: _ = base3.power(exp3, precision=28) exception_caught = False @@ -439,27 +273,18 @@ fn test_power_invalid_inputs() raises: fn main() raises: print("Running BigDecimal exponential tests") - # Run sqrt tests - test_sqrt() + # Run all tests + test_bigdecimal_exponential() # Test sqrt of negative number test_negative_sqrt() - # Run root tests - test_root() - # Test root with invalid inputs test_root_invalid_inputs() - # Run power tests - test_power() - # Test power with invalid inputs test_power_invalid_inputs() - # Run ln tests - test_ln() - # Test ln with invalid inputs test_ln_invalid_inputs() diff --git a/tests/bigdecimal/test_bigdecimal_rounding.mojo b/tests/bigdecimal/test_bigdecimal_rounding.mojo index fe9788d..08a7461 100644 --- a/tests/bigdecimal/test_bigdecimal_rounding.mojo +++ b/tests/bigdecimal/test_bigdecimal_rounding.mojo @@ -5,80 +5,35 @@ Test BigDecimal rounding operations with various rounding modes and precision va from python import Python import testing -from decimojo import BigDecimal, RoundingMode -from decimojo.tests import TestCase -from tomlmojo import parse_file +from decimojo.prelude import * +from decimojo.tests import TestCase, parse_file, load_test_cases -alias rounding_file_path = "tests/bigdecimal/test_data/bigdecimal_rounding.toml" +alias file_path = "tests/bigdecimal/test_data/bigdecimal_rounding.toml" -fn load_test_cases_two_arguments( - file_path: String, table_name: String -) raises -> List[TestCase]: - """Load test cases from a TOML file for a specific table.""" +fn test_bigdecimal_rounding() raises: + # Load test cases from TOML file + var pydecimal = Python.import_module("decimal") var toml = parse_file(file_path) - var test_cases = List[TestCase]() - - # Get array of test cases - var cases_array = toml.get_array_of_tables(table_name) - - for i in range(len(cases_array)): - var case_table = cases_array[i] - test_cases.append( - TestCase( - case_table["a"].as_string(), # Value to round - case_table["b"].as_string(), # Decimal places - case_table["expected"].as_string(), # Expected result - case_table["description"].as_string(), # Test description - ) - ) - return test_cases^ - + var test_cases: List[TestCase] -fn test_round_down() raises: - """Test BigDecimal rounding with ROUND_DOWN mode.""" print("------------------------------------------------------") print("Testing BigDecimal ROUND_DOWN mode...") + print("------------------------------------------------------") - var pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases_two_arguments( - rounding_file_path, "round_down_tests" - ) - print("Loaded", len(test_cases), "test cases for ROUND_DOWN") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var value = BigDecimal(test_case.a) - var decimal_places = Int(test_case.b) - var expected = BigDecimal(test_case.expected) - - # Perform rounding - var result = value.round(decimal_places, RoundingMode.ROUND_DOWN) - + pydecimal.getcontext().rounding = pydecimal.ROUND_DOWN + test_cases = load_test_cases(toml, "round_down_tests") + for test_case in test_cases: + var result = BDec(test_case.a).round(Int(test_case.b), ROUND_DOWN) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - passed += 1 except e: print( - "=" * 50, - "\n", - i + 1, - "failed:", test_case.description, - "\n Value:", - test_case.a, - "\n Decimal places:", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", @@ -88,56 +43,24 @@ fn test_round_down() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) - failed += 1 - print("BigDecimal ROUND_DOWN tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All ROUND_DOWN tests should pass") - - -fn test_round_up() raises: - """Test BigDecimal rounding with ROUND_UP mode.""" print("------------------------------------------------------") print("Testing BigDecimal ROUND_UP mode...") + print("------------------------------------------------------") - pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases_two_arguments( - rounding_file_path, "round_up_tests" - ) - print("Loaded", len(test_cases), "test cases for ROUND_UP") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var value = BigDecimal(test_case.a) - var decimal_places = Int(test_case.b) - var expected = BigDecimal(test_case.expected) - - # Perform rounding - var result = value.round(decimal_places, RoundingMode.ROUND_UP) - + pydecimal.getcontext().rounding = pydecimal.ROUND_UP + test_cases = load_test_cases(toml, "round_up_tests") + for test_case in test_cases: + var result = BDec(test_case.a).round(Int(test_case.b), ROUND_UP) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - passed += 1 except e: print( - "=" * 50, - "\n", - i + 1, - "failed:", test_case.description, - "\n Value:", - test_case.a, - "\n Decimal places:", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", @@ -147,56 +70,24 @@ fn test_round_up() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) - failed += 1 - - print("BigDecimal ROUND_UP tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All ROUND_UP tests should pass") - -fn test_round_half_up() raises: - """Test BigDecimal rounding with ROUND_HALF_UP mode.""" print("------------------------------------------------------") print("Testing BigDecimal ROUND_HALF_UP mode...") + print("------------------------------------------------------") - pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases_two_arguments( - rounding_file_path, "round_half_up_tests" - ) - print("Loaded", len(test_cases), "test cases for ROUND_HALF_UP") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var value = BigDecimal(test_case.a) - var decimal_places = Int(test_case.b) - var expected = BigDecimal(test_case.expected) - - # Perform rounding - var result = value.round(decimal_places, RoundingMode.ROUND_HALF_UP) - + pydecimal.getcontext().rounding = pydecimal.ROUND_HALF_UP + test_cases = load_test_cases(toml, "round_half_up_tests") + for test_case in test_cases: + var result = BDec(test_case.a).round(Int(test_case.b), ROUND_HALF_UP) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - passed += 1 except e: print( - "=" * 50, - "\n", - i + 1, - "failed:", test_case.description, - "\n Value:", - test_case.a, - "\n Decimal places:", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", @@ -206,59 +97,24 @@ fn test_round_half_up() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) - failed += 1 - - print( - "BigDecimal ROUND_HALF_UP tests:", passed, "passed,", failed, "failed" - ) - testing.assert_equal(failed, 0, "All ROUND_HALF_UP tests should pass") - -fn test_round_half_even() raises: - """Test BigDecimal rounding with ROUND_HALF_EVEN (banker's rounding) mode. - """ print("------------------------------------------------------") - print("Testing BigDecimal ROUND_HALF_EVEN mode...") - - pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases_two_arguments( - rounding_file_path, "round_half_even_tests" - ) - print("Loaded", len(test_cases), "test cases for ROUND_HALF_EVEN") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var value = BigDecimal(test_case.a) - var decimal_places = Int(test_case.b) - var expected = BigDecimal(test_case.expected) - - # Perform rounding - var result = value.round(decimal_places, RoundingMode.ROUND_HALF_EVEN) + 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") + for test_case in test_cases: + var result = BDec(test_case.a).round(Int(test_case.b), ROUND_HALF_EVEN) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - passed += 1 except e: print( - "=" * 50, - "\n", - i + 1, - "failed:", test_case.description, - "\n Value:", - test_case.a, - "\n Decimal places:", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", @@ -268,119 +124,49 @@ fn test_round_half_even() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) - failed += 1 - - print( - "BigDecimal ROUND_HALF_EVEN tests:", passed, "passed,", failed, "failed" - ) - testing.assert_equal(failed, 0, "All ROUND_HALF_EVEN tests should pass") - -fn test_extreme_values() raises: - """Test BigDecimal rounding with extreme values.""" print("------------------------------------------------------") print("Testing BigDecimal rounding with extreme values...") + print("------------------------------------------------------") - pydecimal = Python.import_module("decimal") - pydecimal.getcontext().prec = 100 - - # Load test cases from TOML file - var test_cases = load_test_cases_two_arguments( - rounding_file_path, "extreme_value_tests" - ) - print("Loaded", len(test_cases), "test cases for extreme values") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var value = BigDecimal(test_case.a) - var decimal_places = Int(test_case.b) - var expected = BigDecimal(test_case.expected) - - # Perform rounding with default ROUND_HALF_EVEN mode - var result = value.round(decimal_places, RoundingMode.ROUND_HALF_EVEN) - + test_cases = load_test_cases(toml, "extreme_value_tests") + for test_case in test_cases: + var result = BDec(test_case.a).round(Int(test_case.b), ROUND_HALF_EVEN) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - passed += 1 except e: print( - "=" * 50, - "\n", - i + 1, - "failed:", test_case.description, - "\n Value:", - test_case.a, - "\n Decimal places:", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", String(result), "\n Python decimal result (for reference):", String( - pydecimal.Decimal(test_case.a).__round__(decimal_places) + pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) - failed += 1 - - print( - "BigDecimal extreme value tests:", passed, "passed,", failed, "failed" - ) - testing.assert_equal(failed, 0, "All extreme value tests should pass") - -fn test_edge_cases() raises: - """Test BigDecimal rounding with special edge cases.""" print("------------------------------------------------------") print("Testing BigDecimal rounding with special edge cases...") + print("------------------------------------------------------") - pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases_two_arguments( - rounding_file_path, "edge_case_tests" - ) - print("Loaded", len(test_cases), "test cases for edge cases") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var value = BigDecimal(test_case.a) - var decimal_places = Int(test_case.b) - - # Perform rounding with default ROUND_HALF_EVEN mode - var result = value.round(decimal_places, RoundingMode.ROUND_HALF_EVEN) - + test_cases = load_test_cases(toml, "edge_case_tests") + for test_case in test_cases: + var result = BDec(test_case.a).round(Int(test_case.b), ROUND_HALF_EVEN) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), test_case.expected, test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - passed += 1 except e: print( - "=" * 50, - "\n", - i + 1, - "failed:", test_case.description, - "\n Value:", - test_case.a, - "\n Decimal places:", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", @@ -390,57 +176,26 @@ fn test_edge_cases() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) - failed += 1 - print("BigDecimal edge case tests:", passed, "passed,", failed, "failed") - testing.assert_equal(failed, 0, "All edge case tests should pass") - - -fn test_precision_conversions() raises: - """Test BigDecimal rounding with negative precision (rounding to tens, hundreds, etc.). - """ print("------------------------------------------------------") - print("Testing BigDecimal rounding with precision conversions...") - - pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases_two_arguments( - rounding_file_path, "precision_tests" + print( + "Testing BigDecimal rounding with negative precision (rounding to tens," + " hundreds, etc.)" ) - print("Loaded", len(test_cases), "test cases for precision conversions") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var value = BigDecimal(test_case.a) - var decimal_places = Int(test_case.b) - var expected = BigDecimal(test_case.expected) - - # Perform rounding with default ROUND_HALF_EVEN mode - var result = value.round(decimal_places, RoundingMode.ROUND_HALF_EVEN) + print("------------------------------------------------------") + test_cases = load_test_cases(toml, "precision_tests") + for test_case in test_cases: + var result = BDec(test_case.a).round(Int(test_case.b), ROUND_HALF_EVEN) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - passed += 1 except e: print( - "=" * 50, - "\n", - i + 1, - "failed:", test_case.description, - "\n Value:", - test_case.a, - "\n Decimal places:", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", @@ -450,64 +205,23 @@ fn test_precision_conversions() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) - failed += 1 - - print( - "BigDecimal precision conversion tests:", - passed, - "passed,", - failed, - "failed", - ) - testing.assert_equal( - failed, 0, "All precision conversion tests should pass" - ) - -fn test_scientific_notation() raises: - """Test BigDecimal rounding with scientific notation inputs.""" print("------------------------------------------------------") print("Testing BigDecimal rounding with scientific notation inputs...") + print("------------------------------------------------------") - pydecimal = Python.import_module("decimal") - - # Load test cases from TOML file - var test_cases = load_test_cases_two_arguments( - rounding_file_path, "scientific_tests" - ) - print("Loaded", len(test_cases), "test cases for scientific notation") - - # Track test results - var passed = 0 - var failed = 0 - - # Run all test cases in a loop - for i in range(len(test_cases)): - var test_case = test_cases[i] - var value = BigDecimal(test_case.a) - var decimal_places = Int(test_case.b) - var expected = BigDecimal(test_case.expected) - - # Perform rounding with default ROUND_HALF_EVEN mode - var result = value.round(decimal_places, RoundingMode.ROUND_HALF_EVEN) - + test_cases = load_test_cases(toml, "scientific_tests") + for test_case in test_cases: + var result = BDec(test_case.a).round(Int(test_case.b), ROUND_HALF_EVEN) try: - # Using String comparison for easier debugging testing.assert_equal( - String(result), String(expected), test_case.description + lhs=String(result), + rhs=test_case.expected, + msg=test_case.description, ) - passed += 1 except e: print( - "=" * 50, - "\n", - i + 1, - "failed:", test_case.description, - "\n Value:", - test_case.a, - "\n Decimal places:", - test_case.b, "\n Expected:", test_case.expected, "\n Got:", @@ -517,16 +231,6 @@ fn test_scientific_notation() raises: pydecimal.Decimal(test_case.a).__round__(Int(test_case.b)) ), ) - failed += 1 - - print( - "BigDecimal scientific notation tests:", - passed, - "passed,", - failed, - "failed", - ) - testing.assert_equal(failed, 0, "All scientific notation tests should pass") fn test_default_rounding_mode() raises: @@ -534,9 +238,9 @@ fn test_default_rounding_mode() raises: print("------------------------------------------------------") print("Testing BigDecimal default rounding mode...") - var value = BigDecimal("2.5") - var result = value.round(0, RoundingMode.ROUND_HALF_EVEN) - var expected = BigDecimal("2") # HALF_EVEN rounds 2.5 to 2 (nearest even) + var value = BDec("2.5") + var result = value.round(0) + var expected = BDec("2") # HALF_EVEN rounds 2.5 to 2 (nearest even) testing.assert_equal( String(result), @@ -544,9 +248,9 @@ fn test_default_rounding_mode() raises: "Default rounding mode should be ROUND_HALF_EVEN", ) - value = BigDecimal("3.5") + value = BDec("3.5") result = round(value, 0) # No rounding mode specified - expected = BigDecimal("4") # HALF_EVEN rounds 3.5 to 4 (nearest even) + expected = BDec("4") # HALF_EVEN rounds 3.5 to 4 (nearest even) testing.assert_equal( String(result), @@ -561,16 +265,7 @@ fn main() raises: print("Running BigDecimal rounding tests") # Test different rounding modes - test_round_down() - test_round_up() - test_round_half_up() - test_round_half_even() - - # Test special cases - test_extreme_values() - test_edge_cases() - test_precision_conversions() - test_scientific_notation() + test_bigdecimal_rounding() # Test default rounding mode test_default_rounding_mode() diff --git a/tests/bigdecimal/test_data/bigdecimal_arithmetics.toml b/tests/bigdecimal/test_data/bigdecimal_arithmetics.toml index 18c3052..435c2d9 100644 --- a/tests/bigdecimal/test_data/bigdecimal_arithmetics.toml +++ b/tests/bigdecimal/test_data/bigdecimal_arithmetics.toml @@ -1,3 +1,6 @@ +# ===----------------------------------------------------------------------=== # +# Test cases for BigDecimal addition +# ===----------------------------------------------------------------------=== # # === BASIC ADDITION TESTS === [[addition_tests]] a = "42" @@ -918,3 +921,330 @@ a = "3.1415926535897932384626433832795" b = "1.0" expected = "3.14159265358979323846264338327950" description = "Multiplication preserving significant digits up to precision" + +# ===----------------------------------------------------------------------=== # +# Test cases for BigDecimal division +# ===----------------------------------------------------------------------=== # +# === BASIC DIVISION TESTS === +[[division_tests]] +a = "10" +b = "2" +expected = "5" +description = "Simple integer division" + +[[division_tests]] +a = "10" +b = "4" +expected = "2.5" +description = "Integer division resulting in decimal" + +[[division_tests]] +a = "1" +b = "3" +expected = "0.3333333333333333333333333333" +description = "Division resulting in repeating decimal" + +[[division_tests]] +a = "10.5" +b = "2.5" +expected = "4.2" +description = "Decimal division resulting in exact decimal" + +[[division_tests]] +a = "0" +b = "5" +expected = "0" +description = "Zero divided by something" + +# === DIVISION WITH DIFFERENT SCALES === +[[division_tests]] +a = "1.23456789" +b = "0.001" +expected = "1234.56789" +description = "Division by small decimal (scale increase)" + +[[division_tests]] +a = "0.001" +b = "100" +expected = "0.00001" +description = "Small number divided by large (scale increase)" + +[[division_tests]] +a = "1.234" +b = "10" +expected = "0.1234" +description = "Division resulting in scale increase" + +[[division_tests]] +a = "5.75" +b = "0.1" +expected = "57.5" +description = "Division by 0.1 (scale shift)" + +[[division_tests]] +a = "5.75" +b = "0.01" +expected = "575" +description = "Division by 0.01 (scale shift)" + +# === SIGN COMBINATION TESTS === +[[division_tests]] +a = "-10" +b = "2" +expected = "-5" +description = "Negative divided by positive" + +[[division_tests]] +a = "10" +b = "-2" +expected = "-5" +description = "Positive divided by negative" + +[[division_tests]] +a = "-10" +b = "-2" +expected = "5" +description = "Negative divided by negative" + +[[division_tests]] +a = "-0" +b = "5" +expected = "-0" +description = "Negative zero divided by positive" + +[[division_tests]] +a = "0" +b = "-5" +expected = "-0" +description = "Zero divided by negative" + +# === ROUNDING TESTS === +[[division_tests]] +a = "1" +b = "7" +expected = "0.1428571428571428571428571429" +description = "Division with repeating decimal (1/7)" + +[[division_tests]] +a = "2" +b = "3" +expected = "0.6666666666666666666666666667" +description = "Division with repeating decimal (2/3)" + +[[division_tests]] +a = "10" +b = "6" +expected = "1.666666666666666666666666667" +description = "Division with repeating decimal (10/6)" + +[[division_tests]] +a = "1" +b = "9" +expected = "0.1111111111111111111111111111" +description = "Division with repeating digit (1/9)" + +[[division_tests]] +a = "100" +b = "3" +expected = "33.33333333333333333333333333" +description = "Large repeating division" + +# === LARGE AND SMALL NUMBER TESTS === +[[division_tests]] +a = "9999999999999999999999999999" +b = "3" +expected = "3333333333333333333333333333" +description = "Large number simple division" + +[[division_tests]] +a = "1" +b = "9999999999999999999999999999" +expected = "0.0000000000000000000000000001000000000000000000000000000" +description = "One divided by large number" + +[[division_tests]] +a = "0.0000000000000000000000000001" +b = "0.0000000000000000000000000003" +expected = "0.3333333333333333333333333333" +description = "Small number division" + +[[division_tests]] +a = "1000000000000000000000000000000" +b = "0.0000000000000000000000000001" +expected = "1.000000000000000000000000000E+58" +description = "Large divided by small" + +[[division_tests]] +a = "0.0000000000000000000000000001" +b = "1000000000000000000000000000000" +expected = "0.0000000000000000000000000000000000000000000000000000000001" +description = "Small divided by large" + +# === SCIENTIFIC NOTATION TESTS === +[[division_tests]] +a = "1.23e5" +b = "4.56e2" +expected = "269.7368421052631578947368421" +description = "Division with scientific notation" + +[[division_tests]] +a = "1.23e-5" +b = "4.56e-2" +expected = "0.0002697368421052631578947368421" +description = "Division with negative exponents" + +[[division_tests]] +a = "1.23e5" +b = "4.56e-2" +expected = "2697368.421052631578947368421" +description = "Division with mixed exponents" + +# === SPECIAL CASES === +[[division_tests]] +a = "3.14159265358979323846" +b = "2.71828182845904523536" +expected = "1.155727349790921717909242961" +description = "Division of mathematical constants (PI / E)" + +[[division_tests]] +a = "1" +b = "1" +expected = "1" +description = "Division by one" + +[[division_tests]] +a = "0.33333333333333333333333333" +b = "3" +expected = "0.11111111111111111111111111" +description = "Repeating decimal divided by integer" + +[[division_tests]] +a = "5" +b = "10" +expected = "0.5" +description = "Division resulting in exact fraction" + +# === DECIMAL PLACE SHIFTS === +[[division_tests]] +a = "123.456789" +b = "10" +expected = "12.3456789" +description = "Division by 10 (decimal shift left)" + +[[division_tests]] +a = "123.456789" +b = "100" +expected = "1.23456789" +description = "Division by 100 (decimal shift left)" + +[[division_tests]] +a = "123.456789" +b = "1000" +expected = "0.123456789" +description = "Division by 1000 (decimal shift left)" + +[[division_tests]] +a = "123.456789" +b = "0.1" +expected = "1234.56789" +description = "Division by 0.1 (decimal shift right)" + +[[division_tests]] +a = "123.456789" +b = "0.01" +expected = "12345.6789" +description = "Division by 0.01 (decimal shift right)" + +# === PRECISION BOUNDARY TESTS === +[[division_tests]] +a = "1" +b = "3" +expected = "0.3333333333333333333333333333" +description = "Division at precision boundary (1/3)" + +[[division_tests]] +a = "2" +b = "3" +expected = "0.6666666666666666666666666667" +description = "Division at precision boundary (2/3)" + +[[division_tests]] +a = "9.9999999999999999999999999" +b = "9.9999999999999999999999999" +expected = "1" +description = "Division of equal values at precision limit" + +[[division_tests]] +a = "0.0000000000000000000000001" +b = "0.0000000000000000000000001" +expected = "1" +description = "Division of equal small values" + +# === FINANCIAL SCENARIOS === +[[division_tests]] +a = "100.00" +b = "4" +expected = "25.00" +description = "Financial division (dollars)" + +[[division_tests]] +a = "100.00" +b = "3" +expected = "33.33333333333333333333333333" +description = "Financial division with repeating result" + +[[division_tests]] +a = "156.48" +b = "12" +expected = "13.04" +description = "Financial calculation (price per item)" + +# === APPLICATION SCENARIOS === +[[division_tests]] +a = "360" +b = "12" +expected = "30" +description = "Circle division (degrees in a circle / months)" + +[[division_tests]] +a = "1000" +b = "3" +expected = "333.3333333333333333333333333" +description = "Division for equal distribution" + +[[division_tests]] +a = "2.54" +b = "0.01" +expected = "254" +description = "Unit conversion (cm to m)" + +[[division_tests]] +a = "1234.56" +b = "51.44" +expected = "24" +description = "Division resulting in exact integer" + +# === EDGE CASES === +[[division_tests]] +a = "0.0000000000000000000000000009" +b = "0.0000000000000000000000000003" +expected = "3" +description = "Division of very small numbers" + +[[division_tests]] +a = "1" +b = "0.000000000000000000000000001" +expected = "1E+27" +description = "One divided by very small number" + +[[division_tests]] +a = "9999999999999999999999999999.9999999999999999999999999999" +b = "9999999999999999999999999999.9999999999999999999999999999" +expected = "1" +description = "Division of very large equal numbers" + +[[division_tests]] +a = "0" +b = "1" +expected = "0" +description = "Division of zero" diff --git a/tests/bigdecimal/test_data/bigdecimal_compare.toml b/tests/bigdecimal/test_data/bigdecimal_compare.toml index 5e26d83..252a612 100644 --- a/tests/bigdecimal/test_data/bigdecimal_compare.toml +++ b/tests/bigdecimal/test_data/bigdecimal_compare.toml @@ -293,145 +293,145 @@ description = "Near one: a == b" [[greater_than_tests]] a = "10" b = "5" -expected = "true" +expected = "1" description = "Simple case: a > b" [[greater_than_tests]] a = "5" b = "10" -expected = "false" +expected = "0" description = "Simple case: a < b" [[greater_than_tests]] a = "5" b = "5" -expected = "false" +expected = "0" description = "Simple case: a == b" [[greater_than_tests]] a = "-10" b = "5" -expected = "false" +expected = "0" description = "Negative a, positive b, |a| > |b|" [[greater_than_tests]] a = "10" b = "-5" -expected = "true" +expected = "1" description = "Positive a, negative b, |a| > |b|" [[greater_than_tests]] a = "12345678901234567890" b = "1234567890123456789" -expected = "true" +expected = "1" description = "Large numbers: a > b" [[greater_than_tests]] a = "0.000000001" b = "0.0000000001" -expected = "true" +expected = "1" description = "Small decimals: a > b" [[greater_than_tests]] a = "1.23456789" b = "1.23456788" -expected = "true" +expected = "1" description = "Close decimals: a > b" [[greater_than_tests]] a = "1.23e5" b = "4.56e4" -expected = "true" +expected = "1" description = "Scientific notation: a > b" [[greater_than_tests]] a = "3.14159265358979323846" b = "2.71828182845904523536" -expected = "true" +expected = "1" description = "Math constants: PI > E" [[greater_than_tests]] a = "1.61803398874989484820" b = "1.41421356237309504880" -expected = "true" +expected = "1" description = "Math constants: PHI > sqrt(2)" [[greater_than_tests]] a = "0.66666666666666666666" b = "0.33333333333333333333" -expected = "true" +expected = "1" description = "Repeating decimals: 2/3 > 1/3" [[greater_than_tests]] a = "10000000000000000000000000000" b = "1" -expected = "true" +expected = "1" description = "Large vs small: a > b" [[greater_than_tests]] a = "1000.00" b = "999.99" -expected = "true" +expected = "1" description = "Financial numbers: a > b" [[greater_than_tests]] a = "1.79769313486231570E+308" b = "10" -expected = "true" +expected = "1" description = "Near max double precision: a > b" [[greater_than_tests]] a = "9.9999999999999999999999" b = "9.9999999999999999999998" -expected = "true" +expected = "1" description = "Near equal large numbers: a > b" [[greater_than_tests]] a = "1111111110111111111.111111110111111110" b = "987654321098765432.123456789098765432" -expected = "true" +expected = "1" description = "Complex numbers: a > b" [[greater_than_tests]] a = "37.7749" b = "37.7748" -expected = "true" +expected = "1" description = "GPS coordinates: a > b" [[greater_than_tests]] a = "98.6" b = "37.0" -expected = "true" +expected = "1" description = "Temperature conversion: a > b" [[greater_than_tests]] a = "1000.50" b = "243.22" -expected = "true" +expected = "1" description = "Bank balance: a > b" [[greater_than_tests]] a = "987654321987654321.987654321" b = "0.000000000000000000000000001" -expected = "true" +expected = "1" description = "Extreme scale difference: a > b" [[greater_than_tests]] a = "0.0440" b = "0.0015" -expected = "true" +expected = "1" description = "Interest rate: a > b" [[greater_than_tests]] a = "1.23456789012345678901234567" b = "1.23456789012345678901234566" -expected = "true" +expected = "1" description = "Very close numbers: a > b" [[greater_than_tests]] a = "1.000000000000000000000000000" b = "0.999999999999999999999999999" -expected = "true" +expected = "1" description = "Near one: a > b" # Test cases for BigDecimal comparison (<) @@ -439,97 +439,97 @@ description = "Near one: a > b" [[less_than_tests]] a = "10" b = "5" -expected = "false" +expected = "0" description = "Simple case: a > b" [[less_than_tests]] a = "5" b = "10" -expected = "true" +expected = "1" description = "Simple case: a < b" [[less_than_tests]] a = "5" b = "5" -expected = "false" +expected = "0" description = "Simple case: a == b" [[less_than_tests]] a = "-5" b = "10" -expected = "true" +expected = "1" description = "Negative a, positive b, |a| < |b|" [[less_than_tests]] a = "5" b = "-10" -expected = "false" +expected = "0" description = "Positive a, negative b, |a| < |b|" [[less_than_tests]] a = "-10" b = "-5" -expected = "true" +expected = "1" description = "Negative a, negative b, |a| > |b|" [[less_than_tests]] a = "-5" b = "-10" -expected = "false" +expected = "0" description = "Negative a, negative b, |a| < |b|" [[less_than_tests]] a = "1234567890123456789" b = "12345678901234567890" -expected = "true" +expected = "1" description = "Large numbers: a < b" [[less_than_tests]] a = "0.0000000001" b = "0.000000001" -expected = "true" +expected = "1" description = "Small decimals: a < b" [[less_than_tests]] a = "1.23456788" b = "1.23456789" -expected = "true" +expected = "1" description = "Close decimals: a < b" [[less_than_tests]] a = "1.23e-5" b = "4.56e-2" -expected = "true" +expected = "1" description = "Scientific notation: a < b" [[less_than_tests]] a = "0.000000000000000000000000001" b = "1" -expected = "true" +expected = "1" description = "Small vs large: a < b" [[less_than_tests]] a = "999.99" b = "1000.00" -expected = "true" +expected = "1" description = "Financial numbers: a < b" [[less_than_tests]] a = "9.9999999999999999999998" b = "9.9999999999999999999999" -expected = "true" +expected = "1" description = "Near equal large numbers: a < b" [[less_than_tests]] a = "1.23456789012345678901234566" b = "1.23456789012345678901234567" -expected = "true" +expected = "1" description = "Very close numbers: a < b" [[less_than_tests]] a = "0.999999999999999999999999999" b = "1.000000000000000000000000000" -expected = "true" +expected = "1" description = "Near one: a < b" # Test cases for BigDecimal comparison (>=) @@ -537,19 +537,19 @@ description = "Near one: a < b" [[greater_than_or_equal_tests]] a = "10" b = "5" -expected = "true" +expected = "1" description = "Simple case: a > b" [[greater_than_or_equal_tests]] a = "5" b = "10" -expected = "false" +expected = "0" description = "Simple case: a < b" [[greater_than_or_equal_tests]] a = "5" b = "5" -expected = "true" +expected = "1" description = "Simple case: a == b" # Test cases for BigDecimal comparison (<=) @@ -557,19 +557,19 @@ description = "Simple case: a == b" [[less_than_or_equal_tests]] a = "10" b = "5" -expected = "false" +expected = "0" description = "Simple case: a > b" [[less_than_or_equal_tests]] a = "5" b = "10" -expected = "true" +expected = "1" description = "Simple case: a < b" [[less_than_or_equal_tests]] a = "5" b = "5" -expected = "true" +expected = "1" description = "Simple case: a == b" # Test cases for BigDecimal comparison (==) @@ -577,85 +577,85 @@ description = "Simple case: a == b" [[equal_tests]] a = "10" b = "5" -expected = "false" +expected = "0" description = "Simple case: a > b" [[equal_tests]] a = "5" b = "10" -expected = "false" +expected = "0" description = "Simple case: a < b" [[equal_tests]] a = "5" b = "5" -expected = "true" +expected = "1" description = "Simple case: a == b" [[equal_tests]] a = "-5" b = "5" -expected = "false" +expected = "0" description = "Negative a, positive b, |a| == |b|" [[equal_tests]] a = "5" b = "-5" -expected = "false" +expected = "0" description = "Positive a, negative b, |a| == |b|" [[equal_tests]] a = "-0" b = "0" -expected = "true" +expected = "1" description = "Negative zero vs positive zero" [[equal_tests]] a = "0" b = "-0" -expected = "true" +expected = "1" description = "Positive zero vs negative zero" [[equal_tests]] a = "99999999999999999999" b = "99999999999999999999" -expected = "true" +expected = "1" description = "Large numbers: a == b" [[equal_tests]] a = "0.000000001" b = "0.000000001" -expected = "true" +expected = "1" description = "Small decimals: a == b" [[equal_tests]] a = "1.23456789" b = "1.23456789" -expected = "true" +expected = "1" description = "Close decimals: a == b" [[equal_tests]] a = "1.23e5" b = "1.23e5" -expected = "true" +expected = "1" description = "Scientific notation: a == b" [[equal_tests]] a = "1000.00" b = "1000.00" -expected = "true" +expected = "1" description = "Financial numbers: a == b" [[equal_tests]] a = "1.23456789012345678901234567" b = "1.23456789012345678901234567" -expected = "true" +expected = "1" description = "Very close numbers: a == b" [[equal_tests]] a = "1.000000000000000000000000000" b = "1.000000000000000000000000000" -expected = "true" +expected = "1" description = "Near one: a == b" # Test cases for BigDecimal comparison (!=) @@ -663,17 +663,17 @@ description = "Near one: a == b" [[not_equal_tests]] a = "10" b = "5" -expected = "true" +expected = "1" description = "Simple case: a > b" [[not_equal_tests]] a = "5" b = "10" -expected = "true" +expected = "1" description = "Simple case: a < b" [[not_equal_tests]] a = "5" b = "5" -expected = "false" +expected = "0" description = "Simple case: a == b" \ No newline at end of file diff --git a/tests/bigdecimal/test_data/bigdecimal_divide.toml b/tests/bigdecimal/test_data/bigdecimal_divide.toml deleted file mode 100644 index 614f117..0000000 --- a/tests/bigdecimal/test_data/bigdecimal_divide.toml +++ /dev/null @@ -1,323 +0,0 @@ -# === BASIC DIVISION TESTS === -[[division_tests]] -a = "10" -b = "2" -expected = "5" -description = "Simple integer division" - -[[division_tests]] -a = "10" -b = "4" -expected = "2.5" -description = "Integer division resulting in decimal" - -[[division_tests]] -a = "1" -b = "3" -expected = "0.3333333333333333333333333333" -description = "Division resulting in repeating decimal" - -[[division_tests]] -a = "10.5" -b = "2.5" -expected = "4.2" -description = "Decimal division resulting in exact decimal" - -[[division_tests]] -a = "0" -b = "5" -expected = "0" -description = "Zero divided by something" - -# === DIVISION WITH DIFFERENT SCALES === -[[division_tests]] -a = "1.23456789" -b = "0.001" -expected = "1234.56789" -description = "Division by small decimal (scale increase)" - -[[division_tests]] -a = "0.001" -b = "100" -expected = "0.00001" -description = "Small number divided by large (scale increase)" - -[[division_tests]] -a = "1.234" -b = "10" -expected = "0.1234" -description = "Division resulting in scale increase" - -[[division_tests]] -a = "5.75" -b = "0.1" -expected = "57.5" -description = "Division by 0.1 (scale shift)" - -[[division_tests]] -a = "5.75" -b = "0.01" -expected = "575" -description = "Division by 0.01 (scale shift)" - -# === SIGN COMBINATION TESTS === -[[division_tests]] -a = "-10" -b = "2" -expected = "-5" -description = "Negative divided by positive" - -[[division_tests]] -a = "10" -b = "-2" -expected = "-5" -description = "Positive divided by negative" - -[[division_tests]] -a = "-10" -b = "-2" -expected = "5" -description = "Negative divided by negative" - -[[division_tests]] -a = "-0" -b = "5" -expected = "-0" -description = "Negative zero divided by positive" - -[[division_tests]] -a = "0" -b = "-5" -expected = "-0" -description = "Zero divided by negative" - -# === ROUNDING TESTS === -[[division_tests]] -a = "1" -b = "7" -expected = "0.1428571428571428571428571429" -description = "Division with repeating decimal (1/7)" - -[[division_tests]] -a = "2" -b = "3" -expected = "0.6666666666666666666666666667" -description = "Division with repeating decimal (2/3)" - -[[division_tests]] -a = "10" -b = "6" -expected = "1.666666666666666666666666667" -description = "Division with repeating decimal (10/6)" - -[[division_tests]] -a = "1" -b = "9" -expected = "0.1111111111111111111111111111" -description = "Division with repeating digit (1/9)" - -[[division_tests]] -a = "100" -b = "3" -expected = "33.33333333333333333333333333" -description = "Large repeating division" - -# === LARGE AND SMALL NUMBER TESTS === -[[division_tests]] -a = "9999999999999999999999999999" -b = "3" -expected = "3333333333333333333333333333" -description = "Large number simple division" - -[[division_tests]] -a = "1" -b = "9999999999999999999999999999" -expected = "0.0000000000000000000000000001000000000000000000000000000" -description = "One divided by large number" - -[[division_tests]] -a = "0.0000000000000000000000000001" -b = "0.0000000000000000000000000003" -expected = "0.3333333333333333333333333333" -description = "Small number division" - -[[division_tests]] -a = "1000000000000000000000000000000" -b = "0.0000000000000000000000000001" -expected = "1.000000000000000000000000000E+58" -description = "Large divided by small" - -[[division_tests]] -a = "0.0000000000000000000000000001" -b = "1000000000000000000000000000000" -expected = "0.0000000000000000000000000000000000000000000000000000000001" -description = "Small divided by large" - -# === SCIENTIFIC NOTATION TESTS === -[[division_tests]] -a = "1.23e5" -b = "4.56e2" -expected = "269.7368421052631578947368421" -description = "Division with scientific notation" - -[[division_tests]] -a = "1.23e-5" -b = "4.56e-2" -expected = "0.0002697368421052631578947368421" -description = "Division with negative exponents" - -[[division_tests]] -a = "1.23e5" -b = "4.56e-2" -expected = "2697368.421052631578947368421" -description = "Division with mixed exponents" - -# === SPECIAL CASES === -[[division_tests]] -a = "3.14159265358979323846" -b = "2.71828182845904523536" -expected = "1.155727349790921717909242961" -description = "Division of mathematical constants (PI / E)" - -[[division_tests]] -a = "1" -b = "1" -expected = "1" -description = "Division by one" - -[[division_tests]] -a = "0.33333333333333333333333333" -b = "3" -expected = "0.11111111111111111111111111" -description = "Repeating decimal divided by integer" - -[[division_tests]] -a = "5" -b = "10" -expected = "0.5" -description = "Division resulting in exact fraction" - -# === DECIMAL PLACE SHIFTS === -[[division_tests]] -a = "123.456789" -b = "10" -expected = "12.3456789" -description = "Division by 10 (decimal shift left)" - -[[division_tests]] -a = "123.456789" -b = "100" -expected = "1.23456789" -description = "Division by 100 (decimal shift left)" - -[[division_tests]] -a = "123.456789" -b = "1000" -expected = "0.123456789" -description = "Division by 1000 (decimal shift left)" - -[[division_tests]] -a = "123.456789" -b = "0.1" -expected = "1234.56789" -description = "Division by 0.1 (decimal shift right)" - -[[division_tests]] -a = "123.456789" -b = "0.01" -expected = "12345.6789" -description = "Division by 0.01 (decimal shift right)" - -# === PRECISION BOUNDARY TESTS === -[[division_tests]] -a = "1" -b = "3" -expected = "0.3333333333333333333333333333" -description = "Division at precision boundary (1/3)" - -[[division_tests]] -a = "2" -b = "3" -expected = "0.6666666666666666666666666667" -description = "Division at precision boundary (2/3)" - -[[division_tests]] -a = "9.9999999999999999999999999" -b = "9.9999999999999999999999999" -expected = "1" -description = "Division of equal values at precision limit" - -[[division_tests]] -a = "0.0000000000000000000000001" -b = "0.0000000000000000000000001" -expected = "1" -description = "Division of equal small values" - -# === FINANCIAL SCENARIOS === -[[division_tests]] -a = "100.00" -b = "4" -expected = "25.00" -description = "Financial division (dollars)" - -[[division_tests]] -a = "100.00" -b = "3" -expected = "33.33333333333333333333333333" -description = "Financial division with repeating result" - -[[division_tests]] -a = "156.48" -b = "12" -expected = "13.04" -description = "Financial calculation (price per item)" - -# === APPLICATION SCENARIOS === -[[division_tests]] -a = "360" -b = "12" -expected = "30" -description = "Circle division (degrees in a circle / months)" - -[[division_tests]] -a = "1000" -b = "3" -expected = "333.3333333333333333333333333" -description = "Division for equal distribution" - -[[division_tests]] -a = "2.54" # cm -b = "0.01" # convert to m -expected = "254" -description = "Unit conversion (cm to m)" - -[[division_tests]] -a = "1234.56" -b = "51.44" -expected = "24" -description = "Division resulting in exact integer" - -# === EDGE CASES === -[[division_tests]] -a = "0.0000000000000000000000000009" -b = "0.0000000000000000000000000003" -expected = "3" -description = "Division of very small numbers" - -[[division_tests]] -a = "1" -b = "0.000000000000000000000000001" -expected = "1E+27" -description = "One divided by very small number" - -[[division_tests]] -a = "9999999999999999999999999999.9999999999999999999999999999" -b = "9999999999999999999999999999.9999999999999999999999999999" -expected = "1" -description = "Division of very large equal numbers" - -[[division_tests]] -a = "0" -b = "1" -expected = "0" -description = "Division of zero" diff --git a/tests/bigdecimal/test_data/bigdecimal_exponential.toml b/tests/bigdecimal/test_data/bigdecimal_exponential.toml index 7f0ac59..80a8ae6 100644 --- a/tests/bigdecimal/test_data/bigdecimal_exponential.toml +++ b/tests/bigdecimal/test_data/bigdecimal_exponential.toml @@ -1,290 +1,345 @@ # === BASIC SQUARE ROOT TESTS === [[sqrt_tests]] -input = "0" +a = "0" +b = "" expected = "0" description = "Square root of zero" [[sqrt_tests]] -input = "1" +a = "1" +b = "" expected = "1" description = "Square root of one" [[sqrt_tests]] -input = "4" +a = "4" +b = "" expected = "2" description = "Square root of perfect square (small)" [[sqrt_tests]] -input = "9" +a = "9" +b = "" expected = "3" description = "Square root of perfect square (single digit)" [[sqrt_tests]] -input = "16" +a = "16" +b = "" expected = "4" description = "Square root of perfect square (16)" [[sqrt_tests]] -input = "25" +a = "25" +b = "" expected = "5" description = "Square root of perfect square (25)" [[sqrt_tests]] -input = "100" +a = "100" +b = "" expected = "10" description = "Square root of perfect square (100)" # === NON-PERFECT SQUARES === [[sqrt_tests]] -input = "2" +a = "2" +b = "" expected = "1.414213562373095048801688724" description = "Square root of 2 (irrational)" [[sqrt_tests]] -input = "3" +a = "3" +b = "" expected = "1.732050807568877293527446342" description = "Square root of 3 (irrational)" [[sqrt_tests]] -input = "5" +a = "5" +b = "" expected = "2.236067977499789696409173669" description = "Square root of 5 (irrational)" [[sqrt_tests]] -input = "10" +a = "10" +b = "" expected = "3.162277660168379331998893544" description = "Square root of 10 (irrational)" # === DECIMAL INPUTS === [[sqrt_tests]] -input = "0.25" +a = "0.25" +b = "" expected = "0.5" description = "Square root of 0.25" [[sqrt_tests]] -input = "0.01" +a = "0.01" +b = "" expected = "0.1" description = "Square root of 0.01" [[sqrt_tests]] -input = "0.0625" +a = "0.0625" +b = "" expected = "0.25" description = "Square root of 0.0625" [[sqrt_tests]] -input = "2.25" +a = "2.25" +b = "" expected = "1.5" description = "Square root of 2.25" [[sqrt_tests]] -input = "12.25" +a = "12.25" +b = "" expected = "3.5" description = "Square root of 12.25" # === LARGE NUMBERS === [[sqrt_tests]] -input = "1000000" +a = "1000000" +b = "" expected = "1000" description = "Square root of large perfect square" [[sqrt_tests]] -input = "9999999999" +a = "9999999999" +b = "" expected = "99999.99999499999999987500000" description = "Square root of large near-perfect square" [[sqrt_tests]] -input = "1000000000000000000000000000" +a = "1000000000000000000000000000" +b = "" expected = "31622776601683.79331998893544" description = "Square root of very large imperfect square" # === SMALL NUMBERS === [[sqrt_tests]] -input = "0.0001" +a = "0.0001" +b = "" expected = "0.01" description = "Square root of small number" [[sqrt_tests]] -input = "0.000000000001" +a = "0.000000000001" +b = "" expected = "0.000001" description = "Square root of very small number" [[sqrt_tests]] -input = "0.0000000000000000000000000001" +a = "0.0000000000000000000000000001" +b = "" expected = "1E-14" description = "Square root of extremely small number" # === SCIENTIFIC NOTATION === [[sqrt_tests]] -input = "1e10" +a = "1e10" +b = "" expected = "1E+5" description = "Square root with scientific notation (positive exponent)" [[sqrt_tests]] -input = "1e-10" +a = "1e-10" +b = "" expected = "0.00001" description = "Square root with scientific notation (negative exponent)" # === PRECISION TESTS === [[sqrt_tests]] -input = "2" +a = "2" +b = "" expected = "1.414213562373095048801688724" description = "High precision square root of 2" [[sqrt_tests]] -input = "0.9999999999999999" +a = "0.9999999999999999" +b = "" expected = "0.9999999999999999500000000000" description = "Square root slightly less than 1" [[sqrt_tests]] -input = "1.0000000000000001" +a = "1.0000000000000001" +b = "" expected = "1.000000000000000050000000000" description = "Square root slightly more than 1" # === APPLICATION SCENARIOS === [[sqrt_tests]] -input = "3.14159265358979323846" +a = "3.14159265358979323846" +b = "" expected = "1.772453850905516027297421799" description = "Square root of π" [[sqrt_tests]] -input = "2.71828182845904523536" +a = "2.71828182845904523536" +b = "" expected = "1.648721270700128146848563608" description = "Square root of e" # === BASIC NATURAL LOGARITHM TESTS === [[ln_tests]] -input = "1" +a = "1" +b = "" expected = "0" description = "Natural logarithm of 1 (exactly 0)" [[ln_tests]] -input = "2.718281828459045235360287471" +a = "2.718281828459045235360287471" +b = "" expected = "0.9999999999999999999999999999" description = "Natural logarithm of e (approximately 1)" [[ln_tests]] -input = "10" +a = "10" +b = "" expected = "2.302585092994045684017991455" description = "Natural logarithm of 10" [[ln_tests]] -input = "2" +a = "2" +b = "" expected = "0.6931471805599453094172321215" description = "Natural logarithm of 2" [[ln_tests]] -input = "0.5" +a = "0.5" +b = "" expected = "-0.6931471805599453094172321215" description = "Natural logarithm of 0.5 (negative result)" # === POWERS OF e === [[ln_tests]] -input = "7.389056098930650227230427461" +a = "7.389056098930650227230427461" +b = "" expected = "2.000000000000000000000000000" description = "Natural logarithm of e^2 (exactly 2)" [[ln_tests]] -input = "20.08553692318766774092852965" +a = "20.08553692318766774092852965" +b = "" expected = "3.000000000000000000000000000" description = "Natural logarithm of e^3 (exactly 3)" [[ln_tests]] -input = "0.3678794411714423215955237702" +a = "0.3678794411714423215955237702" +b = "" expected = "-0.9999999999999999999999999999" description = "Natural logarithm of 1/e (exactly -1)" [[ln_tests]] -input = "0.1353352832366126918939994949" +a = "0.1353352832366126918939994949" +b = "" expected = "-2.000000000000000000000000001" description = "Natural logarithm of 1/e^2 (exactly -2)" # === POWERS OF 10 === [[ln_tests]] -input = "100" +a = "100" +b = "" expected = "4.605170185988091368035982909" description = "Natural logarithm of 10^2" [[ln_tests]] -input = "0.01" +a = "0.01" +b = "" expected = "-4.605170185988091368035982909" description = "Natural logarithm of 10^-2" [[ln_tests]] -input = "1000" +a = "1000" +b = "" expected = "6.907755278982137052053974364" description = "Natural logarithm of 10^3" [[ln_tests]] -input = "0.001" +a = "0.001" +b = "" expected = "-6.907755278982137052053974364" description = "Natural logarithm of 10^-3" # === SMALL NUMBERS === [[ln_tests]] -input = "0.1" +a = "0.1" +b = "" expected = "-2.302585092994045684017991455" description = "Natural logarithm of 0.1" [[ln_tests]] -input = "0.00001" +a = "0.00001" +b = "" expected = "-11.51292546497022842008995727" description = "Natural logarithm of 1e-5" [[ln_tests]] -input = "0.0000000001" +a = "0.0000000001" +b = "" expected = "-23.02585092994045684017991455" description = "Natural logarithm of 1e-10" # === LARGE NUMBERS === [[ln_tests]] -input = "1000000" +a = "1000000" +b = "" expected = "13.81551055796427410410794873" description = "Natural logarithm of 1e6" [[ln_tests]] -input = "1000000000000" +a = "1000000000000" +b = "" expected = "27.63102111592854820821589746" description = "Natural logarithm of 1e12" [[ln_tests]] -input = "1e50" +a = "1e50" +b = "" expected = "115.1292546497022842008995727" description = "Natural logarithm of 1e50" # === VALUES NEAR 1 === [[ln_tests]] -input = "0.9" +a = "0.9" +b = "" expected = "-0.1053605156578263012275009808" description = "Natural logarithm of 0.9 (near 1)" [[ln_tests]] -input = "1.1" +a = "1.1" +b = "" expected = "0.09531017980432486004395212328" description = "Natural logarithm of 1.1 (near 1)" [[ln_tests]] -input = "0.999999" +a = "0.999999" +b = "" expected = "-0.000001000000500000333333583333533" description = "Natural logarithm very close to 0 (0.999999)" [[ln_tests]] -input = "1.000001" +a = "1.000001" +b = "" expected = "9.999995000003333330833335333E-7" description = "Natural logarithm very close to 0 (1.000001)" # === MATHEMATICAL CONSTANTS === [[ln_tests]] -input = "3.141592653589793238462643383" +a = "3.141592653589793238462643383" +b = "" expected = "1.144729885849400174143427351" description = "Natural logarithm of π" [[ln_tests]] -input = "1.618033988749894848204586834" +a = "1.618033988749894848204586834" +b = "" expected = "0.4812118250596034474977589132" description = "Natural logarithm of φ (golden ratio)" [[ln_tests]] -input = "1.414213562373095048801688724" +a = "1.414213562373095048801688724" +b = "" expected = "0.3465735902799726547086160606" description = "Natural logarithm of √2" diff --git a/tests/biguint/test_biguint_arithmetics.mojo b/tests/biguint/test_biguint_arithmetics.mojo index 34cf50a..78e5822 100644 --- a/tests/biguint/test_biguint_arithmetics.mojo +++ b/tests/biguint/test_biguint_arithmetics.mojo @@ -5,15 +5,14 @@ BigUInt is an unsigned integer type, so it doesn't support negative values. import testing from decimojo.biguint.biguint import BigUInt -from decimojo.tests import TestCase, load_test_cases -import tomlmojo +from decimojo.tests import TestCase, parse_file, load_test_cases alias file_path = "tests/biguint/test_data/biguint_arithmetics.toml" fn test_biguint_arithmetics() raises: # Load test cases from TOML file - var toml = tomlmojo.parse_file(file_path) + var toml = parse_file(file_path) var test_cases: List[TestCase] print("------------------------------------------------------") diff --git a/tests/biguint/test_biguint_truncate_divide.mojo b/tests/biguint/test_biguint_truncate_divide.mojo index 7c31813..8bee336 100644 --- a/tests/biguint/test_biguint_truncate_divide.mojo +++ b/tests/biguint/test_biguint_truncate_divide.mojo @@ -7,9 +7,8 @@ Tests also compare results with Python's built-in int type for verification. import testing import decimojo.biguint.arithmetics from decimojo.biguint.biguint import BigUInt -from decimojo.tests import TestCase, load_test_cases +from decimojo.tests import TestCase, parse_file, load_test_cases from python import Python, PythonObject -from tomlmojo import parse_file alias file_path = "tests/biguint/test_data/biguint_truncate_divide.toml" @@ -37,7 +36,7 @@ fn test_biguint_truncate_divide() raises: # Get Python's built-in int module var py = Python.import_module("builtins") # Load test cases from TOML file - var toml = tomlmojo.parse_file(file_path) + var toml = parse_file(file_path) var test_cases: List[TestCase] run_test(toml, "basic_division_tests", "basic truncate division") diff --git a/tests/decimal/test_arithmetics.mojo b/tests/decimal/test_decimal_arithmetics.mojo similarity index 100% rename from tests/decimal/test_arithmetics.mojo rename to tests/decimal/test_decimal_arithmetics.mojo diff --git a/tests/decimal/test_comparison.mojo b/tests/decimal/test_decimal_comparison.mojo similarity index 100% rename from tests/decimal/test_comparison.mojo rename to tests/decimal/test_decimal_comparison.mojo diff --git a/tests/decimal/test_divide.mojo b/tests/decimal/test_decimal_divide.mojo similarity index 100% rename from tests/decimal/test_divide.mojo rename to tests/decimal/test_decimal_divide.mojo diff --git a/tests/decimal/test_exp.mojo b/tests/decimal/test_decimal_exp.mojo similarity index 100% rename from tests/decimal/test_exp.mojo rename to tests/decimal/test_decimal_exp.mojo diff --git a/tests/decimal/test_factorial.mojo b/tests/decimal/test_decimal_factorial.mojo similarity index 100% rename from tests/decimal/test_factorial.mojo rename to tests/decimal/test_decimal_factorial.mojo diff --git a/tests/decimal/test_from_components.mojo b/tests/decimal/test_decimal_from_components.mojo similarity index 100% rename from tests/decimal/test_from_components.mojo rename to tests/decimal/test_decimal_from_components.mojo diff --git a/tests/decimal/test_from_float.mojo b/tests/decimal/test_decimal_from_float.mojo similarity index 100% rename from tests/decimal/test_from_float.mojo rename to tests/decimal/test_decimal_from_float.mojo diff --git a/tests/decimal/test_from_int.mojo b/tests/decimal/test_decimal_from_int.mojo similarity index 100% rename from tests/decimal/test_from_int.mojo rename to tests/decimal/test_decimal_from_int.mojo diff --git a/tests/decimal/test_from_string.mojo b/tests/decimal/test_decimal_from_string.mojo similarity index 100% rename from tests/decimal/test_from_string.mojo rename to tests/decimal/test_decimal_from_string.mojo diff --git a/tests/decimal/test_ln.mojo b/tests/decimal/test_decimal_ln.mojo similarity index 100% rename from tests/decimal/test_ln.mojo rename to tests/decimal/test_decimal_ln.mojo diff --git a/tests/decimal/test_log.mojo b/tests/decimal/test_decimal_log.mojo similarity index 100% rename from tests/decimal/test_log.mojo rename to tests/decimal/test_decimal_log.mojo diff --git a/tests/decimal/test_log10.mojo b/tests/decimal/test_decimal_log10.mojo similarity index 100% rename from tests/decimal/test_log10.mojo rename to tests/decimal/test_decimal_log10.mojo diff --git a/tests/decimal/test_modulo.mojo b/tests/decimal/test_decimal_modulo.mojo similarity index 100% rename from tests/decimal/test_modulo.mojo rename to tests/decimal/test_decimal_modulo.mojo diff --git a/tests/decimal/test_multiply.mojo b/tests/decimal/test_decimal_multiply.mojo similarity index 100% rename from tests/decimal/test_multiply.mojo rename to tests/decimal/test_decimal_multiply.mojo diff --git a/tests/decimal/test_power.mojo b/tests/decimal/test_decimal_power.mojo similarity index 100% rename from tests/decimal/test_power.mojo rename to tests/decimal/test_decimal_power.mojo diff --git a/tests/decimal/test_quantize.mojo b/tests/decimal/test_decimal_quantize.mojo similarity index 100% rename from tests/decimal/test_quantize.mojo rename to tests/decimal/test_decimal_quantize.mojo diff --git a/tests/decimal/test_root.mojo b/tests/decimal/test_decimal_root.mojo similarity index 100% rename from tests/decimal/test_root.mojo rename to tests/decimal/test_decimal_root.mojo diff --git a/tests/decimal/test_round.mojo b/tests/decimal/test_decimal_round.mojo similarity index 100% rename from tests/decimal/test_round.mojo rename to tests/decimal/test_decimal_round.mojo diff --git a/tests/decimal/test_sqrt.mojo b/tests/decimal/test_decimal_sqrt.mojo similarity index 100% rename from tests/decimal/test_sqrt.mojo rename to tests/decimal/test_decimal_sqrt.mojo diff --git a/tests/decimal/test_to_float.mojo b/tests/decimal/test_decimal_to_float.mojo similarity index 100% rename from tests/decimal/test_to_float.mojo rename to tests/decimal/test_decimal_to_float.mojo diff --git a/tests/decimal/test_to_int.mojo b/tests/decimal/test_decimal_to_int.mojo similarity index 100% rename from tests/decimal/test_to_int.mojo rename to tests/decimal/test_decimal_to_int.mojo diff --git a/tests/decimal/test_to_string.mojo b/tests/decimal/test_decimal_to_string.mojo similarity index 100% rename from tests/decimal/test_to_string.mojo rename to tests/decimal/test_decimal_to_string.mojo diff --git a/tests/decimal/test_truncate_divide.mojo b/tests/decimal/test_decimal_truncate_divide.mojo similarity index 100% rename from tests/decimal/test_truncate_divide.mojo rename to tests/decimal/test_decimal_truncate_divide.mojo diff --git a/tests/decimal/test_utility.mojo b/tests/decimal/test_decimal_utility.mojo similarity index 100% rename from tests/decimal/test_utility.mojo rename to tests/decimal/test_decimal_utility.mojo