Skip to content

Commit

Permalink
add predefined variables
Browse files Browse the repository at this point in the history
Inspired by `sympy.abc`
  • Loading branch information
Deric-W committed Apr 9, 2024
1 parent 9b067e5 commit 8a58144
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/api/terms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Package terms
.. toctree::
:maxdepth: 2

terms/abc
terms/logic
terms/arithmetic
terms/pairs
Expand Down
8 changes: 8 additions & 0 deletions docs/api/terms/abc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Module abc
==========

.. toctree::
:maxdepth: 2

.. automodule:: lambda_calculus.terms.abc
:members:
1 change: 1 addition & 0 deletions src/lambda_calculus/terms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Variable",
"Abstraction",
"Application",
"abc",
"arithmetic",
"logic",
"pairs",
Expand Down
17 changes: 17 additions & 0 deletions src/lambda_calculus/terms/abc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/python3

"""Predefined Variables for all ASCII letters"""

from string import ascii_letters
from . import Variable

__all__ = tuple(ascii_letters)

# better IDE autocompletion
a, b, c, d, e, f, g, h, i, j = map(Variable, "abcdefghij")
k, l, m, n, o, p, q, r, s, t = map(Variable, "klmnopqrst")
u, v, w, x, y, z = map(Variable, "uvwxyz")

A, B, C, D, E, F, G, H, I, J = map(Variable, "ABCDEFGHIJ")
K, L, M, N, O, P, Q, R, S, T = map(Variable, "KLMNOPQRST")
U, V, W, X, Y, Z = map(Variable, "UVWXYZ")
24 changes: 24 additions & 0 deletions tests/terms/test_abc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/python3

"""Tests for the predefined variables"""

from unittest import TestCase
from string import ascii_letters
from lambda_calculus.terms import Variable, abc


class PredefinedVariablesTest(TestCase):
"""Tests for the predefined variables"""

def test_complete(self) -> None:
"""Check whether all letters exist"""
self.assertEqual(tuple(ascii_letters), abc.__all__)
for letter in ascii_letters:
self.assertTrue(hasattr(abc, letter))

def test_variables(self) -> None:
"""Test the predefined variables"""
for letter in ascii_letters:
variable = getattr(abc, letter)
self.assertIsInstance(variable, Variable)
self.assertEqual(variable.name, letter)

0 comments on commit 8a58144

Please sign in to comment.