<commit_before>package com.treetank.service.xml.xpath.xmark;

import java.io.File;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.treetank.TestHelper;
import com.treetank.TestHelper.PATHS;
import com.treetank.api.IDatabase;
import com.treetank.api.IReadTransaction;
import com.treetank.api.ISession;
import com.treetank.exception.TreetankException;
import com.treetank.service.xml.shredder.XMLShredder;
import com.treetank.service.xml.xpath.XPathAxis;
import com.treetank.service.xml.xpath.XPathStringChecker;

/**
 * This class performs tests for XQuery functions used for XMark bench test and
 * XPathMark bench test.
 * 
 * @author <NAME>, Konstanz University
 * 
 */
public class FunctionsXMarkTest {

	final XMarkBenchQueries xmbq = new XMarkBenchQueries();

	private static final String XMLFILE = "10mb.xml";

	private static final String XML = "src" + File.separator + "test"
			+ File.separator + "resources" + File.separator + XMLFILE;

	private IDatabase database = null;
	private ISession session = null;
	private IReadTransaction rtx = null;

	@Before
	public void setUp() {
		try {
			TestHelper.deleteEverything();
			XMLShredder.main(XML, PATHS.PATH1.getFile().getAbsolutePath());
			database = TestHelper.getDatabase(PATHS.PATH1.getFile());
			session = database.getSession();
			rtx = session.beginReadTransaction();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Test function string().
	 */
	@Test
	public void testString() {
		final String query = "fn:string(/site/people/person[@id=\"person3\"]/name)";
		final String result = "Limor Simone";
		XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
				new String[] { result });
	}

	/**
	 * Test comment.
	 */
	@Test
	public void testComment() {
		final String query = "2 (: this is a comment :)";
		final String result = "2";
		XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
				new String[] { result });
	}

	/**
	 * Test function node().
	 */
	@Test
	public void testNode() {
		final String query = "for $b in /site/people/person[@id=\"person1\"] return $b/name/node()";
		final String result = "<NAME>";
		XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
				new String[] { result });
	}

	/**
	 * Test function text().
	 */
	@Test
	public void testText() {
		final String query = "for $b in /site/people/person[@id=\"person0\"] return $b/name/text()";
		final String result = "<NAME>";
		XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
				new String[] { result });
	}

	/**
	 * Test function count().
	 */
	@Test
	public void testCount() {
		final String query = "fn:count(for $i in /site/closed_auctions/closed_auction[price/text() >= 40] return $i/price)";
		final String result = "670";
		XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
				new String[] { result });
	}

	// /**
	// * Test function position().
	// */
	// @Test
	// public void testPosition() {
	// final String query =
	// "/site/open_auctions/open_auction/bidder/increase/position()=1";
	// final String result = "true";
	// XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
	// new String[] { result });
	// }

	// /**
	// * Test function not().
	// */
	// @Test
	// public void testNot() {
	// final String query =
	// "/site/people/person[not(homepage)][@id=\"person1\"]/name/text()";
	// final String result = "<name><NAME></name>";
	// XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),<commit_msg>Query of position() test edited.<commit_after>package com.treetank.service.xml.xpath.xmark;

import java.io.File;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.treetank.TestHelper;
import com.treetank.TestHelper.PATHS;
import com.treetank.api.IDatabase;
import com.treetank.api.IReadTransaction;
import com.treetank.api.ISession;
import com.treetank.exception.TreetankException;
import com.treetank.service.xml.shredder.XMLShredder;
import com.treetank.service.xml.xpath.XPathAxis;
import com.treetank.service.xml.xpath.XPathStringChecker;

/**
 * This class performs tests for XQuery functions used for XMark bench test and
 * XPathMark bench test.
 * 
 * @author <NAME>, Konstanz University
 * 
 */
public class FunctionsXMarkTest {

	final XMarkBenchQueries xmbq = new XMarkBenchQueries();

	private static final String XMLFILE = "10mb.xml";

	private static final String XML = "src" + File.separator + "test"
			+ File.separator + "resources" + File.separator + XMLFILE;

	private IDatabase database = null;
	private ISession session = null;
	private IReadTransaction rtx = null;

	@Before
	public void setUp() {
		try {
			TestHelper.deleteEverything();
			XMLShredder.main(XML, PATHS.PATH1.getFile().getAbsolutePath());
			database = TestHelper.getDatabase(PATHS.PATH1.getFile());
			session = database.getSession();
			rtx = session.beginReadTransaction();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Test function string().
	 */
	@Test
	public void testString() {
		final String query = "fn:string(/site/people/person[@id=\"person3\"]/name)";
		final String result = "<NAME>";
		XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
				new String[] { result });
	}

	/**
	 * Test comment.
	 */
	@Test
	public void testComment() {
		final String query = "2 (: this is a comment :)";
		final String result = "2";
		XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
				new String[] { result });
	}

	/**
	 * Test function node().
	 */
	@Test
	public void testNode() {
		final String query = "for $b in /site/people/person[@id=\"person1\"] return $b/name/node()";
		final String result = "<NAME>";
		XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
				new String[] { result });
	}

	/**
	 * Test function text().
	 */
	@Test
	public void testText() {
		final String query = "for $b in /site/people/person[@id=\"person0\"] return $b/name/text()";
		final String result = "<NAME>";
		XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
				new String[] { result });
	}

	/**
	 * Test function count().
	 */
	@Test
	public void testCount() {
		final String query = "fn:count(for $i in /site/closed_auctions/closed_auction[price/text() >= 40] return $i/price)";
		final String result = "670";
		XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
				new String[] { result });
	}

	// /**
	// * Test function position().
	// */
	// @Test
	// public void testPosition() {
	// final String query =
	// "/site/open_auctions/open_auction/bidder/increase[position()=1]";
	// final String result = "<increase>10.50</increase>";
	// XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
	// new String[] { result });
	// }

	// /**
	// * Test function not().
	// */
	// @Test
	// public void testNot() {
	// final String query =
	// "/site/people/person[not(homepage)][@id=\"person1\"]/name/text()";
	// final String result = "<name><NAME></name>";
	// XPathStringChecker.testIAxisConventions(new XPathAxis(rtx, query),
{'fraction_non_alphanumeric': 0.15295774647887325, 'fraction_numerical': 0.0050704225352112674, 'mean_word_length': 3.917590027700831, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '2021054', 'n_tokens_mistral': 2510, 'n_tokens_neox': 2363, 'n_words': 538}