ThemeQueryCatalogExpansionTest.java

/*******************************************************************************
 * Copyright (c) 2025 Eclipse RDF4J contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Distribution License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *******************************************************************************/
// Some portions generated by Codex
package org.eclipse.rdf4j.benchmark.common;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

import org.eclipse.rdf4j.benchmark.rio.util.ThemeDataSetGenerator.Theme;
import org.junit.jupiter.api.Test;

class ThemeQueryCatalogExpansionTest {

	private static final int EXPANDED_QUERY_COUNT = 11;

	@Test
	void eachThemeHasExpandedQueryCount() {
		for (Theme theme : Theme.values()) {
			List<String> queries = ThemeQueryCatalog.queriesFor(theme);
			assertEquals(EXPANDED_QUERY_COUNT, queries.size(),
					"Unexpected query count for theme " + theme);
		}
	}

	@Test
	void socialQueriesIncludeCliqueCycles() {
		List<String> queries = ThemeQueryCatalog.queriesFor(Theme.SOCIAL_MEDIA);
		assertTrue(containsCycle(queries,
				"?a social:follows ?b",
				"?b social:follows ?c",
				"?c social:follows ?a"),
				"Missing 3-clique cycle query");
		assertTrue(containsCycle(queries,
				"?a social:follows ?b",
				"?b social:follows ?c",
				"?c social:follows ?d",
				"?d social:follows ?a"),
				"Missing 4-clique cycle query");
		assertTrue(containsCycle(queries,
				"?a social:follows ?b",
				"?b social:follows ?c",
				"?c social:follows ?d",
				"?d social:follows ?e",
				"?e social:follows ?a"),
				"Missing 5-clique cycle query");
	}

	private static boolean containsCycle(List<String> queries, String... fragments) {
		return queries.stream().anyMatch(query -> {
			for (String fragment : fragments) {
				if (!query.contains(fragment)) {
					return false;
				}
			}
			return true;
		});
	}
}