コード例 #1
0
def main(input=None):
    """Console script for LEDtester."""

    t1 = time.time()

    if not input == None:

        # Parse instructions from text file
        print('input:', input)
        L, instructions = utils.parse_file(input)

        # Instantiate LED grid object
        grid = LEDsimulator.LEDgrid(L)

        # Apply instructions to grid object
        invalid_count = 0

        for instruction in instructions:
            invalid_count += grid.apply(
                instruction
            )  # applies instruction and then returns 0, or 1 if invalid instruction

        # Output number of lights that are on after all instructions carried out
        print(grid.count(), 'LEDs are on')
        print('Number of invalid instructions:', invalid_count)
        # Output time taken to calculate
        t2 = time.time()
        print('Calculation time:', t2 - t1, 'seconds')

    else:
        print(
            "Error: No input argument was given. The command requires a single filepath or a URI as its argument."
        )

    return 0
コード例 #2
0
def test_parse_valid_uri():
    uri = "http://claritytrec.ucd.ie/~alawlor/comp30670/input_assign3.txt"
    L, instructions = utils.parse_file(uri)
    assert L == 1000
    assert instructions[0:3] == [
        'turn off 660,55 through 986,197', 'turn off 341,304 through 638,850',
        'turn off 199,133 through 461,193'
    ]
    assert instructions[-1] == 'switch 296,687 through 906,775'
コード例 #3
0
ファイル: test_LEDtester.py プロジェクト: crotty-d/led-tester
def test_parse_valid_file():
    file = './data/test_data.txt'
    L, instructions = utils.parse_file(file)
    assert L == 10
    assert instructions == [
        'turn on 0,0 through 9,9', 'turn off 0,0 through 9,9',
        'switch 0,0 through 9,9', 'turn off 0,0 through 9,9',
        'turn on 2,2 through 7,7'
    ]
コード例 #4
0
def test_parse_invalid_uri():
    file = 'http://dsafdfghklk.hkh/file'
    L, instructions = utils.parse_file(file)
    assert L == 0
    assert instructions[0] == 'error'

    grid = LEDsimulator.LEDgrid(10)
    grid.lights[4, 4] = 1

    for instruction in instructions:
        grid.apply(instruction)

    print(grid.lights)

    assert grid.count() == 1
コード例 #5
0
ファイル: test_LEDtester.py プロジェクト: crotty-d/led-tester
def test_parse_invalid_filepath():
    file = './data/doesnotexist.txt'
    L, instructions = utils.parse_file(file)
    assert L == 0
    assert instructions[0] == 'error'

    grid = LEDsimulator.LEDgrid(10)
    grid.lights[4, 4] = 1

    for instruction in instructions:
        grid.apply(instruction)

    print(grid.lights)

    assert grid.count() == 1