from puzzle.heuristics import analyze_word
from spec.data.fixtures import tries
from spec.mamba import *

from puzzle.problems import anagram_problem


with description('AnagramProblem'):
  with before.all:
    analyze_word.init_trie(tries.ambiguous())

  with after.all:
    analyze_word.reset()

  with it('ignores empty and garbage input'):
    expect(anagram_problem.AnagramProblem.score([''])).to(equal(0))

  with it('rejects multiple lines'):
    expect(anagram_problem.AnagramProblem.score(
        'A quick brown fox jumps over the lazy dog'.split())).to(equal(0))

  with it('accepts anagrams'):
    expect(anagram_problem.AnagramProblem.score(['snap'])).to(equal(1))

  with description('problem instance'):
    with before.each:
      self.subject = anagram_problem.AnagramProblem('example', ['snap'])

    with it('solves anagrams'):
      expect(list(self.subject.solutions())).to(equal(['snap', 'naps']))

from puzzle.heuristics import analyze_word
from spec.data.fixtures import tries
from spec.mamba import *

from puzzle.problems import anagram_problem


with description('AnagramProblem'):
  with before.all:
    analyze_word.init_trie(tries.ambiguous())

  with after.all:
    analyze_word.reset()

  with it('ignores empty and garbage input'):
    expect(anagram_problem.AnagramProblem.score([''])).to(equal(0))

  with it('rejects multiple lines'):
    expect(anagram_problem.AnagramProblem.score(
        'A quick brown fox jumps over the lazy dog'.split())).to(equal(0))

  with it('accepts anagrams'):
    expect(anagram_problem.AnagramProblem.score(['snap'])).to(equal(1))

  with description('problem instance'):
    with before.each:
      self.subject = anagram_problem.AnagramProblem('example', ['snap'])

    with it('solves anagrams'):
      expect(sorted(list(self.subject.solutions()))).to(equal(['naps', 'snap']))

Fix non-determinism in anagram_problem_spec.