def test_distribution_must_return_word_nplets(): first, other = make_char_chain(['a', 'word', 'wo', 'luke'], 1) assert (other, first) == ({ 2: { 'w': ['o'] }, 4: { 'k': ['e'], 'l': ['u'], 'o': ['r'], 'r': ['d'], 'u': ['k'], 'w': ['o'] } }, { 1: ['a'], 2: ['w'], 4: ['w', 'l'] }) first, other = make_char_chain(['a', 'word', 'wo', 'luke'], 2) assert (other, first) == ({ 4: { 'wo': ['rd'], 'lu': ['ke'] } }, { 1: ['a'], 2: ['wo'], 4: ['wo', 'lu'] })
def test_distribution_must_return_word_nplets(): first, other = make_char_chain(['a', 'word', 'wo', 'luke'], 1) assert (other, first) == ({2: {'w': ['o']}, 4:{ 'k': ['e'], 'l': ['u'], 'o': ['r'], 'r': ['d'], 'u': ['k'], 'w': ['o']}}, {1: ['a'], 2: ['w'], 4: ['w', 'l']}) first, other = make_char_chain(['a', 'word', 'wo', 'luke'], 2) assert (other, first) == ({4: {'wo': ['rd'], 'lu': ['ke']}}, {1: ['a'], 2: ['wo'], 4: ['wo', 'lu']})
def __init__(self, words, make_lengths_seq): self.dist = {} self.first, self.other, self.word_chars = make_char_chain(words, 3, self.dist) self.lengths = list(make_lengths_seq(words)) self.old_generated = collections.deque([], 100) pos = random.randint(0, len(self.lengths) - 1) left = itertools.islice(self.lengths, pos, None) right = itertools.islice(self.lengths, 0, pos) self.liter = itertools.cycle(itertools.chain(left, right))
def __init__(self, words, make_lengths_seq): self.dist = {} self.first, self.other, self.word_chars = make_char_chain( words, 3, self.dist) self.lengths = list(make_lengths_seq(words)) self.old_generated = collections.deque([], 100) pos = random.randint(0, len(self.lengths) - 1) left = itertools.islice(self.lengths, pos, None) right = itertools.islice(self.lengths, 0, pos) self.liter = itertools.cycle(itertools.chain(left, right))
def test_generate_huge(): words = split_to_words(open('/usr/share/fortune/cookie').read()) first, other = make_char_chain(words, 3) lengths = make_lengths_seq(words) for l in lengths[:1000]: print generate_word(first, other, l, 3), print assert False