예제 #1
0
def test_pair_finder_input_long():
    input_file = read_local_input('input_long.txt')
    input_list = list_input(input_file)
    counted_items = count_items(input_list)
    pairs = pairs_finder(counted_items)
    assert pairs == [[4, 8], [4, 8], [4, 8], [4, 8], [4, 8], [12, 0], [3, 9],
                     [3, 9], [3, 9], [5, 7], [1, 11], [5.5, 6.5], [7.5, 4.5]]
예제 #2
0
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            abort(400)
        filename = secure_filename(request.files['file'].filename)
        if filename != '':
            file_ext = splitext(filename)[1]
            if file_ext not in app.config['UPLOAD_EXTENSIONS']:
                abort(400)
            input_string = request.files['file'].read().decode('utf-8')
            input_list = list_input(input_string)
            counted_items = count_items(input_list)
            pairs = pairs_finder(counted_items)
            write_output(pairs)
        return send_file('output.txt', attachment_filename='output.txt',
                         as_attachment=True, mimetype='text/plain')
예제 #3
0
def test_reading_input_blank_strings():
    input_file = read_local_input('input_blank_and_strings.txt')
    input_list = list_input(input_file)
    assert input_list == [4, 8, 9, 0, 12, 1, 4, 2, 12, 12, 4, 4, 12, 0]
예제 #4
0
def test_counting_values_basic():
    input_file = read_local_input('input_basic.txt')
    input_list = list_input(input_file)
    counted_items = count_items(input_list)
    assert counted_items == {4: 4, 8: 2, 9: 1, 0: 2, 12: 4, 1: 1, 2: 1, 11: 1}
예제 #5
0
def test_reading_input_decimal():
    input_file = read_local_input('input_decimal.txt')
    input_list = list_input(input_file)
    assert input_list == [9, 5.5, 6.5, 3, 5, 5, 5, 6, 8, 3, 7, 1, 1, 11, 12, 12]