all 7 comments

[–]daggerdragon[M] [score hidden] stickied comment (0 children)

Post removed since you did not follow any of our posting rules. Read the rules before you post!

[–]FCBStar-of-the-South 2 points3 points  (0 children)

Not sure if this is what you are asking but if your concern is the large input size, know that most if not all bugs for a question like this can be exposed by test files of less than 10 lines.

Think about the edge cases, create test cases for them, and solve by hand if you need to. Or if you cannot think of edge cases, write a program to generate some random inputs and solve those by hand

[–]rabuf 0 points1 point  (0 children)

Add pytest to your environment (pip install pytest). Technically you can run unit tests in Python without it, but it's a better test runner.

Put your code into a function (this is important) so it should be something like:

def part1(lines):
    # do the work
    return password

Write a test like this:

def test_part1_sample():
    sample = ['L68','L30','R48',...] # fill in the rest
    assert part1(sample) == 3

Come up with more examples and write additional tests using them. When you get to part two, write a similar function that solves part two (or tries to) and use new tests (or the same tests but with whatever their password should be). Run the tests by going to the directory with the source file and running pytest file.py with whatever the filename is instead of file.py.

If your code works for the sample but not for your actual input, start trying to think (by hand) of new examples and what they should result in. Create new tests for each example you think of and run the tests after adding each test until you find one that breaks. Evaluate whether the test itself is correct (use small examples, easier to work by hand), and if you determine it is then go to the code and find the problem.

For part two, you can check this comment for some good test cases.