Beispiel #1
0
def test_parse_file():
    ifile = "data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    assert N == 10
    assert instructions == [['turn on', 0, 0, 9, 9], ['turn off', 0, 0, 9, 9],
                            ['switch', 0, 0, 9, 9], ['turn off', 0, 0, 9, 9],
                            ['turn on', 2, 2, 7, 7]]
def test_parseFile():
    testFile = "C:\input.in"
    N, instructions = utils.parseFile(testFile)
    assert N == 10
    assert instructions == [
        'turn on 2,6 through 4,9\n', 'switch -1,0 through 15,10'
    ]
def test_read_file():
    ifile = "./data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    assert N == 10
    assert instructions == [
        'turn on 0,0 through 9,9\n', 'turn off 0,0 through 9,9\n',
        'switch 0,0 through 9,9\n', 'turn off 0,0 through 9,9\n',
        'turn on 2,2 through 7,7\n'
    ]
Beispiel #4
0
 def test_read_file(self):
     ifile = "C:/Users/Pavinee/led_tester/data/test_data.txt"
     N, instructions = utils.parseFile(ifile)
     assert N == 10
     print()
     assert instructions == [
         'turn on 0,0 through 9,9\n', 'turn off 0,0 through 9,9\n',
         'switch 0,0 through 9,9\n', 'turn off 0,0 through 9,9\n',
         'turn on 2,2 through 7,7'
     ]
def test_NumbersOutofBounds():
    testFile = "C:\input.in"
    N, instructions = utils.parseFile(testFile)
    for i in instructions:
        method, l1, l2, l3, l4 = rc.regexClean(i, N)
    assert method == 'switch'
    assert l1 == 0
    assert l2 == 0
    assert l3 == 9
    assert l4 == 9
def test_RegexNone():
    testFile = "C:\input.in"
    N, instructions = utils.parseFile(testFile)
    for i in instructions:
        method, l1, l2, l3, l4 = rc.regexClean(i, N)
    assert method == None
    assert l1 == None
    assert l2 == None
    assert l3 == None
    assert l4 == None
def test_outcome():
    ifile = "./data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    
    ledtester = led_tester.LightTester(N)
    
    for instruction in instructions:
        ledtester.apply(instruction)
    
    assert ('#occupied: ', 36) 
Beispiel #8
0
def main(input=None):
    """Console script for led_tester."""
    print("input", input) 
    N, instructions = utils.parseFile(input)
    ledTester = LEDTester(N)
    for instruction in instructions: 
        parsed_instruction = utils.find_matches(instruction)
        ledTester.apply(parsed_instruction)
    print('#occupied: ', ledTester.count()) 
    return 0
def main():
    ###############################################################################
    ###############################################################################

    #------------- Accepting command line arguments here--------------------

    parser = argparse.ArgumentParser(
    )  # parser to parse the command line aruments

    # Adding the list of accepted arguments to the parser

    parser.add_argument(
        "--input",
        "-i",
        help="Parameter required to provide input to the program",
        action="store_true"
    )  # Store true --> set it true only when this argument is provided

    parser.add_argument("filename",
                        help="Complete path for the file")  # Filepath

    args = parser.parse_args()  # Parse the arguments

    # Get the file path provided

    filePath = args.filename

    # ------------- Arguments Parsing completed---------------------

    ###############################################################################
    ###############################################################################

    # ------------- Reading the File and performing functions--------------------

    # Read the file only if input argument is provided
    if args.input:
        # startTime = time.time()
        L, ins = utils.parseFile(filePath)

        ## Creating the lights grid
        _lights = Lights.Lights(L)

        ## Getting the methods to be performed to test on the light grid
        for i in ins:
            method, l1, l2, l3, l4 = rc.regexClean(i, L)

            ## Run the instructions on the grid
            if method != None:
                _lights.runCmd(method, l1, l2, l3, l4)
            else:
                continue

        count = _lights.counts()
        # endTime = time.time()
        print(count)
def test_instructions_parsing_switch():
    ifile = "./data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    switch_pat = re.compile(
        ".*(switch)\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*through\s*([+-]?\d+)\s*,\s*([+-]?\d+).*"
    )
    switch = switch_pat.match(instructions[2])
    assert switch.group(1) == "switch"
    assert switch.group(2) == "0"
    assert switch.group(3) == "0"
    assert switch.group(4) == "9"
    assert switch.group(5) == "9"
def test_instructions_parsing_turn_on_22_77():
    ifile = "./data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    on_pat = re.compile(
        ".*(turn on)\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*through\s*([+-]?\d+)\s*,\s*([+-]?\d+).*"
    )
    on = on_pat.match(instructions[4])
    assert on.group(1) == "turn on"
    assert on.group(2) == "2"
    assert on.group(3) == "2"
    assert on.group(4) == "7"
    assert on.group(5) == "7"
