<commit_before>package mil.nga.geopackage.test.tiles.matrixset;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import junit.framework.TestCase;
import mil.nga.geopackage.GeoPackage;
import mil.nga.geopackage.core.contents.Contents;
import mil.nga.geopackage.core.contents.ContentsDao;
import mil.nga.geopackage.core.contents.ContentsDataType;
import mil.nga.geopackage.core.srs.SpatialReferenceSystem;
import mil.nga.geopackage.core.srs.SpatialReferenceSystemDao;
import mil.nga.geopackage.test.TestUtils;
import mil.nga.geopackage.tiles.matrixset.TileMatrixSet;
import mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao;

import com.j256.ormlite.stmt.DeleteBuilder;
import com.j256.ormlite.stmt.PreparedDelete;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.PreparedUpdate;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.UpdateBuilder;

/**
 * Tile Matrix Set Utility test methods
 * 
 * @author osbornb
 */
public class TileMatrixSetUtils {

	/**
	 * Test read
	 * 
	 * @param geoPackage
	 * @param expectedResults
	 * @throws SQLException
	 */
	public static void testRead(GeoPackage geoPackage, Integer expectedResults)
			throws SQLException {

		TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();
		if (dao.isTableExists()) {
			List<TileMatrixSet> results = dao.queryForAll();
			if (expectedResults != null) {
				TestCase.assertEquals(
						"Unexpected number of tile matrix set rows",
						expectedResults.intValue(), results.size());
			}

			if (!results.isEmpty()) {

				// Verify non nulls
				for (TileMatrixSet result : results) {
					TestCase.assertNotNull(result.getTableName());
					TestCase.assertNotNull(result.getId());
					TestCase.assertNotNull(result.getSrsId());
					TestCase.assertNotNull(result.getMinX());
					TestCase.assertNotNull(result.getMinY());
					TestCase.assertNotNull(result.getMaxX());
					TestCase.assertNotNull(result.getMaxY());

					SpatialReferenceSystem srs = result.getSrs();
					TestCase.assertNotNull(srs);
					TestCase.assertNotNull(srs.getSrsName());
					TestCase.assertNotNull(srs.getSrsId());
					TestCase.assertNotNull(srs.getOrganization());
					TestCase.assertNotNull(srs.getOrganizationCoordsysId());
					TestCase.assertNotNull(srs.getDefinition());

					Contents contents = result.getContents();
					TestCase.assertNotNull(contents);
					TestCase.assertNotNull(contents.getTableName());
					TestCase.assertNotNull(contents.getDataType());
					TestCase.assertNotNull(contents.getLastChange());
				}

				// Choose random contents
				int random = (int) (Math.random() * results.size());
				TileMatrixSet tileMatrixSet = results.get(random);

				// Query by id
				TileMatrixSet queryTileMatrixSet = dao.queryForId(tileMatrixSet
						.getId());
				TestCase.assertNotNull(queryTileMatrixSet);
				TestCase.assertEquals(tileMatrixSet.getId(),
						queryTileMatrixSet.getId());

				// Query for equal
				List<TileMatrixSet> queryTileMatrixSetList = dao.queryForEq(
						TileMatrixSet.COLUMN_SRS_ID, tileMatrixSet.getSrsId());
				TestCase.assertNotNull(queryTileMatrixSetList);
				TestCase.assertTrue(queryTileMatrixSetList.size() >= 1);
				boolean found = false;
				for (TileMatrixSet queryTileMatrixSetValue : queryTileMatrixSetList) {
					TestCase.assertEquals(tileMatrixSet.getSrsId(),
							queryTileMatrixSetValue.getSrsId());
					if (!found) {
						found = tileMatrixSet.getId().equals(
								queryTileMatrixSetValue.getId());
					}
				}
				TestCase.assertTrue(found);

				// Query for field values
				Map<String, Object> fieldValues = new HashMap<String, Object>();
				fieldValues.put(TileMatrixSet.COLUMN_MIN_X,
						tileMatrixSet.getMinX());
				fieldValues.put(TileMatrixSet.COLUMN_MAX_X,
						tileMatrixSet.getMaxX());

				queryTileMatrixSetList = dao.queryForFieldValues(fieldValues);
				TestCase.assertNotNull(queryTileMatrixSetList);
				TestCase.assertTrue(queryTileMatrixSetList.size() >= 1);
				found = false;
				for (TileMatrixSet queryTileMatrixSetValue : queryTileMatrixSetList) {
					TestCase.assertEquals(tileMatrixSet.getMinX(),
							queryTileMatrixSetValue.getMinX());
					TestCase.assertEquals(tileMatrixSet.getMaxX(),
							queryTileMatrixSetValue.getMaxX());<commit_msg>test fix<commit_after>package mil.nga.geopackage.test.tiles.matrixset;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import junit.framework.TestCase;
import mil.nga.geopackage.GeoPackage;
import mil.nga.geopackage.core.contents.Contents;
import mil.nga.geopackage.core.contents.ContentsDao;
import mil.nga.geopackage.core.contents.ContentsDataType;
import mil.nga.geopackage.core.srs.SpatialReferenceSystem;
import mil.nga.geopackage.core.srs.SpatialReferenceSystemDao;
import mil.nga.geopackage.test.TestUtils;
import mil.nga.geopackage.tiles.matrixset.TileMatrixSet;
import mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao;

import com.j256.ormlite.stmt.DeleteBuilder;
import com.j256.ormlite.stmt.PreparedDelete;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.PreparedUpdate;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.UpdateBuilder;

/**
 * Tile Matrix Set Utility test methods
 * 
 * @author osbornb
 */
public class TileMatrixSetUtils {

	/**
	 * Test read
	 * 
	 * @param geoPackage
	 * @param expectedResults
	 * @throws SQLException
	 */
	public static void testRead(GeoPackage geoPackage, Integer expectedResults)
			throws SQLException {

		TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();
		if (dao.isTableExists()) {
			List<TileMatrixSet> results = dao.queryForAll();
			if (expectedResults != null) {
				TestCase.assertEquals(
						"Unexpected number of tile matrix set rows",
						expectedResults.intValue(), results.size());
			}

			if (!results.isEmpty()) {

				// Verify non nulls
				for (TileMatrixSet result : results) {
					TestCase.assertNotNull(result.getTableName());
					TestCase.assertNotNull(result.getId());
					TestCase.assertNotNull(result.getSrsId());
					TestCase.assertNotNull(result.getMinX());
					TestCase.assertNotNull(result.getMinY());
					TestCase.assertNotNull(result.getMaxX());
					TestCase.assertNotNull(result.getMaxY());

					SpatialReferenceSystem srs = result.getSrs();
					TestCase.assertNotNull(srs);
					TestCase.assertNotNull(srs.getSrsName());
					TestCase.assertNotNull(srs.getSrsId());
					TestCase.assertNotNull(srs.getOrganization());
					TestCase.assertNotNull(srs.getOrganizationCoordsysId());
					TestCase.assertNotNull(srs.getDefinition());

					Contents contents = result.getContents();
					TestCase.assertNotNull(contents);
					TestCase.assertNotNull(contents.getTableName());
					TestCase.assertNotNull(contents.getDataType());
					TestCase.assertNotNull(contents.getLastChange());
				}

				// Choose random contents
				int random = (int) (Math.random() * results.size());
				TileMatrixSet tileMatrixSet = results.get(random);

				// Query by id
				TileMatrixSet queryTileMatrixSet = dao.queryForId(tileMatrixSet
						.getId());
				TestCase.assertNotNull(queryTileMatrixSet);
				TestCase.assertEquals(tileMatrixSet.getId(),
						queryTileMatrixSet.getId());

				// Query for equal
				List<TileMatrixSet> queryTileMatrixSetList = dao.queryForEq(
						TileMatrixSet.COLUMN_SRS_ID, tileMatrixSet.getSrsId());
				TestCase.assertNotNull(queryTileMatrixSetList);
				TestCase.assertTrue(queryTileMatrixSetList.size() >= 1);
				boolean found = false;
				for (TileMatrixSet queryTileMatrixSetValue : queryTileMatrixSetList) {
					TestCase.assertEquals(tileMatrixSet.getSrsId(),
							queryTileMatrixSetValue.getSrsId());
					if (!found) {
						found = tileMatrixSet.getId().equals(
								queryTileMatrixSetValue.getId());
					}
				}
				TestCase.assertTrue(found);

				// Query for field values
				Map<String, Object> fieldValues = new HashMap<>();
				fieldValues.put(TileMatrixSet.COLUMN_TABLE_NAME,
						tileMatrixSet.getTableName());
				fieldValues.put(TileMatrixSet.COLUMN_SRS_ID,
						tileMatrixSet.getSrsId());

				queryTileMatrixSetList = dao.queryForFieldValues(fieldValues);
				TestCase.assertNotNull(queryTileMatrixSetList);
				TestCase.assertTrue(queryTileMatrixSetList.size() >= 1);
				found = false;
				for (TileMatrixSet queryTileMatrixSetValue : queryTileMatrixSetList) {
					TestCase.assertEquals(tileMatrixSet.getMinX(),
							queryTileMatrixSetValue.getMinX());
					TestCase.assertEquals(tileMatrixSet.getMaxX(),
							queryTileMatrixSetValue.getMaxX());
{'fraction_non_alphanumeric': 0.11401782613728441, 'fraction_numerical': 0.004630165528417641, 'mean_word_length': 4.499681731381286, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1376203', 'n_tokens_mistral': 3174, 'n_tokens_neox': 2597, 'n_words': 397}