Skip to content

Commit

Permalink
Fixing more conformance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kellrott committed Mar 20, 2020
1 parent edeb5ea commit dc1c91e
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 216 deletions.
6 changes: 3 additions & 3 deletions conformance/graphs/swapi.edges
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
{"gid": "(Film:1)-[characters]->(Character:18)", "label": "characters", "from": "Film:1", "to": "Character:18"}
{"gid": "(Film:1)-[characters]->(Character:19)", "label": "characters", "from": "Film:1", "to": "Character:19"}
{"gid": "(Film:1)-[characters]->(Character:81)", "label": "characters", "from": "Film:1", "to": "Character:81"}
{"gid": "(Film:1)-[planets]->(Planet:2)", "label": "planets", "from": "Film:1", "to": "Planet:2"}
{"gid": "(Film:1)-[planets]->(Planet:3)", "label": "planets", "from": "Film:1", "to": "Planet:3"}
{"gid": "(Film:1)-[planets]->(Planet:1)", "label": "planets", "from": "Film:1", "to": "Planet:1"}
{"gid": "(Film:1)-[planets]->(Planet:2)", "label": "planets", "from": "Film:1", "to": "Planet:2", "data" : {"scene_count" : 10}}
{"gid": "(Film:1)-[planets]->(Planet:3)", "label": "planets", "from": "Film:1", "to": "Planet:3", "data" : {"scene_count" : 15}}
{"gid": "(Film:1)-[planets]->(Planet:1)", "label": "planets", "from": "Film:1", "to": "Planet:1", "data" : {"scene_count" : 20}}
{"gid": "(Film:1)-[starships]->(Starship:2)", "label": "starships", "from": "Film:1", "to": "Starship:2"}
{"gid": "(Film:1)-[starships]->(Starship:3)", "label": "starships", "from": "Film:1", "to": "Starship:3"}
{"gid": "(Film:1)-[starships]->(Starship:5)", "label": "starships", "from": "Film:1", "to": "Starship:5"}
Expand Down
178 changes: 60 additions & 118 deletions conformance/tests/ot_aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@
import gripql
import numpy as np

eye_color_count_map = {
"brown": 4,
"blue": 6,
"red": 2,
"yellow": 2,
"black": 1,
"blue-gray": 1,
"hazel": 1,
"orange": 1
}


def test_simple(O, man):
errors = []

man.setGraph("swapi")

count = 0
for row in O.query().V().aggregate(gripql.term("simple-agg", "name")):
for row in O.query().V().aggregate(gripql.term("simple-agg", "eye_color")):
if 'simple-agg' not in row:
errors.append("Result had Incorrect aggregation name")
return errors
row = row['simple-agg']
for res in row["buckets"]:
count += 1
if res['key'] in ['marko', 'alex']:
if res['value'] != 2:
errors.append("Wrong key count for %s" % (res['key']))
elif res['key'] in ['funnel', 'josh', 'vadas', 'peter', 'steve', 'lop', 'alice', 'wanda', 'ripple']:
if res['value'] != 1:
errors.append("Wrong key count for %s" % (res['key']))
if count != 23:
if eye_color_count_map[res['key']] != res['value']:
errors.append("Wrong key count for %s %d != %d" % (res['key'], res["value"], eye_color_count_map[res['key']]))
if count != 8:
errors.append("Wrong number of results recieved %d" % (count))
return errors

Expand All @@ -34,30 +41,22 @@ def test_traversal_term_aggregation(O, man):
man.setGraph("swapi")

count = 0
for row in O.query().V("01").out().hasLabel("Person").aggregate(gripql.term("traversal-agg", "name")):
for row in O.query().V("Film:1").out().hasLabel("Character").aggregate(gripql.term("traversal-agg", "eye_color")):
if 'traversal-agg' not in row:
errors.append("Result had Incorrect aggregation name")
return errors
row = row['traversal-agg']

