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

Commit

Permalink
Add tests and add a catch for subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorkarn committed Oct 11, 2022
1 parent d7c74f4 commit ae1d71a
Showing 1 changed file with 47 additions and 13 deletions.
60 changes: 47 additions & 13 deletions src/sage/combinat/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,30 +382,64 @@ def __iter__(self):
sage: from sage.combinat.diagram import Diagrams
sage: I = iter(Diagrams())
sage: for i in range(3):
sage: for i in range(10):
....: print(next(I))
[]
[(0, 0)]
[(1, 0)]
[(0, 0), (1, 0)]
[(0, 1)]
[(0, 0), (0, 1)]
[(0, 1), (1, 0)]
[(0, 0), (0, 1), (1, 0)]
[(2, 0)]
[(0, 0), (2, 0)]
sage: next(I).parent()
Combinatorial diagrams
sage: del(I)
sage: D = Diagrams()
sage: for d in D:
....: if len(d) >= 3:
....: break
sage: d
[(0, 0), (0, 1), (0, 2)]
sage: from sage.combinat.diagram import NorthwestDiagrams
sage: I = iter(NorthwestDiagrams())
sage: for i in range(20):
....: print(next(I))
[]
[(0, 0)]
[(1, 0)]
[(0, 0), (1, 0)]
[(0, 1)]
[(0, 0), (0, 1)]
[(0, 0), (0, 1), (1, 0)]
[(2, 0)]
[(0, 0), (2, 0)]
[(1, 0), (2, 0)]
[(0, 0), (1, 0), (2, 0)]
[(0, 0), (0, 1), (2, 0)]
[(0, 0), (0, 1), (1, 0), (2, 0)]
[(1, 1)]
[(0, 0), (1, 1)]
[(1, 0), (1, 1)]
[(0, 0), (1, 0), (1, 1)]
[(0, 1), (1, 1)]
[(0, 0), (0, 1), (1, 1)]
[(0, 0), (0, 1), (1, 0), (1, 1)]
"""
from sage.sets.non_negative_integers import NonNegativeIntegers
from sage.misc.mrange import cartesian_product_iterator
from sage.sets.positive_integers import PositiveIntegers
from sage.all import cartesian_product
from sage.misc.misc import subsets
NN = NonNegativeIntegers()
P = cartesian_product_iterator([NN, NN])
# the product of positive integers automatically implements an
# an enumeration which allows us to get out of the first column
PP = PositiveIntegers()
P = cartesian_product([PP, PP])
X = subsets(P)
while True:
yield self.element_class(self, next(X))
# we want to allow cells in the index-0 row but we
# dont want all of them to be in the index-0 row
cells = next(X)
try:
yield self.element_class(self, tuple((i-1, j-1) for i,j in cells))
except ValueError:
# if cells causes the .check method of a
# subclass to fail, just go to the next one
pass

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

0 comments on commit ae1d71a

Please sign in to comment.