<commit_before>// Copyright 2014 The Cayley Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
	"sync"
	"testing"

	"github.com/google/cayley/config"
	"github.com/google/cayley/db"
	"github.com/google/cayley/graph"
	"github.com/google/cayley/query/gremlin"
)

var benchmarkQueries = []struct {
	message string
	query   string
	tag     string
	expect  [][]interface{}
}{
	// Easy one to get us started. How quick is the most straightforward retrieval?
	{
		message: "name predicate",
		query: `
		g.V("<NAME>").In("name").All()
		`,
		expect: [][]interface{}{
			{map[string]string{"id": ":/en/humphrey_bogart"}},
		},
	},

	// Grunty queries.
	// 2014-07-12: This one seems to return in ~20ms in memory;
	// that's going to be measurably slower for every other backend.
	{
		message: "two large sets with no intersection",
		query: `
		function getId(x) { return g.V(x).In("name") }
		var actor_to_film = g.M().In("/film/performance/actor").In("/film/film/starring")

		getId("<NAME>").Follow(actor_to_film).Out("name").Intersect(
			getId("<NAME>").Follow(actor_to_film).Out("name")).All()
			`,
		expect: nil,
	},

	// 2014-07-12: This one takes about 4 whole seconds in memory. This is a behemoth.
	{
		message: "three huge sets with small intersection",
		query: `
			function getId(x) { return g.V(x).In("name") }
			var actor_to_film = g.M().In("/film/performance/actor").In("/film/film/starring")

			var a = getId("<NAME>").Follow(actor_to_film).FollowR(actor_to_film)
			var b = getId("<NAME>").Follow(actor_to_film).FollowR(actor_to_film)
			var c = getId("<NAME>").Follow(actor_to_film).FollowR(actor_to_film)

			seen = {}

			a.Intersect(b).Intersect(c).ForEach(function (d) {
				if (!(d.id in seen)) {
					seen[d.id] = true;
					g.Emit(d.id)
				}
			})
			`,
		expect: [][]interface{}{
			{":/en/billy_gilbert"},
			{":/en/sterling_holloway"},
		},
	},

	// This is more of an optimization problem that will get better over time. This takes a lot
	// of wrong turns on the walk down to what is ultimately the name, but top AND has it easy
	// as it has a fixed ID. Exercises Check().
	{
		message: "the helpless checker",
		query: `
			g.V().As("person").In("name").In().In().Out("name").Is("Casablanca").All()
			`,
		tag: "person",
		expect: [][]interface{}{
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
		},
	},

	//Q: Who starred in both "The Net" and "Speed" ?
	//A: "<NAME>"
	{
		message: "Net and Speed",
		query: common + `m1_actors.Intersect(m2_actors).Out("name").All()
`,
		expect: [][]interface{}{
			{map[string]string{"id": "<NAME>", "movie1": "The Net", "movie2": "Speed"}},
		},
	},

	//Q: Did "Keanu Reeves" star in "The Net" ?
	//A: No
	{
		message: "Keanu in The Net",
		query: common + `actor2.Intersect(m1_actors).Out("name").All()
`,
		expect: nil,
	},

	//Q: Did "<NAME>" star in "Speed" ?
	//A: Yes
	{
		message: "Keanu in Speed",
		query: common + `actor2.Intersect(m2_actors).Out("name").All()
`,
		expect: [][]interface{}{
			{map[string]string{"id": "<NAME>", "movie2": "Speed"}},
		},
	},

	//Q: Has "<NAME>" co-starred with anyone who starred in "The Net" ?
	//A: "<NAME>" was in "Speed" and "The Lake House" with "<NAME>",
	//   who was in "The Net"
	{
		message: "Keanu with other in The Net",
		query: common + `actor2.Follow(coStars1).Intersect(m1_actors).Out("name").All()
`,
		expect: [][]interface{}{
			{map[string]string{"id": "<NAME>", "movie1": "The Net", "costar1_movie": "Speed"}},
			{map[string]string{"movie1": "The Net", "costar1_movie": "The Lake House", "id": "<NAME>"}},
		},
	},

	//Q: Do "<NAME>" and "<NAME>" have any commons co-stars?
	//A: Yes, many. For example: SB starred with "<NAME>" in "The Prince
	//    of Egypt", and KR starred with <NAME> in "Parenthood".
	{
		message: "Keanu and Bullock with other",
		query: common + `actor1.Save("name","costar1_actor").Follow(coStars1).Intersect(actor2.Save("name","costar2_actor").Follow(coStars2)).Out("name").All()
`,
		expect: [][]interface{}{
			{map[string]string{"costar2_movie": "Speed", "id": "Al<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "Keanu Reeves"}},
			{map[string]string{"costar1_movie": "Demolition Man", "costar2_actor": "<NAME>", "costar2_movie": "Thumbsucker", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Miss Congeniality", "costar2_actor": "<NAME>", "costar2_movie": "Thumbsucker", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Lake House", "costar2_actor": "<NAME>", "costar2_movie": "The Lake House", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Proposal", "costar2_actor": "<NAME>", "costar2_movie": "The Devil's Advocate", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "Keanu Reeves", "costar2_movie": "River's Edge", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "Chattahoochee", "costar2_actor": "Keanu Reeves"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Practical Magic", "costar2_actor": "Keanu Reeves", "costar2_movie": "Parenthood", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Lake House", "costar2_actor": "Keanu Reeves", "costar2_movie": "The Lake House", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "Keanu Reeves"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed 2: Cruise Control", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "While You Were Sleeping", "costar2_actor": "Keanu Reeves", "costar2_movie": "The Replacements", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Infamous", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "Ke<NAME>", "costar2_movie": "Speed"}},
			{map[string]string{"costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>", "costar2_movie": "Flying", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Lake House", "costar2_actor": "<NAME>", "costar2_movie": "Flying", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "The Day the Earth Stood Still", "costar2_actor": "<NAME>", "costar2_movie": "The Animatrix", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Tune in Tomorrow"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "Keanu Reeves", "costar2_movie": "The Last Time I Committed Suicide", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Constantine", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Permanent Record", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Dangerous Liaisons", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Private Lives of <NAME>", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "A Scanner Darkly", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "A Walk in the Clouds", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Hardball", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Life Under Water", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Much Ado About Nothing", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "My Own Private Idaho", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Parenthood", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Point Break", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Providence", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "River's Edge", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Something's Gotta Give", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Sweet November", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Lake House", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Matrix Reloaded"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Matrix Revisited", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Prince of Pennsylvania", "id": "<NAME>"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "The Replacements", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Even Cowgirls Get the Blues", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Youngblood", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "<NAME> Bogus Journey", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "<NAME>'s Excellent Adventure", "id": "<NAME>"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "<NAME>nemonic"}},
			{map[string]string{"costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Devil's Advocate", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Thumbsucker", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "I Love You to Death", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "<NAME>", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "The Gift", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film"}},
			{map[string]string{"costar2_movie": "Little Buddha", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Night Watchman", "id": "<NAME>"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Chain Reaction"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Babes in Toyland", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Day the Earth Stood Still", "id": "<NAME>"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "The Lake House", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "The Lake House"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Proposal", "costar2_actor": "<NAME>", "costar2_movie": "Parenthood", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Prince of Egypt", "costar2_actor": "<NAME>", "costar2_movie": "Dangerous Liaisons", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Premonition", "costar2_actor": "<NAME>", "costar2_movie": "Constantine", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_movie": "The Thing Called Love", "costar2_actor": "<NAME>", "costar2_movie": "My Own Private Idaho", "id": "River Phoenix", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "I Love You to Death", "id": "River Phoenix"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Proposal", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Crash", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Gun Shy", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Demolition Man"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Divine Secrets of the Ya-Ya Sisterhood", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "A Time to Kill", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Forces of Nature", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Hope Floats", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Infamous", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Love Potion No. 9", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Miss Congeniality", "costar2_actor": "<NAME>", "costar2_movie": "Speed"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Miss Congeniality 2: Armed and Fabulous", "costar2_actor": "<NAME>", "costar2_movie": "Speed"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Murder by Numbers", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Practical Magic", "costar2_actor": "Ke<NAME>", "costar2_movie": "Speed"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed"}},
			{map[string]string{"costar1_movie": "Speed 2: Cruise Control", "costar2_actor": "Ke<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Lake House", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Net", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "The Prince of Egypt", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Two Weeks Notice"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "While You Were Sleeping", "costar2_actor": "Keanu Reeves"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "28 Days", "costar2_actor": "<NAME>", "costar2_movie": "Speed"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Premonition"}},
			{map[string]string{"costar1_movie": "<NAME>", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Fire on the Amazon"}},
			{map[string]string{"costar1_movie": "The Thing Called Love", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "In Love and War", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Lake House", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Divine Secrets of the Ya-Ya Sisterhood", "costar2_actor": "<NAME>", "costar2_movie": "The Private Lives of Pippa Lee", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "The Lake House", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "The Lake House", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Prince of Egypt", "costar2_actor": "<NAME>", "costar2_movie": "Parenthood", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>, Jr."}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
		},
	},
}

const common = `
var movie1 = g.V().Has("name", "The Net")
var movie2 = g.V().Has("name", "Speed")
var actor1 = g.V().Has("name", "<NAME>")
var actor2 = g.V().Has("name", "<NAME>")

// (film) -> starring -> (actor)
var filmToActor = g.Morphism().Out("/film/film/starring").Out("/film/performance/actor")

// (actor) -> starring -> [film -> starring -> (actor)]
var coStars1 = g.Morphism().In("/film/performance/actor").In("/film/film/starring").Save("name","costar1_movie").Follow(filmToActor)
var coStars2 = g.Morphism().In("/film/performance/actor").In("/film/film/starring").Save("name","costar2_movie").Follow(filmToActor)

// Stars for the movies "The Net" and "Speed"
var m1_actors = movie1.Save("name","movie1").Follow(filmToActor)
var m2_actors = movie2.Save("name","movie2").Follow(filmToActor)
`

var (
	once sync.Once
	cfg  = &config.Config{
		DatabasePath:   "30kmoviedata.nt.gz",
		DatabaseType:   "memstore",
		GremlinTimeout: 300,
	}

	ts graph.TripleStore
)

func prepare(t testing.TB) {
	var err error
	once.Do(func() {
		ts, err = db.Open(cfg)
		if err != nil {
			t.Fatalf("Failed to open %q: %v", cfg.DatabasePath, err)
		}
	})
}

func TestQueries(t *testing.T) {
	prepare(t)<commit_msg>Update tests to use cquads parsed data<commit_after>// Copyright 2014 The Cayley Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
	"sync"
	"testing"

	"github.com/google/cayley/config"
	"github.com/google/cayley/db"
	"github.com/google/cayley/graph"
	"github.com/google/cayley/query/gremlin"
)

var benchmarkQueries = []struct {
	message string
	query   string
	tag     string
	expect  [][]interface{}
}{
	// Easy one to get us started. How quick is the most straightforward retrieval?
	{
		message: "name predicate",
		query: `
		g.V("<NAME>").In("name").All()
		`,
		expect: [][]interface{}{
			{map[string]string{"id": "/en/humphrey_bogart"}},
		},
	},

	// Grunty queries.
	// 2014-07-12: This one seems to return in ~20ms in memory;
	// that's going to be measurably slower for every other backend.
	{
		message: "two large sets with no intersection",
		query: `
		function getId(x) { return g.V(x).In("name") }
		var actor_to_film = g.M().In("/film/performance/actor").In("/film/film/starring")

		getId("<NAME>").Follow(actor_to_film).Out("name").Intersect(
			getId("<NAME>").Follow(actor_to_film).Out("name")).All()
			`,
		expect: nil,
	},

	// 2014-07-12: This one takes about 4 whole seconds in memory. This is a behemoth.
	{
		message: "three huge sets with small intersection",
		query: `
			function getId(x) { return g.V(x).In("name") }
			var actor_to_film = g.M().In("/film/performance/actor").In("/film/film/starring")

			var a = getId("<NAME>").Follow(actor_to_film).FollowR(actor_to_film)
			var b = getId("<NAME>").Follow(actor_to_film).FollowR(actor_to_film)
			var c = getId("<NAME>").Follow(actor_to_film).FollowR(actor_to_film)

			seen = {}

			a.Intersect(b).Intersect(c).ForEach(function (d) {
				if (!(d.id in seen)) {
					seen[d.id] = true;
					g.Emit(d.id)
				}
			})
			`,
		expect: [][]interface{}{
			{"/en/billy_gilbert"},
			{"/en/sterling_holloway"},
		},
	},

	// This is more of an optimization problem that will get better over time. This takes a lot
	// of wrong turns on the walk down to what is ultimately the name, but top AND has it easy
	// as it has a fixed ID. Exercises Check().
	{
		message: "the helpless checker",
		query: `
			g.V().As("person").In("name").In().In().Out("name").Is("Casablanca").All()
			`,
		tag: "person",
		expect: [][]interface{}{
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
			{map[string]string{"id": "Casablanca", "person": "<NAME>"}},
		},
	},

	//Q: Who starred in both "The Net" and "Speed" ?
	//A: "<NAME>"
	{
		message: "Net and Speed",
		query: common + `m1_actors.Intersect(m2_actors).Out("name").All()
`,
		expect: [][]interface{}{
			{map[string]string{"id": "<NAME>", "movie1": "The Net", "movie2": "Speed"}},
		},
	},

	//Q: Did "<NAME>eves" star in "The Net" ?
	//A: No
	{
		message: "Keanu in The Net",
		query: common + `actor2.Intersect(m1_actors).Out("name").All()
`,
		expect: nil,
	},

	//Q: Did "Keanu Reeves" star in "Speed" ?
	//A: Yes
	{
		message: "Keanu in Speed",
		query: common + `actor2.Intersect(m2_actors).Out("name").All()
`,
		expect: [][]interface{}{
			{map[string]string{"id": "<NAME>", "movie2": "Speed"}},
		},
	},

	//Q: Has "<NAME>" co-starred with anyone who starred in "The Net" ?
	//A: "<NAME>" was in "Speed" and "The Lake House" with "<NAME>",
	//   who was in "The Net"
	{
		message: "Keanu with other in The Net",
		query: common + `actor2.Follow(coStars1).Intersect(m1_actors).Out("name").All()
`,
		expect: [][]interface{}{
			{map[string]string{"id": "<NAME>", "movie1": "The Net", "costar1_movie": "Speed"}},
			{map[string]string{"movie1": "The Net", "costar1_movie": "The Lake House", "id": "<NAME>"}},
		},
	},

	//Q: Do "<NAME>" and "<NAME>" have any commons co-stars?
	//A: Yes, many. For example: SB starred with "<NAME>" in "The Prince
	//    of Egypt", and KR starred with <NAME> in "Parenthood".
	{
		message: "Keanu and Bullock with other",
		query: common + `actor1.Save("name","costar1_actor").Follow(coStars1).Intersect(actor2.Save("name","costar2_actor").Follow(coStars2)).Out("name").All()
`,
		expect: [][]interface{}{
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_movie": "Demolition Man", "costar2_actor": "<NAME>", "costar2_movie": "Thumbsucker", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Miss Congeniality", "costar2_actor": "<NAME>", "costar2_movie": "Thumbsucker", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Lake House", "costar2_actor": "Keanu Reeves", "costar2_movie": "The Lake House", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Proposal", "costar2_actor": "Keanu Reeves", "costar2_movie": "The Devil's Advocate", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "Keanu Reeves", "costar2_movie": "River's Edge", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "Chattahoochee", "costar2_actor": "Keanu Reeves"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Practical Magic", "costar2_actor": "Keanu Reeves", "costar2_movie": "Parenthood", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Lake House", "costar2_actor": "Keanu Reeves", "costar2_movie": "The Lake House", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed 2: Cruise Control", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "While You Were Sleeping", "costar2_actor": "Ke<NAME>", "costar2_movie": "The Replacements", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Infamous", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "Ke<NAME>", "costar2_movie": "Speed"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>", "costar2_movie": "Flying", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Lake House", "costar2_actor": "<NAME>", "costar2_movie": "Flying", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "The Day the Earth Stood Still", "costar2_actor": "<NAME>", "costar2_movie": "The Animatrix", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Tune in Tomorrow"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Last Time I Committed Suicide", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Constantine", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Permanent Record", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Dangerous Liaisons", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Private Lives of Pippa Lee", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "A Scanner Darkly", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "A Walk in the Clouds", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Hardball", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Life Under Water", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Much Ado About Nothing", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "My Own Private Idaho", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Parenthood", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Point Break", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Providence", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "River's Edge", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Something's Gotta Give", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Sweet November", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Lake House", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Matrix Reloaded"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Matrix Revisited", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Prince of Pennsylvania", "id": "<NAME>"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "The Replacements", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Even Cowgirls Get the Blues", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Youngblood", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Bill & Ted's Bogus Journey", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Bill & Ted's Excellent Adventure", "id": "<NAME>"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Johnny Mnemonic"}},
			{map[string]string{"costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Devil's Advocate", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Thumbsucker", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "I Love You to Death", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "<NAME> Dracula", "id": "<NAME>", "costar1_actor": "/people/person"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "The Gift", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film"}},
			{map[string]string{"costar2_movie": "Little Buddha", "id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Night Watchman", "id": "<NAME>"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Chain Reaction"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "Babes in Toyland", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Day the Earth Stood Still", "id": "<NAME>"}},
			{map[string]string{"costar2_actor": "<NAME>", "costar2_movie": "The Lake House", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "The Lake House"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Proposal", "costar2_actor": "<NAME>", "costar2_movie": "Parenthood", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Prince of Egypt", "costar2_actor": "<NAME>", "costar2_movie": "Dangerous Liaisons", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Premonition", "costar2_actor": "<NAME>", "costar2_movie": "Constantine", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_movie": "The Thing Called Love", "costar2_actor": "<NAME>", "costar2_movie": "My Own Private Idaho", "id": "River Phoenix", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "I Love You to Death", "id": "River Phoenix"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Proposal", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Crash", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Gun Shy", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar2_actor": "Ke<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Demolition Man"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Divine Secrets of the Ya-Ya Sisterhood", "costar2_actor": "Ke<NAME>"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "A Time to Kill", "costar2_actor": "Keanu Reeves"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Forces of Nature", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Hope Floats", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Infamous", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Love Potion No. 9", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Miss Congeniality", "costar2_actor": "Ke<NAME>", "costar2_movie": "Speed"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Miss Congeniality 2: Armed and Fabulous", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Murder by Numbers", "costar2_actor": "Ke<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Practical Magic", "costar2_actor": "Ke<NAME>", "costar2_movie": "Speed"}},
			{map[string]string{"costar2_actor": "Ke<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Speed"}},
			{map[string]string{"costar1_movie": "Speed 2: Cruise Control", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Lake House", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Net", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_movie": "The Prince of Egypt", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Two Weeks Notice"}},
			{map[string]string{"costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "While You Were Sleeping", "costar2_actor": "Keanu Reeves"}},
			{map[string]string{"id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "28 Days", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed"}},
			{map[string]string{"costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Premonition"}},
			{map[string]string{"costar1_movie": "<NAME>", "costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar2_actor": "Keanu Reeves", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "Fire on the Amazon"}},
			{map[string]string{"costar1_movie": "The Thing Called Love", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>", "costar1_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "In Love and War", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "/people/person", "costar1_movie": "/film/film", "costar2_actor": "<NAME>", "costar2_movie": "The Lake House", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Divine Secrets of the Ya-Ya Sisterhood", "costar2_actor": "<NAME>", "costar2_movie": "The Private Lives of Pippa Lee", "id": "<NAME>"}},
			{map[string]string{"costar2_movie": "The Lake House", "id": "<NAME>", "costar1_actor": "<NAME>", "costar1_movie": "The Lake House", "costar2_actor": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "The Prince of Egypt", "costar2_actor": "<NAME>", "costar2_movie": "Parenthood", "id": "<NAME>"}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>, Jr."}},
			{map[string]string{"costar1_actor": "<NAME>", "costar1_movie": "Speed", "costar2_actor": "<NAME>", "costar2_movie": "Speed", "id": "<NAME>"}},
		},
	},
}

const common = `
var movie1 = g.V().Has("name", "The Net")
var movie2 = g.V().Has("name", "Speed")
var actor1 = g.V().Has("name", "<NAME>")
var actor2 = g.V().Has("name", "<NAME>")

// (film) -> starring -> (actor)
var filmToActor = g.Morphism().Out("/film/film/starring").Out("/film/performance/actor")

// (actor) -> starring -> [film -> starring -> (actor)]
var coStars1 = g.Morphism().In("/film/performance/actor").In("/film/film/starring").Save("name","costar1_movie").Follow(filmToActor)
var coStars2 = g.Morphism().In("/film/performance/actor").In("/film/film/starring").Save("name","costar2_movie").Follow(filmToActor)

// Stars for the movies "The Net" and "Speed"
var m1_actors = movie1.Save("name","movie1").Follow(filmToActor)
var m2_actors = movie2.Save("name","movie2").Follow(filmToActor)
`

var (
	once sync.Once
	cfg  = &config.Config{
		DatabasePath:   "30kmoviedata.nq.gz",
		DatabaseType:   "memstore",
		GremlinTimeout: 300,
	}

	ts graph.TripleStore
)

func prepare(t testing.TB) {
	var err error
	once.Do(func() {
		ts, err = db.Open(cfg)
		if err != nil {
			t.Fatalf("Failed to open %q: %v", cfg.DatabasePath, err)
		}
	})
}

func TestQueries(t *testing.T) {
	prepare(t)
{'fraction_non_alphanumeric': 0.24469165136623824, 'fraction_numerical': 0.02047737336645426, 'mean_word_length': 6.786074672048436, 'pattern_counts': {'":': 1087, '<': 557, '<?xml version=': 0, '>': 569, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3045173', 'n_tokens_mistral': 18257, 'n_tokens_neox': 16855, 'n_words': 3600}