Skip to content

Commit

Permalink
FreeModuleCoBasis: Add _test_iter_len
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Aug 6, 2020
1 parent 1e69c0e commit f1f67d3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/sage/tensor/modules/free_module_basis.py
Expand Up @@ -90,6 +90,13 @@ def __iter__(self):
def _test_iter_len(self, **options):
r"""
Test that __iter__ and __len__ work correctly.
EXAMPLES::
sage: M = FiniteRankFreeModule(ZZ, 3, name='M')
sage: e = M.basis('e')
sage: e._test_iter_len()
"""
tester = self._tester(**options)
g = iter(self)
Expand Down Expand Up @@ -416,6 +423,28 @@ def __init__(self, basis, symbol, latex_symbol=None, indices=None,
self.set_name(symbol, latex_symbol=latex_symbol, indices=indices,
latex_indices=latex_indices, index_position='up')

def _test_iter_len(self, **options):
r"""
Test that __iter__ and __len__ work correctly.
This method overrides ``Basis_abstract`` so that containment
of elements in the dual of ``self.free_module()`` is tested instead.
EXAMPLES::
sage: M = FiniteRankFreeModule(ZZ, 3, name='M')
sage: e = M.basis('e')
sage: f = e.dual_basis()
sage: f._test_iter_len()
"""
tester = self._tester(**options)
g = iter(self)
b = list(g)
for x in b:
tester.assertTrue(x in self.free_module().dual())
tester.assertEqual(len(b), len(self))
tester.assertEqual(len(b), self.free_module().rank())

def _repr_(self):
r"""
Expand Down

0 comments on commit f1f67d3

Please sign in to comment.