package graph_queries

import (
	"strings"
	"testing"
)

func TestEdgeQueriesUseNamedGraphsAndDistinct(t *testing.T) {
	tests := []struct {
		name  string
		query string
	}{
		{name: "default", query: defaultEdgeQuery(100, 25, false)},
		{name: "hierarchy", query: hierarchyEdgeQuery(100, 25, false)},
		{name: "types_only", query: typesOnlyEdgeQuery(100, 25, false)},
	}

	for _, tt := range tests {
		if !strings.Contains(tt.query, "SELECT DISTINCT ?s ?p ?o") {
			t.Fatalf("%s edge query should de-duplicate triples across named graphs:\n%s", tt.name, tt.query)
		}
		if !strings.Contains(tt.query, "GRAPH ?g") {
			t.Fatalf("%s edge query should read from named graphs:\n%s", tt.name, tt.query)
		}
		if strings.Contains(tt.query, "owl:Class") {
			t.Fatalf("%s edge query should no longer require owl:Class declarations:\n%s", tt.name, tt.query)
		}
	}
}

func TestPredicateQueriesUseNamedGraphs(t *testing.T) {
	tests := []struct {
		name  string
		query string
	}{
		{name: "default", query: defaultPredicateQuery(false)},
		{name: "hierarchy", query: hierarchyPredicateQuery(false)},
		{name: "types_only", query: typesOnlyPredicateQuery(false)},
	}

	for _, tt := range tests {
		if !strings.Contains(tt.query, "SELECT DISTINCT ?p") {
			t.Fatalf("%s predicate query should remain distinct:\n%s", tt.name, tt.query)
		}
		if !strings.Contains(tt.query, "GRAPH ?g") {
			t.Fatalf("%s predicate query should read from named graphs:\n%s", tt.name, tt.query)
		}
	}
}
