# Path: wordseg/algos/baseline.py
# def segment(text, probability=0.5, log=utils.null_logger()):
#     """Random word segmentation given a boundary probability
# 
#     Given a probability :math:`p`, the probability :math:`P(t_i)` to
#     add a word boundary after each token :math:`t_i` is:
# 
#     .. math::
# 
#         P(t_i) = P(X < p), X \\sim \\mathcal{U}(0, 1).
# 
#     Parameters
#     ----------
#     text : sequence
#         The input utterances to segment, tokens are
#         assumed to be space separated.
#     probability: float, optional
#         The probability to append a word boundary after each token.
#     log : logging.Logger
#         Where to send log messages
# 
#     Yields
#     ------
#     segmented_text : generator
#         The randomly segmented utterances.
# 
#     Raises
#     ------
#     ValueError
#         if the probability is not a float in [0, 1].
# 
#     """
#     # make sure the probability is valid
#     if not isinstance(probability, float):
#         raise ValueError('probability must be a float')
#     if probability < 0 or probability > 1:
#         raise ValueError(
#             'probability must be in [0, 1], it is {}'.format(probability))
# 
#     log.info('P(word boundary) = %s', probability)
#     for utt in text:
#         yield ''.join(
#             token + ' ' if random.random() < probability else token
#             for token in utt.strip().split(' '))


import pytest
from wordseg.algos.baseline import segment
"""Test of the wordseg.algos.baseline module"""




@pytest.mark.parametrize('p', (1.01, -1, 'a', True, 1))
def test_proba_bad(p):
    with pytest.raises(ValueError):
        list(segment('a b c', probability=p))


def test_hello():
    assert list(segment(['h e l l o'], probability=0.0)) == ['hello']

# Path: wordseg/algos/baseline.py
# def segment(text, probability=0.5, log=utils.null_logger()):
#     """Random word segmentation given a boundary probability
# 
#     Given a probability :math:`p`, the probability :math:`P(t_i)` to
#     add a word boundary after each token :math:`t_i` is:
# 
#     .. math::
# 
#         P(t_i) = P(X < p), X \\sim \\mathcal{U}(0, 1).
# 
#     Parameters
#     ----------
#     text : sequence
#         The input utterances to segment, tokens are
#         assumed to be space separated.
#     probability: float, optional
#         The probability to append a word boundary after each token.
#     log : logging.Logger
#         Where to send log messages
# 
#     Yields
#     ------
#     segmented_text : generator
#         The randomly segmented utterances.
# 
#     Raises
#     ------
#     ValueError
#         if the probability is not a float in [0, 1].
# 
#     """
#     # make sure the probability is valid
#     if not isinstance(probability, float):
#         raise ValueError('probability must be a float')
#     if probability < 0 or probability > 1:
#         raise ValueError(
#             'probability must be in [0, 1], it is {}'.format(probability))
# 
#     log.info('P(word boundary) = %s', probability)
#     for utt in text:
#         yield ''.join(
#             token + ' ' if random.random() < probability else token
#             for token in utt.strip().split(' '))


# Path: test/test_algo_baseline.py
import pytest
from wordseg.algos.baseline import segment

"""Test of the wordseg.algos.baseline module"""




@pytest.mark.parametrize('p', (1.01, -1, 'a', True, 1))
def test_proba_bad(p):
    with pytest.raises(ValueError):
        list(segment('a b c', probability=p))


def test_hello():
    assert list(segment(['h e l l o'], probability=0.0)) == ['hello']

    assert list(segment(['h e l l o'], probability=1.0)) == ['h e l l o ']