Commit c18c2cf5 authored by Evgeny Kusmenko's avatar Evgeny Kusmenko

Merge branch 'new_junit_tests' into 'master'

New JUnit tests

See merge request !27
parents 45b48793 821b76b8
Pipeline #106586 passed with stages
...@@ -37,6 +37,7 @@ public class CNNArchTemplateController { ...@@ -37,6 +37,7 @@ public class CNNArchTemplateController {
private LayerNameCreator nameManager; private LayerNameCreator nameManager;
private ArchitectureSymbol architecture; private ArchitectureSymbol architecture;
private String loss;
//temporary attributes. They are set after calling process() //temporary attributes. They are set after calling process()
private Writer writer; private Writer writer;
...@@ -44,8 +45,6 @@ public class CNNArchTemplateController { ...@@ -44,8 +45,6 @@ public class CNNArchTemplateController {
private Target targetLanguage; private Target targetLanguage;
private ArchitectureElementData dataElement; private ArchitectureElementData dataElement;
public String loss;
public static final String CROSS_ENTROPY = "cross_entropy"; public static final String CROSS_ENTROPY = "cross_entropy";
public static final String EUCLIDEAN = "euclidean"; public static final String EUCLIDEAN = "euclidean";
......
...@@ -22,6 +22,7 @@ package de.monticore.lang.monticar.cnnarch.caffe2generator; ...@@ -22,6 +22,7 @@ package de.monticore.lang.monticar.cnnarch.caffe2generator;
import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.Log;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
import org.apache.commons.cli.ParseException;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -31,6 +32,7 @@ import java.nio.file.Path; ...@@ -31,6 +32,7 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import org.junit.contrib.java.lang.system.Assertion;
import org.junit.contrib.java.lang.system.ExpectedSystemExit; import org.junit.contrib.java.lang.system.ExpectedSystemExit;
import static junit.framework.TestCase.assertTrue; import static junit.framework.TestCase.assertTrue;
...@@ -62,26 +64,33 @@ public class GenerationTest extends AbstractSymtabTest{ ...@@ -62,26 +64,33 @@ public class GenerationTest extends AbstractSymtabTest{
} }
@Test @Test
public void testCifar10Classifier() throws IOException, TemplateException { public void testUnsupportedLayersCifar10Classifier() throws IOException, TemplateException {
Log.getFindings().clear(); Log.getFindings().clear();
String[] args = {"-m", "src/test/resources/valid_tests", "-r", "CifarClassifierNetwork", "-o", "./target/generated-sources-cnnarch/"}; String[] args = {"-m", "src/test/resources/valid_tests", "-r", "CifarClassifierNetwork", "-o", "./target/generated-sources-cnnarch/"};
exit.expectSystemExit(); exit.expectSystemExit();
exit.checkAssertionAfterwards(new Assertion() {
public void checkAssertion() {
assertTrue(Log.getFindings().size() == 2);
}
});
CNNArch2Caffe2Cli.main(args); CNNArch2Caffe2Cli.main(args);
assertTrue(Log.getFindings().size() == 2);
} }
@Test @Test
public void testAlexnetGeneration() throws IOException, TemplateException { public void testUnsupportedLayersAlexnet() throws IOException, TemplateException {
Log.getFindings().clear(); Log.getFindings().clear();
String[] args = {"-m", "src/test/resources/architectures", "-r", "Alexnet", "-o", "./target/generated-sources-cnnarch/"}; String[] args = {"-m", "src/test/resources/architectures", "-r", "Alexnet", "-o", "./target/generated-sources-cnnarch/"};
exit.expectSystemExit(); exit.expectSystemExit();
exit.checkAssertionAfterwards(new Assertion() {
public void checkAssertion() {
assertTrue(Log.getFindings().size() == 2);
}
});
CNNArch2Caffe2Cli.main(args); CNNArch2Caffe2Cli.main(args);
assertTrue(Log.getFindings().size() == 2);
} }
@Test @Test
public void testGeneratorVGG16() throws IOException, TemplateException { public void testGeneratorVGG16Generation() throws IOException, TemplateException {
Log.getFindings().clear(); Log.getFindings().clear();
String[] args = {"-m", "src/test/resources/architectures", "-r", "VGG16", "-o", "./target/generated-sources-cnnarch/"}; String[] args = {"-m", "src/test/resources/architectures", "-r", "VGG16", "-o", "./target/generated-sources-cnnarch/"};
CNNArch2Caffe2Cli.main(args); CNNArch2Caffe2Cli.main(args);
...@@ -102,17 +111,25 @@ public class GenerationTest extends AbstractSymtabTest{ ...@@ -102,17 +111,25 @@ public class GenerationTest extends AbstractSymtabTest{
Log.getFindings().clear(); Log.getFindings().clear();
String[] args = {"-m", "src/test/resources/architectures", "-r", "ThreeInputCNN_M14"}; String[] args = {"-m", "src/test/resources/architectures", "-r", "ThreeInputCNN_M14"};
exit.expectSystemExit(); exit.expectSystemExit();
exit.checkAssertionAfterwards(new Assertion() {
public void checkAssertion() {
assertTrue(Log.getFindings().size() == 2);
}
});
CNNArch2Caffe2Cli.main(args); CNNArch2Caffe2Cli.main(args);
assertTrue(Log.getFindings().size() == 2);
} }
@Test @Test
public void testResNeXtGeneration() throws IOException, TemplateException { public void testUnsupportedLayersResNeXt() throws IOException, TemplateException {
Log.getFindings().clear();; Log.getFindings().clear();;
String[] args = {"-m", "src/test/resources/architectures", "-r", "ResNeXt50"}; String[] args = {"-m", "src/test/resources/architectures", "-r", "ResNeXt50"};
exit.expectSystemExit(); exit.expectSystemExit();
exit.checkAssertionAfterwards(new Assertion() {
public void checkAssertion() {
assertTrue(Log.getFindings().size() == 2);
}
});
CNNArch2Caffe2Cli.main(args); CNNArch2Caffe2Cli.main(args);
assertTrue(Log.getFindings().size() == 2);
} }
@Test @Test
...@@ -190,7 +207,9 @@ public class GenerationTest extends AbstractSymtabTest{ ...@@ -190,7 +207,9 @@ public class GenerationTest extends AbstractSymtabTest{
String rootModelName = "alexnet"; String rootModelName = "alexnet";
CNNArch2Caffe2 generator = new CNNArch2Caffe2(); CNNArch2Caffe2 generator = new CNNArch2Caffe2();
generator.setGenerationTargetPath("./target/generated-sources-cnnarch"); generator.setGenerationTargetPath("./target/generated-sources-cnnarch");
generator.generateCMake(rootModelName); if(generator.isCMakeRequired()){
generator.generateCMake(rootModelName);
}
assertTrue(Log.getFindings().isEmpty()); assertTrue(Log.getFindings().isEmpty());
...@@ -207,4 +226,17 @@ public class GenerationTest extends AbstractSymtabTest{ ...@@ -207,4 +226,17 @@ public class GenerationTest extends AbstractSymtabTest{
"FindArmadillo.cmake")); "FindArmadillo.cmake"));
} }
@Test
public void testWrongArgumentCNNArch2Caffe2Cli() throws ParseException {
Log.getFindings().clear();
String[] args = {"-x", "src/test/resources/architectures", "-y", "LeNet", "-z", "./target/generated-sources-cnnarch/"};
exit.expectSystemExit();
exit.checkAssertionAfterwards(new Assertion() {
public void checkAssertion() {
assertTrue(Log.getFindings().size() == 2);
}
});
CNNArch2Caffe2Cli.main(args);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment