Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mojoproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test = "magic run package && magic run mojo test tests --filter"
t = "clear && magic run package && magic run mojo test tests --filter"

# benches
bench_dec = "magic run package && cd benches/decimal && magic run mojo -I ../ bench.mojo && cd ../.. && magic run clean"
bench_bint = "magic run package && cd benches/bigint && magic run mojo -I ../ bench.mojo && cd ../.. && magic run clean"
bench_buint = "magic run package && cd benches/biguint && magic run mojo -I ../ bench.mojo && cd ../.. && magic run clean"
bench_bdec = "magic run package && cd benches/bigdecimal && magic run mojo -I ../ bench.mojo && cd ../.. && magic run clean"
bench_dec = "clear && magic run package && cd benches/decimal && magic run mojo -I ../ bench.mojo && cd ../.. && magic run clean"
bench_bint = "clear && magic run package && cd benches/bigint && magic run mojo -I ../ bench.mojo && cd ../.. && magic run clean"
bench_buint = "clear && magic run package && cd benches/biguint && magic run mojo -I ../ bench.mojo && cd ../.. && magic run clean"
bench_bdec = "clear && magic run package && cd benches/bigdecimal && magic run mojo -I ../ bench.mojo && cd ../.. && magic run clean"
70 changes: 70 additions & 0 deletions tests/bigdecimal/test_bigdecimal_arithmetics.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,80 @@ fn test_add() raises:
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...")

# 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

try:
# Using String comparison for easier debugging
testing.assert_equal(
String(result), String(expected), 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:",
String(result),
"\n Error:",
String(e),
)
failed += 1

print("BigDecimal subtraction tests:", passed, "passed,", failed, "failed")
testing.assert_equal(failed, 0, "All subtraction tests should pass")


fn main() raises:
print("Running BigDecimal arithmetic tests")

# Run addition tests
test_add()

# Run subtraction tests
test_subtract()

print("All BigDecimal arithmetic tests passed!")
Loading