![JAR search and dependency download from the Maven repository](/logo.png)
test.it.unimi.dsi.big.mg4j.Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mg4j-big Show documentation
Show all versions of mg4j-big Show documentation
MG4J (Managing Gigabytes for Java) is a free full-text search engine for large document collections written in Java. The big version is a fork of the original MG4J that can handle more than 2^31 terms and documents.
The newest version!
package it.unimi.dsi.big.mg4j;
/*
* MG4J: Managing Gigabytes for Java (big)
*
* Copyright (C) 2005-2011 Sebastiano Vigna
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see .
*
*/
import java.io.File;
import org.junit.Assert;
/** A static container of utility methods for test cases. */
public final class Util {
/** The property specifying the data directory. */
public static final String DATA_DIR = " it.unimi.dsi.big.mg4j.data";
/** Cannot be instantiated. */
private Util() {}
/** Returns a derelativised version of the given filename.
*
* The general data directory must be specified in the
* property it.unimi.dsi.law.data. The directory
* must contain a test subdirectory (in which
* name
will be searched for).
*
*
If name
starts with a slash, it will
* be derelativised w.r.t. the directory test
* in it.unimi.dsi.law.data. Otherwise,
* the package name (with dots replaced by directory separator)
* will be used additionally.
*
*
This class will directly {@link org.junit.Assert#fail()}
* the current test if the property is not defined. It will
* return null
if it.unimi.dsi.law.data
* is the empty string. Thus, you should start your tests as follows:
*
*
* String filename = Util.getTestFile( ... );
* if ( filename == null ) return;
*
*
* @param self the object performing the derelativisation.
* @param name a filename (to be found in the test data directory).
* @return the derelativised filename, or null
* if it.unimi.dsi.law.data is not set.
*/
public static String getTestFile( final Object self, final String name ) {
final String dataDirName = System.getProperty( DATA_DIR );
if ( dataDirName == null ) Assert.fail( DATA_DIR + " is not defined" );
else if ( dataDirName.length() == 0 ) return null;
File testDir = new File( dataDirName, "test" );
if ( name.charAt( 0 ) != '/' ) {
final String[] piece = self.getClass().getName().split( "\\." );
File actualDir = testDir;
// Note that we skip "test".
for( int i = 1; i < piece.length - 1; i++ ) actualDir = new File( actualDir, piece[ i ] );
testDir = actualDir;
}
return new File( testDir, name ).toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy