Skip to content

Add comprehensive unit tests for AlyaNum with enhanced assertion helpers for detailed test output#4

Merged
evilbocchi merged 17 commits into
mainfrom
copilot/fix-050ad53a-1441-4d52-ba28-bf3c5d6bbb04
Aug 1, 2025
Merged

Add comprehensive unit tests for AlyaNum with enhanced assertion helpers for detailed test output#4
evilbocchi merged 17 commits into
mainfrom
copilot/fix-050ad53a-1441-4d52-ba28-bf3c5d6bbb04

Conversation

Copilot AI commented Aug 1, 2025

Copy link
Copy Markdown
Contributor

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)

  • Identity properties: Additive identity (a + 0 = a), multiplicative identity (a × 1 = a), exponentiation identity (a^1 = a, a^0 = 1)
  • Commutativity: Addition (a + b = b + a), multiplication (a × b = b × a), including tests with large numbers
  • Associativity: Addition ((a + b) + c = a + (b + c)), multiplication ((a × b) × c = a × (b × c))
  • Distributivity: Multiplication over addition (a × (b + c) = (a × b) + (a × c))
  • Inverse operations: Addition/subtraction, multiplication/division, power/root reversibility

Large Number Tests (18 tests)

Tests operations with numbers approaching the 10^^^^10 safe limit mentioned in the code:

  • Tetration (^^): 2^^3 = 16, 2^^4 = 65536, and larger towers
  • Pentation (^^^): 2^^^3 and higher-order operations
  • Hexation (^^^^): 2^^^^3 and extreme hyperoperations
  • Googol-scale operations: 10^100 and beyond
  • Scientific notation: 1e1000+ numbers
  • Extreme numbers: Testing the library's upper bounds with heptation levels

Edge Cases and Boundary Conditions (18 tests)

  • Zero behavior: 0 + a, 0 × a, 0^a, a^0 across all operations
  • Negative numbers: Sign handling in arithmetic and hyperoperations
  • Very small numbers: 1e-100 precision handling
  • One in hyperoperations: 1^^a, 1^^^a, 1^^^^a edge cases
  • String parsing: Various formats including scientific notation
  • Comparison operations: Equality, less than, greater than with edge values

Enhanced Test Infrastructure

Added detailed assertion helper functions that provide informative error messages instead of generic assertion failures:

-- Before: Generic assertion failure
assert(a:moreThan(b), "should be greater")
-- Output: assertion failed

-- After: Detailed assertion with values
assertMoreThan(a, b, "should be greater")
-- Output: Expected E(100)1K > E(100)2K: should be greater

The new assertion helpers include:

  • assertEquals(actual, expected, msg): Shows "Expected X, got Y" for AlyaNum equality
  • assertMoreThan(actual, expected, msg): Shows "Expected X > Y" when greater-than fails
  • assertLessThan(actual, expected, msg): Shows "Expected X < Y" when less-than fails
  • assertMoreEquals/assertLessEquals: For >= and <= comparisons with detailed output

Why This Matters

The AlyaNum library handles numbers up to 10^^^^^10 (heptation), which is astronomically large. This enhanced test suite ensures:

  1. Mathematical correctness at extreme scales
  2. Proper hyperoperation behavior (tetration, pentation, hexation)
  3. Robust edge case handling for real-world usage
  4. String conversion reliability for display purposes
  5. Better debugging with detailed assertion failure messages showing actual vs expected values

Example test demonstrating the enhanced assertions:

addTest("commutativity: large numbers", function()
    local a = AlyaNum.new(1e100)
    local b = AlyaNum.new(1e150)
    assertEquals(a:add(b), b:add(a), "large a + b should equal b + a")
    assertEquals(a:mul(b), b:mul(a), "large a * b should equal b * a")
end)

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.

… and large number support

