def test_parse_2(): replacements, molecule = parse_input(test_input_2) assert len(replacements) == 3 assert replacements[0] == ('H', 'HO') assert replacements[1] == ('H', 'OH') assert replacements[2] == ('O', 'HH') assert molecule == 'HOHOHO'
def test_replacements_1(): replacements, molecule = parse_input(test_input_1) generated_molecules = do_replacements(molecule, replacements) assert len(generated_molecules) == 4 assert 'HOOH' in generated_molecules assert 'HOHO' in generated_molecules assert 'OHOH' in generated_molecules assert 'HHHH' in generated_molecules
def test_build_2_greedy(): replacements, _ = parse_input(build_replacements) n_steps = build_molecule(replacements, 'HOHOHO', reverse=True, greedy=True) assert n_steps == 6
def test_build_1_reverse(): replacements, _ = parse_input(build_replacements) n_steps = build_molecule(replacements, 'HOH', reverse=True) assert n_steps == 3
def test_build_2(): replacements, _ = parse_input(build_replacements) n_steps = build_molecule(replacements, 'HOHOHO') assert n_steps == 6
def test_part_1(): with open('input.txt') as f: specs = f.read() replacements, molecule = parse_input(specs) generated_molecules = do_replacements(molecule, replacements) assert len(generated_molecules) == 535
def test_replacements_2(): replacements, molecule = parse_input(test_input_2) generated_molecules = do_replacements(molecule, replacements) assert len(generated_molecules) == 7
def test_part_2(): with open('input.txt') as f: specs = f.read() replacements, molecule = parse_input(specs) n_steps = build_molecule(replacements, target=molecule, reverse=True, greedy=True) assert n_steps == 212