Skip to content

Commit

Permalink
#14 : added test for PPM/PGM files
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrián González Sieira committed Nov 7, 2018
1 parent a5c427d commit c364783
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.io.*;
import java.util.Scanner;

public class PPMFileReader {
public class MapFileReader {

private String format;
private int[][][] pixels;
Expand All @@ -34,7 +34,7 @@ public class PPMFileReader {
* @throws {@link FileNotFoundException} when the specified path does not exist
* @throws {@link IOException} when an I/O error occurs
*/
public PPMFileReader(String path) throws FileNotFoundException, IOException{
public MapFileReader(String path) throws FileNotFoundException, IOException{
//instantiate new reader to fill the information of the file
FileInputStream inputStream = new FileInputStream(path);
Scanner scanner = new Scanner(inputStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

import es.usc.citius.lab.joctomap.util.PPMFileReaderTest;
import es.usc.citius.lab.joctomap.util.MapFileReaderTest;

/**
* Order the execution of all java tests in the library.
Expand All @@ -29,7 +29,7 @@
*/
@RunWith(Suite.class)
@SuiteClasses({
PPMFileReaderTest.class,
MapFileReaderTest.class,
AdjacencyMapTest.class
})
public class JavaTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package es.usc.citius.lab.joctomap.util;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

import static org.junit.Assert.*;

public class MapFileFormatReaderTest {

private MapFileReader readerPPM1;
private MapFileReader readerPPM2;
private MapFileReader readerPGM1;
private MapFileReader readerPGM2;

@Test
public void test01_readPGM() throws IOException, URISyntaxException{
this.readerPPM1 = new MapFileReader(new File(MapFileReaderTest.class.getClassLoader().getResource("ecmr_ascii.ppm").toURI()).getAbsolutePath());
this.readerPPM2 = new MapFileReader(new File(MapFileReaderTest.class.getClassLoader().getResource("ecmr_binary.ppm").toURI()).getAbsolutePath());
assertEquals(this.readerPPM1.getSizeX(), this.readerPPM2.getSizeX());
assertEquals(this.readerPPM1.getSizeY(), this.readerPPM2.getSizeY());
assertEquals(this.readerPPM1.getMaxValue(), this.readerPPM2.getMaxValue());
assertEquals(this.readerPPM1.getPixels().length, this.readerPPM1.getPixels().length);
for(int i = 0; i < this.readerPPM1.getPixels().length; i++){
assertEquals(this.readerPPM1.getPixels().length, this.readerPPM2.getPixels().length);
for(int j = 0; j < this.readerPPM1.getPixels()[i].length; j++){
assertEquals(this.readerPPM1.getPixels()[i][j][0], this.readerPPM2.getPixels()[i][j][0]);
assertEquals(this.readerPPM1.getPixels()[i][j][1], this.readerPPM2.getPixels()[i][j][1]);
assertEquals(this.readerPPM1.getPixels()[i][j][2], this.readerPPM2.getPixels()[i][j][2]);
}
}
}

@Test
public void test03_readPPM() throws IOException, URISyntaxException{
this.readerPGM1 = new MapFileReader(new File(MapFileReaderTest.class.getClassLoader().getResource("ecmr_ascii.pgm").toURI()).getAbsolutePath());
this.readerPGM2 = new MapFileReader(new File(MapFileReaderTest.class.getClassLoader().getResource("ecmr_binary.pgm").toURI()).getAbsolutePath());
assertEquals(this.readerPGM1.getSizeX(), this.readerPGM2.getSizeX());
assertEquals(this.readerPGM1.getSizeY(), this.readerPGM2.getSizeY());
assertEquals(this.readerPGM1.getMaxValue(), this.readerPGM2.getMaxValue());
assertEquals(this.readerPGM1.getPixels().length, this.readerPGM1.getPixels().length);
for(int i = 0; i < this.readerPGM1.getPixels().length; i++){
assertEquals(this.readerPGM1.getPixels().length, this.readerPGM2.getPixels().length);
for(int j = 0; j < this.readerPGM1.getPixels()[i].length; j++){
assertEquals(this.readerPGM1.getPixels()[i][j][0], this.readerPGM2.getPixels()[i][j][0]);
assertEquals(this.readerPGM1.getPixels()[i][j][1], this.readerPGM2.getPixels()[i][j][1]);
assertEquals(this.readerPGM1.getPixels()[i][j][2], this.readerPGM2.getPixels()[i][j][2]);
}
}
}

@Test
public void test05_compareFormats() throws IOException, URISyntaxException{
this.readerPGM1 = new MapFileReader(new File(MapFileReaderTest.class.getClassLoader().getResource("ecmr_ascii.pgm").toURI()).getAbsolutePath());
this.readerPPM1 = new MapFileReader(new File(MapFileReaderTest.class.getClassLoader().getResource("ecmr_ascii.ppm").toURI()).getAbsolutePath());
assertEquals(this.readerPGM1.getSizeX(), this.readerPPM1.getSizeX());
assertEquals(this.readerPGM1.getSizeY(), this.readerPPM1.getSizeY());
assertEquals(this.readerPGM1.getMaxValue(), this.readerPPM1.getMaxValue());
assertEquals(this.readerPGM1.getPixels().length, this.readerPGM1.getPixels().length);
for(int i = 0; i < this.readerPGM1.getPixels().length; i++){
assertEquals(this.readerPGM1.getPixels().length, this.readerPPM1.getPixels().length);
for(int j = 0; j < this.readerPGM1.getPixels()[i].length; j++){
assertEquals(this.readerPGM1.getPixels()[i][j][0], this.readerPPM1.getPixels()[i][j][0]);
assertEquals(this.readerPGM1.getPixels()[i][j][1], this.readerPPM1.getPixels()[i][j][1]);
assertEquals(this.readerPGM1.getPixels()[i][j][2], this.readerPPM1.getPixels()[i][j][2]);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.IOException;
import java.net.URISyntaxException;

import org.junit.BeforeClass;
import org.junit.Test;

/**
Expand All @@ -31,19 +30,19 @@
*
* @author Adrián González Sieira {@literal <[email protected]>}
*/
public class PPMFileReaderTest {
public class MapFileReaderTest {

private PPMFileReader reader;
/**
private MapFileReader reader;

/**
* Constructor which loads a resource
*
* @throws FileNotFoundException if file not found
* @throws IOException if I/O error occurs
* @throws URISyntaxException if URI bad formatted
*/
public PPMFileReaderTest() throws IOException, URISyntaxException{
this.reader = new PPMFileReader(new File(PPMFileReaderTest.class.getClassLoader().getResource("ecmr.ppm").toURI()).getAbsolutePath());
public MapFileReaderTest() throws IOException, URISyntaxException{
this.reader = new MapFileReader(new File(MapFileReaderTest.class.getClassLoader().getResource("ecmr_ascii.ppm").toURI()).getAbsolutePath());
}

/**
Expand Down

0 comments on commit c364783

Please sign in to comment.