Skip to content
This repository was archived by the owner on Mar 2, 2020. It is now read-only.

Ceg benchmark german #473

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,39 @@ public class ModelGenerationTestBase extends EmfRestTest {
private Predicate<JSONObject> MATCHES_VAR_COND(String var, String cond, String type) {
return (obj -> obj.getString(ECLASS).equals(CEGNode.class.getSimpleName())
&& obj.getString(RequirementsPackage.Literals.CEG_NODE__TYPE.getName()).equals(type)
&& (obj.getString(RequirementsPackage.Literals.CEG_NODE__VARIABLE.getName())).toLowerCase()
.equals(var.toLowerCase())
&& (obj.getString(RequirementsPackage.Literals.CEG_NODE__CONDITION.getName())).toLowerCase()
.equals(cond.toLowerCase()));
&& checkStringEquality(obj.getString(RequirementsPackage.Literals.CEG_NODE__VARIABLE.getName()), var)
&& checkStringEquality(obj.getString(RequirementsPackage.Literals.CEG_NODE__CONDITION.getName()), cond));
}

private Predicate<JSONObject> MATCHES_ID_VAR_COND(String id, String var, String cond) {
return (obj -> obj.getString(ECLASS).equals(CEGNode.class.getSimpleName())
&& obj.getString(BasePackage.Literals.IID__ID.getName()).equals(id)
&& (obj.getString(RequirementsPackage.Literals.CEG_NODE__VARIABLE.getName())).toLowerCase()
.equals(var.toLowerCase())
&& (obj.getString(RequirementsPackage.Literals.CEG_NODE__CONDITION.getName())).toLowerCase()
.equals(cond.toLowerCase()));
&& checkStringEquality(obj.getString(RequirementsPackage.Literals.CEG_NODE__VARIABLE.getName()), var)
&& checkStringEquality(obj.getString(RequirementsPackage.Literals.CEG_NODE__CONDITION.getName()), cond));
}


/**
* Check if two strings contain the same words. Order and case are not relevant
* @param s1
* @param s2
* @return
*/
private boolean checkStringEquality(String s1, String s2) {
Copy link
Owner

@junkerm junkerm Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems overly complex due to the many splits and replaces of differnt kinds of whitspace. How about:

  1. split strings with regex e.g. using \s* (any whitespace, any number of times)
  2. Add all non empty parts into a set
  3. Compare sets using equals

Additionally: I would opt to crate a class "TextUtit" in specmate-common and move the method there as a static method. I guess we can move more such methods there over time.

if(s1.equalsIgnoreCase(s2)) {
return true;
}
String s1Lower = s1.toLowerCase();
s1Lower = " " + s1Lower.replace(" ", " ") + " ";
String[] stringArray = s2.toLowerCase().split(" ");
for (String string : stringArray) {
if(!s1Lower.contains(string)) {
return false;
}
s1Lower= s1Lower.replace(" " + string + " ", "");
}
s1Lower= s1Lower.replace(" ", "");
return s1Lower.equals("");
}

public ModelGenerationTestBase() throws Exception {
Expand All @@ -63,7 +83,10 @@ protected void checkResultingModel(JSONArray generated, CEGModel model) {
nodes += "[" + item.get("variable") + " ; ";
}
if (item.keySet().contains("condition")) {
nodes += item.get("condition") + "],";
nodes += item.get("condition") + " ; ";
}
if (item.keySet().contains("type")) {
nodes += item.get("type") + "],";
}
}

Expand All @@ -79,7 +102,7 @@ protected void checkResultingModel(JSONArray generated, CEGModel model) {
MATCHES_VAR_COND(node.getVariable(), node.getCondition(), node.getType().getLiteral())));

Assert.assertTrue("Node with variable \"" + node.getVariable() + "\" and condition \"" + node.getCondition()
+ "\" not found. Nodes found: " + nodes, matched);
+ "\" and type \""+ node.getType() + "\" not found. Nodes found: " + nodes, matched);
}

// Verify connections
Expand Down
Loading