From 8a5814464682be4b5a2ea977a1c356039f8bc238 Mon Sep 17 00:00:00 2001 From: Eric Wolf Date: Tue, 9 Apr 2024 22:25:32 +0200 Subject: [PATCH] add predefined variables Inspired by `sympy.abc` --- docs/api/terms.rst | 1 + docs/api/terms/abc.rst | 8 ++++++++ src/lambda_calculus/terms/__init__.py | 1 + src/lambda_calculus/terms/abc.py | 17 +++++++++++++++++ tests/terms/test_abc.py | 24 ++++++++++++++++++++++++ 5 files changed, 51 insertions(+) create mode 100644 docs/api/terms/abc.rst create mode 100644 src/lambda_calculus/terms/abc.py create mode 100644 tests/terms/test_abc.py diff --git a/docs/api/terms.rst b/docs/api/terms.rst index 12e1c6a..b05ed74 100644 --- a/docs/api/terms.rst +++ b/docs/api/terms.rst @@ -4,6 +4,7 @@ Package terms .. toctree:: :maxdepth: 2 + terms/abc terms/logic terms/arithmetic terms/pairs diff --git a/docs/api/terms/abc.rst b/docs/api/terms/abc.rst new file mode 100644 index 0000000..d53c64a --- /dev/null +++ b/docs/api/terms/abc.rst @@ -0,0 +1,8 @@ +Module abc +========== + +.. toctree:: + :maxdepth: 2 + +.. automodule:: lambda_calculus.terms.abc + :members: \ No newline at end of file diff --git a/src/lambda_calculus/terms/__init__.py b/src/lambda_calculus/terms/__init__.py index 0b56ce3..6d18ce2 100644 --- a/src/lambda_calculus/terms/__init__.py +++ b/src/lambda_calculus/terms/__init__.py @@ -17,6 +17,7 @@ "Variable", "Abstraction", "Application", + "abc", "arithmetic", "logic", "pairs", diff --git a/src/lambda_calculus/terms/abc.py b/src/lambda_calculus/terms/abc.py new file mode 100644 index 0000000..37c7711 --- /dev/null +++ b/src/lambda_calculus/terms/abc.py @@ -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") diff --git a/tests/terms/test_abc.py b/tests/terms/test_abc.py new file mode 100644 index 0000000..2ed874b --- /dev/null +++ b/tests/terms/test_abc.py @@ -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)