This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b8be0d
commit 1488582
Showing
11 changed files
with
267 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
|
||
class EnumeratedSetsTests: | ||
""" | ||
Generic tests for the category of enumerated sets. | ||
""" | ||
|
||
def test_enumerated_set_contains(self, category_instance, max_runs): | ||
""" | ||
Test that the methods :meth:`.__contains__` and :meth:`.__iter__` are consistent. | ||
""" | ||
i = 0 | ||
for w in category_instance: | ||
assert w in category_instance | ||
|
||
i += 1 | ||
if i > max_runs: | ||
return | ||
|
||
def test_enumerated_set_iter_list(self, category_instance, max_runs): | ||
""" | ||
Test that the methods :meth:`.list` and :meth:`.__iter__` are consistent. | ||
.. NOTE:: | ||
This test does nothing if the cardinality of the set | ||
is larger than the max_runs argument. | ||
""" | ||
if category_instance.list != category_instance._list_default: | ||
# TODO: if self._cardinality is self._cardinality_from_iterator | ||
# we could make sure to stop the counting at | ||
# self.max_test_enumerated_set_loop | ||
if category_instance.cardinality() > max_runs: | ||
print("Enumerated set too big; skipping test; increase max_runs") | ||
return | ||
ls = category_instance.list() | ||
i = 0 | ||
for obj in category_instance: | ||
assert obj == ls[i] | ||
i += 1 | ||
assert i == len(ls) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class FiniteEnumeratedSetsTests: | ||
""" | ||
Generic tests for the category of finite enumerated sets. | ||
""" | ||
|
||
def test_enumerated_set_iter_cardinality(self, category_instance, max_runs): | ||
""" | ||
Checks that the methods :meth:`.cardinality` and | ||
:meth:`.__iter__` are consistent. Also checks that | ||
:meth:`.cardinality` returns an ``Integer``. | ||
For efficiency reasons, those tests are not run if | ||
:meth:`.cardinality` is | ||
:meth:`._cardinality_from_iterator`, or if ``category_instance`` is too | ||
big. | ||
""" | ||
if category_instance.cardinality != category_instance._cardinality_from_iterator: | ||
card = category_instance.cardinality() | ||
if card <= max_runs: | ||
assert card == category_instance._cardinality_from_iterator() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class TestFiniteSemigroup(): | ||
""" | ||
Tests for finite semigroups. | ||
""" | ||
|
||
@staticmethod | ||
def category_instances(): | ||
from sage.categories.examples.finite_semigroups import LeftRegularBand | ||
return [ | ||
LeftRegularBand(alphabet = ('a','b')), | ||
LeftRegularBand(alphabet = ('a','b','c')), | ||
LeftRegularBand(alphabet = ('a','b','c', 'd')) | ||
] | ||
|
||
def test_associativity(self, set_elements, max_runs): | ||
""" | ||
Test associativity of multiplication of elements. | ||
""" | ||
from sage.misc.misc import some_tuples | ||
for x, y, z in some_tuples(set_elements, 3, max_runs): | ||
assert (x * y) * z == x * (y * z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
from sage.rings.infinity import infinity | ||
|
||
class InfiniteEnumeratedSetsTests: | ||
""" | ||
Generic tests for the category of infinite enumerated sets. | ||
""" | ||
def test_enumerated_set_iter_cardinality(self, category_instance): | ||
""" | ||
Test that the methods :meth:`.cardinality` and | ||
:meth:`.__iter__` are consistent. | ||
For infinite enumerated sets: | ||
* :meth:`.cardinality` is supposed to return `infinity` | ||
* :meth:`.list` is supposed to raise a ``NotImplementedError``. | ||
""" | ||
assert category_instance.cardinality() == infinity | ||
with pytest.raises(NotImplementedError): | ||
category_instance.list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.