Co-authored-by: evilbocchi <71329833+evilbocchi@users.noreply.github.com>
Copilot AI changed the title [WIP] Can you read the main luau file and write unit tests for it in the monolith unit testing script. Make it comprehensive with identity, associativity, commutativity, etc. Ensure to also include unit tests for large numbers, up to a safe soft limit of abo... Add comprehensive unit tests for AlyaNum mathematical properties and large number operations Aug 1, 2025
Copilot AI requested a review from evilbocchi August 1, 2025 03:14
@evilbocchi

Copy link
Copy Markdown
Owner

Create helper functions like assertMoreThan/assertLessThan/etc. instead of assert for more detailed test outputs

Copilot AI and others added 2 commits August 1, 2025 03:29
Co-authored-by: evilbocchi <71329833+evilbocchi@users.noreply.github.com>
Co-authored-by: evilbocchi <71329833+evilbocchi@users.noreply.github.com>

Copilot AI commented Aug 1, 2025

Copy link
Copy Markdown
Contributor Author

Create helper functions like assertMoreThan/assertLessThan/etc. instead of assert for more detailed test outputs

I've added detailed assertion helper functions to replace generic assert() calls with more informative test outputs. The new helpers include:

  • assertEquals(actual, expected, msg) - Shows "Expected X, got Y"
  • assertMoreThan(actual, expected, msg) - Shows "Expected X > Y"
  • assertLessThan(actual, expected, msg) - Shows "Expected X < Y"
  • assertMoreEquals/assertLessEquals for >= and <= comparisons

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.

Copilot AI changed the title Add comprehensive unit tests for AlyaNum mathematical properties and large number operations Add comprehensive unit tests for AlyaNum with enhanced assertion helpers for detailed test output Aug 1, 2025
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.
@coderabbitai

coderabbitai Bot commented Aug 1, 2025

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@evilbocchi evilbocchi marked this pull request as ready for review August 1, 2025 05:53
@evilbocchi evilbocchi requested a review from Copilot August 1, 2025 05:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread test/tests.luau Outdated
Comment thread test/tests.luau Outdated

function assertMoreThan(actual, expected, msg)
if not actual:moreThan(expected) then
error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " > " .. tostring(expected:toString()), 2)

Copilot AI Aug 1, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double tostring() call is redundant since toString() already returns a string. Consider using (msg or "") .. " Expected " .. actual:toString() .. " > " .. expected:toString()

Suggested change
error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " > " .. tostring(expected:toString()), 2)
error((msg or "") .. " Expected " .. actual:toString() .. " > " .. expected:toString(), 2)

Copilot uses AI. Check for mistakes.
Comment thread test/tests.luau Outdated
Comment on lines +31 to +55
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)

Copilot AI Aug 1, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double tostring() call is redundant since toString() already returns a string. Consider using (msg or "") .. " Expected " .. actual:toString() .. " < " .. expected:toString()

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment thread test/tests.luau Outdated
Comment on lines +31 to +55
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)

Copilot AI Aug 1, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double tostring() call is redundant since toString() already returns a string. Consider using (msg or "") .. " Expected " .. actual:toString() .. " >= " .. expected:toString()

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment thread test/tests.luau Outdated

function assertLessEquals(actual, expected, msg)
if not actual:lessEquals(expected) then
error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " <= " .. tostring(expected:toString()), 2)

Copilot AI Aug 1, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double tostring() call is redundant since toString() already returns a string. Consider using (msg or "") .. " Expected " .. actual:toString() .. " <= " .. expected:toString()

Suggested change
error((msg or "") .. " Expected " .. tostring(actual:toString()) .. " <= " .. tostring(expected:toString()), 2)
error((msg or "") .. " Expected " .. actual:toString() .. " <= " .. expected:toString(), 2)

Copilot uses AI. Check for mistakes.
Comment thread src/init.luau Outdated
Comment thread src/init.luau Outdated
Comment thread src/init.luau Outdated
Comment thread src/init.luau Outdated
Comment thread src/init.luau Outdated
evilbocchi and others added 7 commits August 1, 2025 14:01
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>
evilbocchi and others added 2 commits August 1, 2025 14:04
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@evilbocchi evilbocchi merged commit 2986717 into main Aug 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants