
import io

from hypothesis import given
from hypothesis.strategies import lists, integers

from sensibility import Program, vocabulary
#semicolon = vocabulary.to_index(';')


@given(lists(integers(min_value=vocabulary.start_token_index + 1,
                      max_value=vocabulary.end_token_index - 1),
             min_size=1))
def test_program_random(tokens):
    p = Program('<none>', tokens)
    assert 0 <= p.random_token_index() < len(p)
    assert 0 <= p.random_insertion_point() <= len(p)


@given(lists(integers(min_value=vocabulary.start_token_index + 1,
                      max_value=vocabulary.end_token_index - 1),
             min_size=1))
def test_program_print(tokens):
    program = Program('<none>', tokens)
    with io.StringIO() as output:
        program.print(output)
        output_text = output.getvalue()
    assert len(program) >= 1
    assert len(program) == len(output_text.split())


import io

from hypothesis import given
from hypothesis.strategies import builds, lists, integers, just

from sensibility import Program, vocabulary


tokens = integers(min_value=vocabulary.start_token_index + 1,
                  max_value=vocabulary.end_token_index - 1)
vectors = lists(tokens, min_size=1)
programs = builds(Program, just('<test>'), vectors)


@given(programs)
def test_program_random(program):
    assert 0 <= program.random_token_index() < len(program)
    assert 0 <= program.random_insertion_point() <= len(program)


@given(programs)
def test_program_print(program):
    with io.StringIO() as output:
        program.print(output)
        output_text = output.getvalue()
    assert len(program) == len(output_text.split())

Clean up test a bit.
Clean up test a bit.

  
  import io
  
  from hypothesis import given
- from hypothesis.strategies import lists, integers
+ from hypothesis.strategies import builds, lists, integers, just
  
  from sensibility import Program, vocabulary
- #semicolon = vocabulary.to_index(';')
  
  
- @given(lists(integers(min_value=vocabulary.start_token_index + 1,
+ tokens = integers(min_value=vocabulary.start_token_index + 1,
-                       max_value=vocabulary.end_token_index - 1),
+                   max_value=vocabulary.end_token_index - 1)
+ vectors = lists(tokens, min_size=1)
+ programs = builds(Program, just('<test>'), vectors)
-              min_size=1))
- def test_program_random(tokens):
-     p = Program('<none>', tokens)
-     assert 0 <= p.random_token_index() < len(p)
-     assert 0 <= p.random_insertion_point() <= len(p)
  
  
- @given(lists(integers(min_value=vocabulary.start_token_index + 1,
-                       max_value=vocabulary.end_token_index - 1),
-              min_size=1))
+ @given(programs)
+ def test_program_random(program):
+     assert 0 <= program.random_token_index() < len(program)
+     assert 0 <= program.random_insertion_point() <= len(program)
+ 
+ 
+ @given(programs)
- def test_program_print(tokens):
+ def test_program_print(program):
-     program = Program('<none>', tokens)
      with io.StringIO() as output:
          program.print(output)
          output_text = output.getvalue()
-     assert len(program) >= 1
      assert len(program) == len(output_text.split())
  
Clean up test a bit.
## Code Before:

import io

from hypothesis import given
from hypothesis.strategies import lists, integers

from sensibility import Program, vocabulary
#semicolon = vocabulary.to_index(';')


@given(lists(integers(min_value=vocabulary.start_token_index + 1,
                      max_value=vocabulary.end_token_index - 1),
             min_size=1))
def test_program_random(tokens):
    p = Program('<none>', tokens)
    assert 0 <= p.random_token_index() < len(p)
    assert 0 <= p.random_insertion_point() <= len(p)


@given(lists(integers(min_value=vocabulary.start_token_index + 1,
                      max_value=vocabulary.end_token_index - 1),
             min_size=1))
def test_program_print(tokens):
    program = Program('<none>', tokens)
    with io.StringIO() as output:
        program.print(output)
        output_text = output.getvalue()
    assert len(program) >= 1
    assert len(program) == len(output_text.split())

## Instruction:
Clean up test a bit.
## Code After:

import io

from hypothesis import given
from hypothesis.strategies import builds, lists, integers, just

from sensibility import Program, vocabulary


tokens = integers(min_value=vocabulary.start_token_index + 1,
                  max_value=vocabulary.end_token_index - 1)
vectors = lists(tokens, min_size=1)
programs = builds(Program, just('<test>'), vectors)


@given(programs)
def test_program_random(program):
    assert 0 <= program.random_token_index() < len(program)
    assert 0 <= program.random_insertion_point() <= len(program)


@given(programs)
def test_program_print(program):
    with io.StringIO() as output:
        program.print(output)
        output_text = output.getvalue()
    assert len(program) == len(output_text.split())
