-
Notifications
You must be signed in to change notification settings - Fork 0
Add variable pattern tests for egg #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
adf78f4
6c83939
8182c72
82d5b8c
958977c
683fd07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -198,3 +198,196 @@ async def test_egg_cancellation(temp_db): | |||||||
| await task | ||||||||
| except asyncio.CancelledError: | ||||||||
| pass | ||||||||
|
|
||||||||
|
|
||||||||
| # Variable-based tests | ||||||||
| @pytest.mark.asyncio | ||||||||
| async def test_egg_symmetry_with_variables(temp_db): | ||||||||
| """Test symmetry with variables: given variable equality a(`x)=b(`x), | ||||||||
| the system can derive the symmetric concrete instance b(t)=a(t) by | ||||||||
| unifying the variable pattern with concrete value t.""" | ||||||||
| addr, engine, session = temp_db | ||||||||
|
|
||||||||
| # Add fact a(`x)=b(`x) with variable | ||||||||
| async with session() as sess: | ||||||||
| sess.add(Facts(data="----\n(binary == (unary a `x) (unary b `x))\n")) | ||||||||
| sess.add(Ideas(data="----\n(binary == (unary b t) (unary a t))\n")) | ||||||||
| await sess.commit() | ||||||||
|
|
||||||||
| # Run the main function with a timeout | ||||||||
| task = asyncio.create_task(main(addr, engine, session)) | ||||||||
| await asyncio.sleep(0.3) | ||||||||
| task.cancel() | ||||||||
| try: | ||||||||
| await task | ||||||||
| except asyncio.CancelledError: | ||||||||
| pass | ||||||||
|
Comment on lines
+218
to
+224
|
||||||||
|
|
||||||||
| # Verify that fact b(t)=a(t) was produced | ||||||||
| async with session() as sess: | ||||||||
| facts = await sess.scalars(select(Facts)) | ||||||||
| fact_data = [f.data for f in facts.all()] | ||||||||
| assert "----\n(binary == (unary b t) (unary a t))\n" in fact_data | ||||||||
|
|
||||||||
|
|
||||||||
| @pytest.mark.asyncio | ||||||||
| async def test_egg_transitivity_with_variables(temp_db): | ||||||||
| """Test transitivity with variables: given a(`x)=b(`x), b(`x)=c(`x), should produce a(t)=c(t).""" | ||||||||
| addr, engine, session = temp_db | ||||||||
|
|
||||||||
| # Add facts a(`x)=b(`x) and b(`x)=c(`x) | ||||||||
| async with session() as sess: | ||||||||
| sess.add(Facts(data="----\n(binary == (unary a `x) (unary b `x))\n")) | ||||||||
| sess.add(Facts(data="----\n(binary == (unary b `x) (unary c `x))\n")) | ||||||||
| sess.add(Ideas(data="----\n(binary == (unary a t) (unary c t))\n")) | ||||||||
| await sess.commit() | ||||||||
|
|
||||||||
| # Run the main function | ||||||||
| task = asyncio.create_task(main(addr, engine, session)) | ||||||||
| await asyncio.sleep(0.3) | ||||||||
| task.cancel() | ||||||||
| try: | ||||||||
| await task | ||||||||
| except asyncio.CancelledError: | ||||||||
|
||||||||
| pass | ||||||||
|
|
||||||||
| # Verify that fact a(t)=c(t) was produced | ||||||||
| async with session() as sess: | ||||||||
| facts = await sess.scalars(select(Facts)) | ||||||||
| fact_data = [f.data for f in facts.all()] | ||||||||
| assert "----\n(binary == (unary a t) (unary c t))\n" in fact_data | ||||||||
|
|
||||||||
|
|
||||||||
| @pytest.mark.asyncio | ||||||||
| async def test_egg_congruence_with_variables(temp_db): | ||||||||
| """Test congruence with variables: given a(`x)=b(`x), derive f(a(t))=f(b(t)). | ||||||||
|
|
||||||||
| This tests that variable patterns enable congruence on nested structures: | ||||||||
| - Variable fact a(`x)=b(`x) allows deriving concrete equality a(t)=b(t) | ||||||||
| - Concrete equality a(t)=b(t) enables congruence to derive f(a(t))=f(b(t)) | ||||||||
| """ | ||||||||
| addr, engine, session = temp_db | ||||||||
|
|
||||||||
| # Add variable equality fact | ||||||||
| async with session() as sess: | ||||||||
| sess.add(Facts(data="----\n(binary == (unary a `x) (unary b `x))\n")) | ||||||||
| # Add ideas to test the derivation chain | ||||||||
| sess.add(Ideas(data="----\n(binary == (unary a t) (unary b t))\n")) # concrete instance | ||||||||
| sess.add(Ideas(data="----\n(binary == (unary f (unary a t)) (unary f (unary b t)))\n")) # congruence | ||||||||
| await sess.commit() | ||||||||
hzhangxyz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
|
||||||||
| # Run the main function | ||||||||
| task = asyncio.create_task(main(addr, engine, session)) | ||||||||
| await asyncio.sleep(0.3) | ||||||||
| task.cancel() | ||||||||
| try: | ||||||||
| await task | ||||||||
| except asyncio.CancelledError: | ||||||||
| pass | ||||||||
|
||||||||
| pass | |
| # The task is expected to be cancelled as part of this test. | |
| assert task.cancelled() |
hzhangxyz marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'except' clause does nothing but pass and there is no explanatory comment.
| except asyncio.CancelledError: | |
| except asyncio.CancelledError: | |
| # Expected when stopping the background task during test teardown. |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'except' clause does nothing but pass and there is no explanatory comment.
| except asyncio.CancelledError: | |
| except asyncio.CancelledError: | |
| # Task cancellation is expected here: we stop the background `main` loop for this test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'except' clause does nothing but pass and there is no explanatory comment.