
test.it.unimi.dsi.law.io.tool.Text2DataData2TextTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of law Show documentation
Show all versions of law Show documentation
The software distributed by the Laboratory for Web Algorithmics (LAW).
The newest version!
package it.unimi.dsi.law.io.tool;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
import com.google.common.io.Files;
import com.martiansoftware.jsap.JSAPException;
public class Text2DataData2TextTest {
@Test
public void testInt(){
assertTrue(testCore("INT", "10000\n", "10000\n"));
assertTrue(testCore("INT", "-10000\n12\n", "-10000\n12\n"));
assertTrue(testCore("INT", "10000\n" + Integer.MAX_VALUE + "\n12\n", "10000\n" + Integer.MAX_VALUE + "\n12\n"));
assertTrue(testCore("INT", "10000\n" + Integer.MIN_VALUE + "\n12\n", "10000\n" + Integer.MIN_VALUE + "\n12\n"));
}
@Test
public void testByte(){
assertTrue(testCore("BYTE", "0\n", "0\n"));
assertTrue(testCore("BYTE", "1\n", "1\n"));
assertTrue(testCore("BYTE", "0111\n", "73\n"));
assertTrue(testCore("BYTE", "011\n110\n", "9\n110\n"));
}
@Test
public void testShort(){
assertTrue(testCore("SHORT", "1\n", "1\n"));
assertTrue(testCore("SHORT", "15\n", "15\n"));
assertTrue(testCore("SHORT", "-12\n"+Short.MAX_VALUE+"\n", "-12\n"+Short.MAX_VALUE+"\n"));
assertTrue(testCore("SHORT", "-12\n"+Short.MIN_VALUE+"\n17\n", "-12\n"+Short.MIN_VALUE+"\n17\n"));
}
@Test
public void testLong(){
assertTrue(testCore("LONG", "45678\n45678\n45678\n", "45678\n45678\n45678\n"));
assertTrue(testCore("LONG", "45678\n"+Long.MIN_VALUE+"\n", "45678\n"+Long.MIN_VALUE+"\n"));
assertTrue(testCore("LONG", Long.MAX_VALUE+"\n", Long.MAX_VALUE+"\n"));
}
@Test
public void testFloat(){
assertTrue(testCore("FLOAT", "32\n", "32.0\n"));
assertTrue(testCore("FLOAT", "32.0\n", "32.0\n"));
assertTrue(testCore("FLOAT", "1e+05\n", "100000.0\n"));
assertTrue(testCore("FLOAT", "100000.0\n100000\n", "100000.0\n100000.0\n"));
assertTrue(testCore("FLOAT", "100000.0\n"+Float.MAX_VALUE+"\n", "100000.0\n" + Float.MAX_VALUE + "\n"));
assertTrue(testCore("FLOAT", "100000.0\n"+Float.MIN_VALUE+"\n", "100000.0\n" + Float.MIN_VALUE + "\n"));
}
@Test
public void testDouble(){
assertTrue(testCore("DOUBLE", "0.45\n", "0.45\n"));
assertTrue(testCore("DOUBLE", "1e+05\n", "100000.0\n"));
assertTrue(testCore("DOUBLE", "100000.0\n"+Double.MAX_VALUE+"\n", "100000.0\n" + Double.MAX_VALUE + "\n"));
assertTrue(testCore("DOUBLE", "100000.0\n"+Double.MIN_VALUE+"\n", "100000.0\n" + Double.MIN_VALUE + "\n"));
}
private boolean testCore(String type, String text, String textExpected){
try{
File f1 = new File(type + "InFile.txt");
File f2 = new File(type + "OutFile.txt");
File f3 = new File(type + "InFile2.txt");
if (f1.exists() || f2.exists() || f3.exists()) {
System.err.println("Unable to perform test " + this.getClass().toString() + " because of existing temp files");
return false;
}
Files.asCharSink(f1, StandardCharsets.UTF_8).write(text);
Text2DataOutput.main(("-t " + type + " " + type + "InFile.txt" + " " + type + "OutFile.txt").split(" "));
DataInput2Text.main(("-t " + type + " " + type + "OutFile.txt" + " " + type + "InFile2.txt").split(" "));
boolean rst = textExpected.equals(Files.asCharSource(f3, StandardCharsets.UTF_8).read());
//boolean rst = FileUtils.contentEquals(f1, f3);
f1.delete();
f2.delete();
f3.delete();
return rst;
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (JSAPException e) {
e.printStackTrace();
return false;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy