コード例 #1
0
ファイル: fit.py プロジェクト: wroldwiedbwe/f_it
    def combinations_with_replacement(self, r: int):
        """See itertools.combinations_with_replacement_

        .. _itertools.combinations_with_replacement: https://docs.python.org/3/library/itertools.html#itertools.combinations_with_replacement
        """  # noqa
        this_len = len_or_none(self)
        if this_len is None:
            length = None
        else:
            length = nCr(this_len, r, True)

        return FIt(combinations_with_replacement(self, r), length)
コード例 #2
0
ファイル: test_utils.py プロジェクト: clbarnes/f_it
def test_nCr_edges():
    with pytest.raises(ValueError):
        nCr(-1, 1)
    with pytest.raises(ValueError):
        nCr(1, -1)
    assert nCr(0, 0) == 0
    assert nCr(2, 3) == 0
コード例 #3
0
ファイル: fit.py プロジェクト: wroldwiedbwe/f_it
    def combinations(self, r: int, replace=False):
        """See itertools.combinations_

        Difference from stdlib: ``replace`` argument to use
        itertools.combinations_with_replacement_

        .. _itertools.combinations: https://docs.python.org/3/library/itertools.html#itertools.combinations
        .. _itertools.combinations_with_replacement: https://docs.python.org/3/library/itertools.html#itertools.combinations_with_replacement
        """  # noqa
        if replace:
            return FIt.combinations_with_replacement(self, r)

        this_len = len_or_none(self)
        if this_len is None:
            length = None
        else:
            length = nCr(this_len, r)

        return FIt(combinations(self, r), length)
コード例 #4
0
ファイル: test_utils.py プロジェクト: clbarnes/f_it
def test_nCr_replace():
    assert nCr(3, 2, True) == 6
コード例 #5
0
ファイル: test_utils.py プロジェクト: clbarnes/f_it
def test_nCr():
    assert nCr(3, 2) == 3