Update tests

This commit is contained in:
Isaac Shoebottom 2022-11-18 16:30:31 -04:00
parent bfdc5dc93b
commit 8501f2f473
3 changed files with 30 additions and 7 deletions

View File

@ -37,7 +37,10 @@ def select(table, search_items):
columns = list()
for item in search_items:
columns.append(header_numbers[item])
if type(item) is int: # Convert searched elements into strings if it is a number
columns.append(header_numbers[str(item)])
else:
columns.append(header_numbers[item])
columns.sort()
for item in table:
lst = list()
@ -96,11 +99,9 @@ def check_row(row, query):
if type(query[0]) and type(query[2]) is tuple:
return perform_operation(query[1], query[0], query[2])
elif query[2] not in row:
else:
stringify = str(query[2])
return perform_operation(query[1], row[str(query[0])], stringify)
else:
return perform_operation(query[1], row[str(query[0])], row[query[2]])
def filter_table(table, query):

View File

@ -81,6 +81,24 @@ def test_filter_table2():
# Student Tests
table2 = read_csv('test2.csv')
hmap2 = header_map(table2[0])
def test_header_map2():
assert header_map(table2[0]) == {"name": 0, "100": 1}
def test_select2():
assert select(table2, [100]) == [["100"], ["500"], ["1000"]]
assert select(table2, ["name"]) == [["name"], ["teddy"], ["lovely"]]
assert select(table2, ["name", 100]) == [["name", "100"], ["teddy", "500"], ["lovely", "1000"]]
def test_row2dict2():
assert row2dict(hmap2, table2[1]) == {"name": "teddy", "100": "500"}
assert row2dict(hmap2, table2[2]) == {"name": "lovely", "100": "1000"}
def test_check_row_2():
row = {'name': 'Bob', 'age': '5', 'eye colour': 'blue'}
@ -88,6 +106,9 @@ def test_check_row_2():
def test_check_row_3():
# Could not get test to pass, but included for completeness of tests
table2 = read_csv('test2.csv')
assert check_row(table2[1], ("100", "==", "500"))
row = row2dict(hmap2, table2[1])
assert check_row(row, ("100", "==", 500))
def test_filter_table3():
assert filter_table(table2, ("100", ">=", 100)) == [["name", "100"], ["teddy", "500"], ["lovely", "1000"]]

View File

@ -2,6 +2,7 @@ from readcsv import *
sampledata = read_csv('2014-1000.csv')
# Wanted to make more tests but time-consuming to check data for correctness
# Student Tests
def test_header_map_big_data():