コード例 #1
0
    def test_part_one(self):
        "Test part two example of Decompress object"

        # 1. Create Decompress object from text
        myobj = decompress.Decompress(text=aoc_09.from_text(PART_ONE_TEXT))

        # 2. Check the part one result
        self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
コード例 #2
0
    def test_part_two(self):
        "Test part two example of Decompress object"

        # 1. Create Decompress object from text
        myobj = decompress.Decompress(part2=True,
                                      text=aoc_09.from_text(PART_TWO_TEXT))

        # 2. Check the part two result
        self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
コード例 #3
0
    def test_text_init(self):
        "Test the Decompress object creation from text"

        # 1. Create Decompress object from text
        myobj = decompress.Decompress(text=aoc_09.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 1)

        # 3. Check methods
        self.assertEqual(myobj.expand(), EXAMPLE_EXPAND)
コード例 #4
0
    def test_empty_init(self):
        "Test the default Decompress creation"

        # 1. Create default Decompress object
        myobj = decompress.Decompress()

        # 2. Make sure it has the default values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(myobj.text, None)

        # 3. Check methods
        self.assertEqual(myobj.expand(), '')
コード例 #5
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the puzzle solver
    solver = decompress.Decompress(part2=True, text=input_lines)

    # 2. Determine the solution for part two
    solution = solver.part_two(verbose=args.verbose, limit=args.limit)
    if solution is None:
        print("There is no solution")
    else:
        print("The solution for part two is %s" % (solution))

    # 3. Return result
    return solution is not None
コード例 #6
0
    def test_examples_one(self):
        "Test the part one examples"

        # 1. Loop for the examples
        for text, expanded in EXAMPLES_ONE.items():

            # 1. Create Decompress object from text
            myobj = decompress.Decompress(text=[text])

            # 2. Make sure it has the expected values
            self.assertEqual(myobj.part2, False)
            self.assertEqual(len(myobj.text), 1)

            # 3. Check methods
            self.assertEqual(myobj.expand(), expanded)
コード例 #7
0
    def test_examples_two(self):
        "Test the part two examples"

        # 1. Loop for the examples
        for text, expanded in EXAMPLES_TWO.items():

            # 1. Create Decompress object from text
            # print(text, expanded)
            myobj = decompress.Decompress(text=[text], part2=True)

            # 2. Make sure it has the expected values
            self.assertEqual(myobj.part2, True)
            self.assertEqual(len(myobj.text), 1)

            # 3. Check methods
            self.assertEqual(myobj.expanded(), expanded)
コード例 #8
0
import decompress
import argparse

# 添加参数
parser = argparse.ArgumentParser()
parser.add_argument('inputFile', help='inputFile')
parser.add_argument('outputFile', help='ouputFile')
args = parser.parse_args()
inputFile = args.inputFile
outputFile = args.outputFile

mydecompress = decompress.Decompress()
mydecompress.unziptxt(inputFile, outputFile)