Commit 4724e969 authored by Alexander Ryndin's avatar Alexander Ryndin
Browse files

simplified test

parent 91c2b0b4
......@@ -6,6 +6,7 @@
package de.monticore.lang.monticar.generator;
import de.monticore.lang.monticar.generator.order.simulator.AbstractSymtab;
import org.junit.Assert;
import java.io.File;
import java.io.IOException;
......@@ -29,7 +30,12 @@ public class AbstractSymtabTest extends AbstractSymtab {
}
public static boolean areBothFilesEqual(File file1, File file2) {
if (!file1.exists() || !file2.exists()) {
if (!file1.exists()) {
Assert.fail("file does not exist: " + file1.getAbsolutePath());
return false;
}
if (!file2.exists()) {
Assert.fail("file does not exist: " + file2.getAbsolutePath());
return false;
}
List<String> lines1;
......@@ -39,18 +45,31 @@ public class AbstractSymtabTest extends AbstractSymtab {
lines2 = Files.readAllLines(file2.toPath());
} catch (IOException e) {
e.printStackTrace();
Assert.fail("IO error: " + e.getMessage());
return false;
}
lines1 = discardEmptyLines(lines1);
lines2 = discardEmptyLines(lines2);
if (lines1.size() != lines2.size()) {
Assert.fail(
"files have different number of lines: "
+ file1.getAbsolutePath()
+ " has " + lines1
+ " lines and " + file2.getAbsolutePath() + " has " + lines2 + " lines"
);
return false;
}
int len = lines1.size();
for (int i = 0; i < len; i++) {
if (!lines1.get(i).equals(lines2.get(i))) {
return false;
}
String l1 = lines1.get(i);
String l2 = lines2.get(i);
Assert.assertEquals("files differ in " + i + " line: "
+ file1.getAbsolutePath()
+ " has " + l1
+ " and " + file2.getAbsolutePath() + " has " + l2,
l1,
l2
);
}
return true;
}
......
......@@ -2,7 +2,6 @@ package de.monticore.lang.monticar.generator;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.cpp.GeneratorCPP;
import de.monticore.lang.monticar.generator.cpp.TestsGeneratorCPP;
import de.monticore.symboltable.Scope;
import org.junit.Test;
......@@ -11,8 +10,8 @@ import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class TestsGenTest extends AbstractSymtabTest {
......@@ -32,20 +31,6 @@ public class TestsGenTest extends AbstractSymtabTest {
generatorCPP.setGenerateTests(true);
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/MySuperAwesomeComponent1/");
List<File> files = generatorCPP.generateFiles(componentSymbol, symtab);
String resPath = "testsgen/MySuperAwesomeComponent1/";
files = files.stream()
.filter(f -> {
// vendor stuff is not really generated
if (f.getName().toLowerCase().equals("catch.hpp")) {
return false;
}
try {
return f.getCanonicalPath().contains(TestsGeneratorCPP.TESTS_DIRECTORY_NAME + File.separator);
} catch (IOException e) {
return false;
}
})
.collect(Collectors.toList());
testFilesAreEqual(files, resPath);
assertEquals(15, files.size());
}
}
#ifndef TESTING_SUBPACKAGE1_MYSUPERAWESOMECOMPONENT1_C11_TEST
#define TESTING_SUBPACKAGE1_MYSUPERAWESOMECOMPONENT1_C11_TEST
#include "catch.hpp"
#include "../testing_subpackage1_mySuperAwesomeComponent1_c11.h"
TEST_CASE("testing.subpackage1.Comp1Test1", "[testing_subpackage1_mySuperAwesomeComponent1_c11]") {
testing_subpackage1_mySuperAwesomeComponent1_c11 component;
component.init();
component.in2 = 0.0;
component.in1 = true;
component.in3 = 0.0;
component.execute();
REQUIRE( component.out2 >= 0.0 );
REQUIRE( component.out2 <= 0.0 );
REQUIRE( component.out3 >= 100.0 );
REQUIRE( component.out3 <= 100.0 );
REQUIRE_FALSE( component.out1 );
component.in2 = 1.0;
component.in1 = false;
component.in3 = 12.3;
component.execute();
REQUIRE( component.out2 >= -1.0 );
REQUIRE( component.out2 <= -1.0 );
REQUIRE( component.out3 >= 87.69 );
REQUIRE( component.out3 <= 87.71000000000001 );
REQUIRE( component.out1 );
component.in2 = 2.0;
component.in1 = true;
component.in3 = 100.0;
component.execute();
REQUIRE( component.out2 >= -2.0 );
REQUIRE( component.out2 <= -2.0 );
REQUIRE( component.out3 >= 0.0 );
REQUIRE( component.out3 <= 0.0 );
REQUIRE_FALSE( component.out1 );
}
TEST_CASE("testing.subpackage1.Comp1Test2", "[testing_subpackage1_mySuperAwesomeComponent1_c11]") {
testing_subpackage1_mySuperAwesomeComponent1_c11 component;
component.init();
component.in2 = 0.0;
component.in1 = false;
component.in3 = 12.3;
component.execute();
REQUIRE( component.out2 >= 0.0 );
REQUIRE( component.out2 <= 0.0 );
REQUIRE( component.out3 >= 87.69 );
REQUIRE( component.out3 <= 87.71000000000001 );
REQUIRE( component.out1 );
component.in2 = -11.0;
component.in1 = true;
component.in3 = 45.6;
component.execute();
REQUIRE( component.out2 >= 10.0 );
REQUIRE( component.out2 <= 12.0 );
REQUIRE( component.out3 >= 54.39 );
REQUIRE( component.out3 <= 54.41 );
REQUIRE_FALSE( component.out1 );
component.in2 = -200.0;
component.in1 = true;
component.in3 = 78.9;
component.execute();
REQUIRE( component.out2 >= 200.0 );
REQUIRE( component.out2 <= 200.0 );
REQUIRE( component.out3 >= 21.09 );
REQUIRE( component.out3 <= 21.110000000000003 );
REQUIRE_FALSE( component.out1 );
}
#endif
#ifndef TESTING_SUBPACKAGE1_MYSUPERAWESOMECOMPONENT1_C21_TEST
#define TESTING_SUBPACKAGE1_MYSUPERAWESOMECOMPONENT1_C21_TEST
#include "catch.hpp"
#include "../testing_subpackage1_mySuperAwesomeComponent1_c21.h"
TEST_CASE("testing.subpackage1.Comp2Test1", "[testing_subpackage1_mySuperAwesomeComponent1_c21]") {
testing_subpackage1_mySuperAwesomeComponent1_c21 component;
component.init();
component.in2 = 10.1;
component.in1 = 12.3;
component.execute();
REQUIRE( component.out1 >= 59.6 );
REQUIRE( component.out1 <= 59.800000000000004 );
component.in2 = 12.1;
component.in1 = 45.6;
component.execute();
REQUIRE( component.out1 >= 93.30000000000001 );
REQUIRE( component.out1 <= 93.5 );
component.in2 = 14.1;
component.in1 = 78.9;
component.execute();
REQUIRE( component.out1 >= 96.80000000000001 );
REQUIRE( component.out1 <= 97.0 );
}
TEST_CASE("testing.subpackage1.Comp2Test3", "[testing_subpackage1_mySuperAwesomeComponent1_c21]") {
testing_subpackage1_mySuperAwesomeComponent1_c21 component;
component.init();
component.in2 = 6.0;
component.in1 = 1.0;
component.execute();
REQUIRE( component.out1 >= 97.10000000000001 );
REQUIRE( component.out1 <= 97.3 );
component.in2 = 7.0;
component.in1 = 2.0;
component.execute();
REQUIRE( component.out1 >= 92.30000000000001 );
REQUIRE( component.out1 <= 92.5 );
component.in2 = 8.0;
component.in1 = 3.0;
component.execute();
REQUIRE( component.out1 >= 87.5 );
REQUIRE( component.out1 <= 87.69999999999999 );
component.in2 = 9.0;
component.in1 = 4.0;
component.execute();
REQUIRE( component.out1 >= 83.4 );
REQUIRE( component.out1 <= 83.6 );
component.in2 = 1.0;
component.in1 = 5.0;
component.execute();
REQUIRE( component.out1 >= 96.0 );
REQUIRE( component.out1 <= 96.19999999999999 );
}
TEST_CASE("testing.subpackage1.Comp2Test2", "[testing_subpackage1_mySuperAwesomeComponent1_c21]") {
testing_subpackage1_mySuperAwesomeComponent1_c21 component;
component.init();
component.in2 = 1.1;
component.in1 = 1.1;
component.execute();
REQUIRE( component.out1 >= 49.9 );
REQUIRE( component.out1 <= 50.1 );
}
#endif
#ifndef TESTING_SUBPACKAGE1_MYSUPERAWESOMECOMPONENT1_TEST
#define TESTING_SUBPACKAGE1_MYSUPERAWESOMECOMPONENT1_TEST
#include "catch.hpp"
#include "../testing_subpackage1_mySuperAwesomeComponent1.h"
TEST_CASE("testing.subpackage1.MySuperAwesomeComponent1", "[testing_subpackage1_mySuperAwesomeComponent1]") {
testing_subpackage1_mySuperAwesomeComponent1 component;
component.init();
component.in2 = 0.0;
component.in1 = true;
component.in3 = 0.0;
component.execute();
REQUIRE( component.out2 >= 0.0 );
REQUIRE( component.out2 <= 0.0 );
REQUIRE( component.out3 >= 100.0 );
REQUIRE( component.out3 <= 100.0 );
REQUIRE( component.out4 >= 99.9 );
REQUIRE( component.out4 <= 100.1 );
REQUIRE_FALSE( component.out1 );
component.in2 = 1.0;
component.in1 = false;
component.in3 = 12.3;
component.execute();
REQUIRE( component.out2 >= -1.0 );
REQUIRE( component.out2 <= -1.0 );
REQUIRE( component.out3 >= 87.69 );
REQUIRE( component.out3 <= 87.71000000000001 );
REQUIRE( component.out4 >= 97.9 );
REQUIRE( component.out4 <= 98.1 );
REQUIRE( component.out1 );
component.in2 = 2.0;
component.in1 = true;
component.in3 = 100.0;
component.execute();
REQUIRE( component.out2 >= -2.0 );
REQUIRE( component.out2 <= -2.0 );
REQUIRE( component.out3 >= 0.0 );
REQUIRE( component.out3 <= 0.0 );
REQUIRE( component.out4 >= 99.9 );
REQUIRE( component.out4 <= 100.1 );
REQUIRE_FALSE( component.out1 );
}
#endif
#ifndef TESTS_MAIN
#define TESTS_MAIN
#include "../Helper.h"
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
int main(int argc, char* argv[]) {
Helper::init();
Catch::Session session;
int returnCode = session.applyCommandLine(argc, argv);
if (returnCode != 0) {
octave_quit();
return returnCode;
}
int numFailed = session.run();
octave_quit();
return numFailed;
}
#include "testing_subpackage1_mySuperAwesomeComponent1_test.hpp"
#include "testing_subpackage1_mySuperAwesomeComponent1_c11_test.hpp"
#include "testing_subpackage1_mySuperAwesomeComponent1_c21_test.hpp"
#endif
Supports Markdown
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