def test_instructions_parsing_turn_off():
    ifile = "./data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    off_pat = re.compile(
        ".*(turn off)\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*through\s*([+-]?\d+)\s*,\s*([+-]?\d+).*"
    )
    off = off_pat.match(instructions[1])
    assert off.group(1) == "turn off"
    assert off.group(2) == "0"
    assert off.group(3) == "0"
    assert off.group(4) == "9"
    assert off.group(5) == "9"
Beispiel #13
0
def main(input=None):
    """Console script for led_tester."""
    print("input", input)
    
    N, instructions = utils.parseFile(input)
    
    ledTester = led_tester.LightTester(N)
    
    
    ledTester.apply(instructions)
    
    print('#occupied: ', ledTester.count()) 
    return 0
Beispiel #14
0
def main(input=None):
    """Console script for led_tester."""
    print("input", input)

    N, instructions = parseFile(input)
    LEDTester(N, instructions)
    #     N, instructions = parseFile(input)

    #     ledTester = LEDTester(N)
    #
    #     for instruction in instructions:
    #         ledTester.apply(instruction)
    #
    #     print('#occupied: ', ledTester.countOccupied())
    return 0
Beispiel #15
0
def main(input=None):
    """Console script for ledtester."""
    print("input", input)
    #invoke the function to parse the input file
    N, instructions = parseFile(input)

    if (N != 0):
        #creating an object of the class LEDTester
        ledTester = LEDTester(N)
        for instruction in instructions:
            instruction = str(instruction)
            #invoke function to apply the commands
            ledTester.apply(instruction)

        #invoke the function to count the lights that are on and print it.
        print("Number of lights on are : ", ledTester.countLights())
    return 0
Beispiel #16
0
 def test_command_line_interface(self):
     ifile = "C:/Users/Pavinee/led_tester/data/test_data.txt"
     N, instructions = utils.parseFile(ifile)
     assert N is not None
     assert instructions is not None
Beispiel #17
0
def test_command_line_interface():
    ifile = '../data/test_data.txt'
    N, instructions = utils.parseFile(ifile)
    print("N is ", N)
    print("instructions", instructions)
    assert N is not None
Beispiel #18
0
def test_run_file():
    ifile = "./data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    
    
    
Beispiel #19
0
import led_tester
import sys
from led_tester import utils
from led_tester import Grid

if __name__ == "__main__":

    # print(sys.argv)
    sys.argv
    file_name = sys.argv[2]
    utils.parseFile(file_name)
Beispiel #20
0
def test_light_grid_http_file():
    ifile = "http://claritytrec.ucd.ie/~alawlor/comp30670/input_assign3.txt"
    N, instructions = utils.parseFile(ifile)
    led_test2 = LEDTester(N)
    assert led_test2.size() == 1000000
Beispiel #21
0
def test_light_grid_local_file():
    ifile = "./data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    led_test1 = LEDTester(N)
    assert led_test1.size() == 100
Beispiel #22
0
def test_parsing_from_http_file():
    ifile = "http://claritytrec.ucd.ie/~alawlor/comp30670/input_assign3.txt"
    N, instructions = utils.parseFile(ifile)
    assert N == 1000
    assert instructions[0] == ['turn', 'off', '660,55', 'through', '986,197']
Beispiel #23
0
def test_reading_from_file():
    ifile = "./data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    print(instructions)
    assert N == 10
    assert instructions[0] == ['turn', 'on', '0,0', 'through', '9,9']
Beispiel #24
0
def test_get_size():
    ifile = "data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    assert N is not None
def test_command_line_interface():
    """Test the CLI."""
    ifile = "./data/test_data.txt"
    N, instructions = utils.parseFile(ifile)
    assert N is not None
def test_read_file_http():
    ifile = "http://claritytrec.ucd.ie/~alawlor/comp30670/input_assign3.txt"
    N, instructions = utils.parseFile(ifile)
    assert N == 1000
    assert instructions[0] == 'turn off 660,55 through 986,197'
Beispiel #27
0
 def test_switch(self):
     ifile = "C:/Users/Pavinee/led_tester/data/test_data.txt"
     N, instructions = utils.parseFile(ifile)
     assert N is not None
     assert instructions is not None
Beispiel #28
0
def main():
    ifile = "C:/Users/Pavinee/led_tester/data/input_assign3.txt"
    N, instructions = utils.parseFile(ifile)
    #print(N, instructions)
    matrix = LEDTester(N, instructions)