Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
ConvexSet_base._test_contains: Expand and add doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Jun 12, 2021
1 parent e66448e commit 1f7826d
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions src/sage/geometry/convex_set.py
Expand Up @@ -395,14 +395,61 @@ def contains(self, point):
def _test_contains(self, tester=None, **options):
"""
Test the ``contains`` method.
EXAMPLES::
sage: from sage.geometry.convex_set import ConvexSet_closed
sage: class FaultyConvexSet(ConvexSet_closed):
....: def ambient_vector_space(self, base_field=QQ):
....: return base_field^2
....: ambient = ambient_vector_space
....: def contains(self, point):
....: if isinstance(point, (tuple, list)):
....: return all(x in ZZ for x in point)
....: return point.parent() == ZZ^2
sage: FaultyConvexSet()._test_contains()
Traceback (most recent call last):
...
AssertionError: False != True
sage: class AlsoFaultyConvexSet(ConvexSet_closed):
....: def ambient_vector_space(self, base_field=QQ):
....: return base_field^2
....: def ambient(self):
....: return ZZ^2
....: def contains(self, point):
....: return point in ZZ^2
sage: AlsoFaultyConvexSet()._test_contains()
Traceback (most recent call last):
...
AssertionError: True != False
"""
if tester is None:
tester = self._tester(**options)
ambient = self.ambient()
space = self.ambient_vector_space()
point = space.an_element()
coords = space.coordinates(point)
try:
ambient_point = ambient.an_element()
except (AttributeError, NotImplementedError):
ambient_point = None
space_point = space.an_element()
else:
space_point = space(ambient_point)
space_coords = space.coordinates(space_point)
if self.contains != NotImplemented:
tester.assertEqual(self.contains(point), self.contains(coords))
contains_space_point = self.contains(space_point)
if ambient_point is not None:
tester.assertEqual(contains_space_point, self.contains(ambient_point))
tester.assertEqual(contains_space_point, self.contains(space_coords))
from sage.rings.qqbar import AA
ext_space = self.ambient_vector_space(AA)
ext_space_point = ext_space(space_point)
tester.assertEqual(contains_space_point, self.contains(ext_space_point))
from sage.symbolic.ring import SR
symbolic_space = self.ambient_vector_space(SR)
symbolic_space_point = symbolic_space(space_point)
# Only test that it can accept SR vectors without error.
self.contains(symbolic_space_point)

@abstract_method(optional=True)
def intersection(self, other):
Expand Down

0 comments on commit 1f7826d

Please sign in to comment.