Add comprehensive unit tests for AlyaNum with enhanced assertion helpers for detailed test output#4
Conversation
… and large number support Co-authored-by: evilbocchi <71329833+evilbocchi@users.noreply.github.com>
|
Create helper functions like assertMoreThan/assertLessThan/etc. instead of assert for more detailed test outputs |
Co-authored-by: evilbocchi <71329833+evilbocchi@users.noreply.github.com>
Co-authored-by: evilbocchi <71329833+evilbocchi@users.noreply.github.com>
I've added detailed assertion helper functions to replace generic
These now provide detailed error messages with actual AlyaNum values instead of generic assertion failures. For example, instead of just "assertion failed", you now get outputs like "Expected E(100)2K > E(100)1K: large a + b should equal b + a". Committed in 3dca1b5. |
Eliminated the unused 'minMult' variable from the add function in init.luau to clean up the code and improve readability.
Eliminated an unnecessary print statement that output file contents during test execution. This cleans up the test runner output.
Added descriptive comments to constants related to number formatting and float64 limits in init.luau for improved code clarity and maintainability.
Improves AlyaNum.fromString to correctly handle scientific notation, including negative exponents and mantissas. Updates tests to use more accurate representations of large numbers, adjusts assertions for edge cases, and relaxes string parsing tolerance for very large or small numbers.
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Join our Discord community for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Pull Request Overview
This PR significantly expands the AlyaNum library's test suite from 20 to 68 comprehensive unit tests, adding thorough validation for mathematical properties, large number operations, and edge cases. The changes enhance test coverage for numbers up to 10^^^^^10 (heptation level) and improve debugging capabilities.
Key changes:
- Added 48 new comprehensive unit tests covering mathematical properties, large numbers, and edge cases
- Introduced enhanced assertion helper functions that provide detailed error messages with actual vs expected values
- Removed debug print statement from test runner for cleaner output
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 13 comments.
| File | Description |
|---|---|
| testRunner.luau | Removed debug print statement to clean up test output |
| test/tests.luau | Added 48 new tests and 5 enhanced assertion helper functions for better test diagnostics |
| src/init.luau | Refactored scientific notation parsing logic and improved variable naming |
|
|
||
| function assertMoreThan(actual, expected, msg) | ||
| if not actual:moreThan(expected) then | ||
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " > " .. tostring(expected:toString()), 2) |
There was a problem hiding this comment.
The double tostring() call is redundant since toString() already returns a string. Consider using (msg or "") .. " Expected " .. actual:toString() .. " > " .. expected:toString()
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " > " .. tostring(expected:toString()), 2) | |
| error((msg or "") .. " Expected " .. actual:toString() .. " > " .. expected:toString(), 2) |
| error((msg or "") .. " Expected " .. tostring(expected:toString()) .. ", got " .. tostring(actual:toString()), 2) | ||
| end | ||
| end | ||
|
|
||
| function assertMoreThan(actual, expected, msg) | ||
| if not actual:moreThan(expected) then | ||
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " > " .. tostring(expected:toString()), 2) | ||
| end | ||
| end | ||
|
|
||
| function assertLessThan(actual, expected, msg) | ||
| if not actual:lessThan(expected) then | ||
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " < " .. tostring(expected:toString()), 2) | ||
| end | ||
| end | ||
|
|
||
| function assertMoreEquals(actual, expected, msg) | ||
| if not actual:moreEquals(expected) then | ||
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " >= " .. tostring(expected:toString()), 2) | ||
| end | ||
| end | ||
|
|
||
| function assertLessEquals(actual, expected, msg) | ||
| if not actual:lessEquals(expected) then | ||
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " <= " .. tostring(expected:toString()), 2) |
There was a problem hiding this comment.
The double tostring() call is redundant since toString() already returns a string. Consider using (msg or "") .. " Expected " .. actual:toString() .. " < " .. expected:toString()
| error((msg or "") .. " Expected " .. tostring(expected:toString()) .. ", got " .. tostring(actual:toString()), 2) | |
| end | |
| end | |
| function assertMoreThan(actual, expected, msg) | |
| if not actual:moreThan(expected) then | |
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " > " .. tostring(expected:toString()), 2) | |
| end | |
| end | |
| function assertLessThan(actual, expected, msg) | |
| if not actual:lessThan(expected) then | |
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " < " .. tostring(expected:toString()), 2) | |
| end | |
| end | |
| function assertMoreEquals(actual, expected, msg) | |
| if not actual:moreEquals(expected) then | |
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " >= " .. tostring(expected:toString()), 2) | |
| end | |
| end | |
| function assertLessEquals(actual, expected, msg) | |
| if not actual:lessEquals(expected) then | |
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " <= " .. tostring(expected:toString()), 2) | |
| error((msg or "") .. " Expected " .. expected:toString() .. ", got " .. actual:toString(), 2) | |
| end | |
| end | |
| function assertMoreThan(actual, expected, msg) | |
| if not actual:moreThan(expected) then | |
| error((msg or "") .. " Expected " .. actual:toString() .. " > " .. expected:toString(), 2) | |
| end | |
| end | |
| function assertLessThan(actual, expected, msg) | |
| if not actual:lessThan(expected) then | |
| error((msg or "") .. " Expected " .. actual:toString() .. " < " .. expected:toString(), 2) | |
| end | |
| end | |
| function assertMoreEquals(actual, expected, msg) | |
| if not actual:moreEquals(expected) then | |
| error((msg or "") .. " Expected " .. actual:toString() .. " >= " .. expected:toString(), 2) | |
| end | |
| end | |
| function assertLessEquals(actual, expected, msg) | |
| if not actual:lessEquals(expected) then | |
| error((msg or "") .. " Expected " .. actual:toString() .. " <= " .. expected:toString(), 2) |
| error((msg or "") .. " Expected " .. tostring(expected:toString()) .. ", got " .. tostring(actual:toString()), 2) | ||
| end | ||
| end | ||
|
|
||
| function assertMoreThan(actual, expected, msg) | ||
| if not actual:moreThan(expected) then | ||
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " > " .. tostring(expected:toString()), 2) | ||
| end | ||
| end | ||
|
|
||
| function assertLessThan(actual, expected, msg) | ||
| if not actual:lessThan(expected) then | ||
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " < " .. tostring(expected:toString()), 2) | ||
| end | ||
| end | ||
|
|
||
| function assertMoreEquals(actual, expected, msg) | ||
| if not actual:moreEquals(expected) then | ||
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " >= " .. tostring(expected:toString()), 2) | ||
| end | ||
| end | ||
|
|
||
| function assertLessEquals(actual, expected, msg) | ||
| if not actual:lessEquals(expected) then | ||
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " <= " .. tostring(expected:toString()), 2) |
There was a problem hiding this comment.
The double tostring() call is redundant since toString() already returns a string. Consider using (msg or "") .. " Expected " .. actual:toString() .. " >= " .. expected:toString()
| error((msg or "") .. " Expected " .. tostring(expected:toString()) .. ", got " .. tostring(actual:toString()), 2) | |
| end | |
| end | |
| function assertMoreThan(actual, expected, msg) | |
| if not actual:moreThan(expected) then | |
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " > " .. tostring(expected:toString()), 2) | |
| end | |
| end | |
| function assertLessThan(actual, expected, msg) | |
| if not actual:lessThan(expected) then | |
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " < " .. tostring(expected:toString()), 2) | |
| end | |
| end | |
| function assertMoreEquals(actual, expected, msg) | |
| if not actual:moreEquals(expected) then | |
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " >= " .. tostring(expected:toString()), 2) | |
| end | |
| end | |
| function assertLessEquals(actual, expected, msg) | |
| if not actual:lessEquals(expected) then | |
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " <= " .. tostring(expected:toString()), 2) | |
| error((msg or "") .. " Expected " .. expected:toString() .. ", got " .. actual:toString(), 2) | |
| end | |
| end | |
| function assertMoreThan(actual, expected, msg) | |
| if not actual:moreThan(expected) then | |
| error((msg or "") .. " Expected " .. actual:toString() .. " > " .. expected:toString(), 2) | |
| end | |
| end | |
| function assertLessThan(actual, expected, msg) | |
| if not actual:lessThan(expected) then | |
| error((msg or "") .. " Expected " .. actual:toString() .. " < " .. expected:toString(), 2) | |
| end | |
| end | |
| function assertMoreEquals(actual, expected, msg) | |
| if not actual:moreEquals(expected) then | |
| error((msg or "") .. " Expected " .. actual:toString() .. " >= " .. expected:toString(), 2) | |
| end | |
| end | |
| function assertLessEquals(actual, expected, msg) | |
| if not actual:lessEquals(expected) then | |
| error((msg or "") .. " Expected " .. actual:toString() .. " <= " .. expected:toString(), 2) |
|
|
||
| function assertLessEquals(actual, expected, msg) | ||
| if not actual:lessEquals(expected) then | ||
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " <= " .. tostring(expected:toString()), 2) |
There was a problem hiding this comment.
The double tostring() call is redundant since toString() already returns a string. Consider using (msg or "") .. " Expected " .. actual:toString() .. " <= " .. expected:toString()
| error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " <= " .. tostring(expected:toString()), 2) | |
| error((msg or "") .. " Expected " .. actual:toString() .. " <= " .. expected:toString(), 2) |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This PR adds a comprehensive test suite for the AlyaNum library, expanding the existing 20 tests to 68 comprehensive unit tests that thoroughly validate mathematical properties, large number operations, and edge cases.
What's Added
Mathematical Property Tests (12 tests)
Large Number Tests (18 tests)
Tests operations with numbers approaching the 10^^^^10 safe limit mentioned in the code:
Edge Cases and Boundary Conditions (18 tests)
Enhanced Test Infrastructure
Added detailed assertion helper functions that provide informative error messages instead of generic assertion failures:
The new assertion helpers include:
Why This Matters
The AlyaNum library handles numbers up to 10^^^^^10 (heptation), which is astronomically large. This enhanced test suite ensures:
Example test demonstrating the enhanced assertions:
This ensures the AlyaNum library maintains mathematical rigor even when working with numbers that exceed the capabilities of standard floating-point arithmetic by many orders of magnitude, while providing clear debugging information when tests fail.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.