count += 1
if len(row["buckets"]) != 5:
if len(row["buckets"]) != len(eye_color_count_map):
errors.append(
"Unexpected number of terms: %d != %d" %
(len(row["buckets"]), 5)
(len(row["buckets"]), len(eye_color_count_map))
)

for res in row["buckets"]:
if res["key"] == "alex":
if res["value"] != 2:
errors.append(
"Incorrect term count: %d != %d" %
(res["value"], 2))
else:
if res["value"] != 1:
errors.append(
"Incorrect term count: %d != %d" %
(res["value"], 1))
if eye_color_count_map[res['key']] != res['value']:
errors.append("Wrong key count for %s %d != %d" % (res['key'], res["value"], eye_color_count_map[res['key']]))

if count != 1:
errors.append(
Expand All @@ -72,37 +71,29 @@ def test_traversal_histogram_aggregation(O, man):

man.setGraph("swapi")

height_agg_map = {
75: 2,
100: 0,
125: 0,
150: 6,
175: 8,
200: 1,
225: 1
}

count = 0
for row in O.query().V("01").out().hasLabel("Person").aggregate(gripql.histogram("traversal-agg", "age", 5)):
for row in O.query().V("Film:1").out().hasLabel("Character").aggregate(gripql.histogram("traversal-agg", "height", 25)):
count += 1
if 'traversal-agg' not in row:
errors.append("Result had Incorrect aggregation name")
return errors
row = row['traversal-agg']

if len(row["buckets"]) < 4:
errors.append(
"Unexpected number of terms: %d != %d" %
(len(row["buckets"]), 4)
)

for res in row["buckets"]:
if res["key"] == 20:
if res["value"] != 1:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == 25:
if res["value"] != 2:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == 30:
if res["value"] != 1:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == 35:
if res["value"] != 1:
errors.append("Incorrect bucket count returned: %s" % res)
else:
errors.append("Incorrect bucket key returned: %s" % res)
if height_agg_map[res["key"]] != res["value"]:
errors.append("Incorrect bucket count returned: %s" % res)

if len(row["buckets"]) != 4:
if len(row["buckets"]) != 7:
errors.append("Incorrect bucket size returned: %d" % len(row["buckets"]))

if count != 1:
Expand All @@ -120,57 +111,29 @@ def test_traversal_percentile_aggregation(O, man):

count = 0
percents = [1, 5, 25, 50, 75, 95, 99, 99.9]
for row in O.query().V("01").out().hasLabel("Person").aggregate(gripql.percentile("traversal-agg", "age", percents)):
for row in O.query().V("Film:1").out().hasLabel("Character").aggregate(gripql.percentile("traversal-agg", "height", percents)):
count += 1

if 'traversal-agg' not in row:
errors.append("Result had Incorrect aggregation name")
return errors
row = row['traversal-agg']

print(row)
if len(row["buckets"]) != len(percents):
errors.append(
"Unexpected number of terms: %d != %d" %
(len(row["buckets"]), len(percents))
)

ages = np.array([25, 35, 32, 26, 22])
heights = np.array([96, 97, 150, 165, 167, 170, 172, 173, 175, 178, 180, 180, 180, 182, 183, 188, 202, 228])

# for tests quantiles need to be withing 15% of the actual value
def getMinMax(input_data, percent, accuracy=0.15):
return np.percentile(input_data, percent) * (1 - accuracy), np.percentile(input_data, percent) * (1 + accuracy)

for res in row["buckets"]:
if res["key"] == 1:
minpv, maxpv = getMinMax(ages, res["key"])
if res["value"] <= minpv or res["value"] >= maxpv:
errors.append("Incorrect quantile value returned for %.2f:\n\tmin: %.2f\n\tmax: %.2f\n\tactual: %.2f" % (res["key"], minpv, maxpv, res["value"]))
elif res["key"] == 5:
minpv, maxpv = getMinMax(ages, res["key"])
if res["value"] <= minpv or res["value"] >= maxpv:
errors.append("Incorrect quantile value returned for %.2f:\n\tmin: %.2f\n\tmax: %.2f\n\tactual: %.2f" % (res["key"], minpv, maxpv, res["value"]))
elif res["key"] == 25:
minpv, maxpv = getMinMax(ages, res["key"])
if res["value"] <= minpv or res["value"] >= maxpv:
errors.append("Incorrect quantile value returned for %.2f:\n\tmin: %.2f\n\tmax: %.2f\n\tactual: %.2f" % (res["key"], minpv, maxpv, res["value"]))
elif res["key"] == 50:
minpv, maxpv = getMinMax(ages, res["key"])
if res["value"] <= minpv or res["value"] >= maxpv:
errors.append("Incorrect quantile value returned for %.2f:\n\tmin: %.2f\n\tmax: %.2f\n\tactual: %.2f" % (res["key"], minpv, maxpv, res["value"]))
elif res["key"] == 75:
minpv, maxpv = getMinMax(ages, res["key"])
if res["value"] <= minpv or res["value"] >= maxpv:
errors.append("Incorrect quantile value returned for %.2f:\n\tmin: %.2f\n\tmax: %.2f\n\tactual: %.2f" % (res["key"], minpv, maxpv, res["value"]))
elif res["key"] == 95:
minpv, maxpv = getMinMax(ages, res["key"])
if res["value"] <= minpv or res["value"] >= maxpv:
errors.append("Incorrect quantile value returned for %.2f:\n\tmin: %.2f\n\tmax: %.2f\n\tactual: %.2f" % (res["key"], minpv, maxpv, res["value"]))
elif res["key"] == 99:
minpv, maxpv = getMinMax(ages, res["key"])
if res["value"] <= minpv or res["value"] >= maxpv:
errors.append("Incorrect quantile value returned for %.2f:\n\tmin: %.2f\n\tmax: %.2f\n\tactual: %.2f" % (res["key"], minpv, maxpv, res["value"]))
elif res["key"] == 99.9:
minpv, maxpv = getMinMax(ages, res["key"])
if res["key"] in percents:
minpv, maxpv = getMinMax(heights, res["key"])
if res["value"] <= minpv or res["value"] >= maxpv:
errors.append("Incorrect quantile value returned for %.2f:\n\tmin: %.2f\n\tmax: %.2f\n\tactual: %.2f" % (res["key"], minpv, maxpv, res["value"]))
else:
Expand All @@ -189,49 +152,31 @@ def test_traversal_edge_histogram_aggregation(O, man):

man.setGraph("swapi")

scene_count_agg_map = {
8: 1,
12: 1,
16: 0,
20: 1
}

count = 0
for row in O.query().V().hasLabel("Person").outE().aggregate(gripql.histogram("edge-agg", "count", 4)):
for row in O.query().V().hasLabel("Film").outE().aggregate(gripql.histogram("edge-agg", "scene_count", 4)):
count += 1
if 'edge-agg' not in row:
errors.append("Result had Incorrect aggregation name")
return errors
row = row['edge-agg']

if len(row["buckets"]) < 2:
errors.append(
"Unexpected number of terms: %d != %d" %
(len(row["buckets"]), 2)
)

for res in row["buckets"]:
if res["key"] == 4:
if res["value"] != 2:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == 20:
if res["value"] != 2:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == 28:
if res["value"] != 1:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == 32:
if res["value"] != 2:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == 48:
if res["value"] != 1:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == 72:
if res["value"] != 3:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == 88:
if res["value"] != 1:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] in [8, 12, 16, 24, 36, 40, 44, 52, 56, 60, 64, 68, 76, 80, 84]:
if res["value"] != 0:
errors.append("Incorrect bucket count returned: %s" % res)
else:
errors.append("Incorrect bucket key returned: %s" % res)
if scene_count_agg_map[res["key"]] != res["value"]:
errors.append("Incorrect bucket count returned: %s" % res)

if len(row["buckets"]) != 22:
if len(row["buckets"]) != len(scene_count_agg_map):
errors.append("Incorrect bucket count: %d" % len(row["buckets"]))
if count != 1:
errors.append(
Expand All @@ -246,32 +191,29 @@ def test_traversal_gid_aggregation(O, man):

man.setGraph("swapi")

planet_agg_map = {
"Planet:1": 7,
"Planet:2": 2
}

count = 0
for row in O.query().V().hasLabel("Person").as_("a").out("knows").select("a").aggregate(gripql.term("gid-agg", "_gid")):
for row in O.query().V().hasLabel("Planet").as_("a").out("residents").select("a").aggregate(gripql.term("gid-agg", "_gid")):
count += 1
if 'gid-agg' not in row:
errors.append("Result had Incorrect aggregation name")
return errors
row = row['gid-agg']
print(row)

if len(row["buckets"]) < 2:
if len(row["buckets"]) < len(planet_agg_map):
errors.append(
"Unexpected number of terms: %d != %d" %
(len(row["buckets"]), 2)
)

for res in row["buckets"]:
if res["key"] == "01":
if res["value"] != 4:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == "02":
if res["value"] != 1:
errors.append("Incorrect bucket count returned: %s" % res)
elif res["key"] == "04":
if res["value"] != 1:
errors.append("Incorrect bucket count returned: %s" % res)
else:
errors.append("Incorrect bucket key returned: %s" % res)
if planet_agg_map[res["key"]] != res["value"]:
errors.append("Incorrect bucket count returned: %s" % res)

if count != 1:
errors.append(
Expand Down
8 changes: 4 additions & 4 deletions conformance/tests/ot_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def test_count(O, man):
i = list(O.query().V().count())
if len(i) < 1:
errors.append("Fail: nothing returned for O.query().V().count()")
elif i[0].count != 25:
errors.append("Fail: O.query().V().count() %s != %s" % (i[0].count, 25))
elif i[0].count != 39:
errors.append("Fail: O.query().V().count() %s != %s" % (i[0].count, 39))

i = list(O.query().V("non-existent").count())
if len(i) < 1:
Expand All @@ -20,8 +20,8 @@ def test_count(O, man):
i = list(O.query().E().count())
if len(i) < 1:
errors.append("Fail: nothing returned for O.query().E().count()")
elif i[0].count != 14:
errors.append("Fail: O.query().E().count() %s != %s" % (i[0].count, 14))
elif i[0].count != 144:
errors.append("Fail: O.query().E().count() %s != %s" % (i[0].count, 144))

i = list(O.query().E("non-existent").count())
if len(i) < 1:
Expand Down
10 changes: 5 additions & 5 deletions conformance/tests/ot_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ def test_fields(O, man):
man.setGraph("swapi")

expected = {
u"gid": u"10",
u"gid": u"Character:1",
u"label": u"Character",
u"data": {u"name": u"han"}
u"data": {u"name": u"Luke Skywalker"}
}
resp = O.query().V("10").fields(["name"]).execute()
resp = O.query().V("Character:1").fields(["name"]).execute()
if resp[0] != expected:
errors.append("vertex contains incorrect fields: \nexpected:%s\nresponse:%s" % (expected, resp))

expected = {
u"gid": u"10",
u"gid": u"Character:1",
u"label": u"Character",
u"data": {}
}
resp = O.query().V("10").fields(["non-existent"]).execute()
resp = O.query().V("Character:1").fields(["non-existent"]).execute()
if resp[0] != expected:
errors.append("vertex contains incorrect fields: \nexpected:%s\nresponse:%s" % (expected, resp))

Expand Down
Loading

0 comments on commit dc1c91e

Please sign in to comment.