Skip to content
Snippets Groups Projects
Commit 95b7f7cd authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

Add checker for in contact and not in contact

parent fa3bb584
No related branches found
No related tags found
No related merge requests found
......@@ -57,7 +57,6 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<!-- wordnet -->
<dependency>
<groupId>edu.mit</groupId>
......
package de.unikoblenz.fgbks.base.utils.boundary.checker;
import static de.unikoblenz.fgbks.base.utils.boundary.BoundType.INCLUSIVE;
import de.unikoblenz.fgbks.base.utils.boundary.AbstractGrowingBoundary;
public class CheckInContact extends AbstractBoundaryCheck<AbstractGrowingBoundary> {
private static final CheckInContact instance = new CheckInContact();
private CheckInContact() {
super();
}
public static CheckInContact getInstance() {
return instance;
}
@Override
public BoundaryCheckType getType() {
return BoundaryCheckType.IS_IN_CONTACT;
}
@Override
public boolean check(AbstractGrowingBoundary b1, AbstractGrowingBoundary b2) {
return checkBounds(b1, b2);
}
public static boolean checkBounds(AbstractGrowingBoundary b1, AbstractGrowingBoundary b2) {
// TODO: check raw types
if (b1.getLowerBound().compareTo(b2.getLowerBound()) <= 0) {
return checkOrdered(b1, b2);
} else {
return checkOrdered(b2, b1);
}
}
private static boolean checkOrdered(AbstractGrowingBoundary b1, AbstractGrowingBoundary b2) {
if (b1.getUpperBound().compareTo(b2.getLowerBound()) > 0) {
return true;
}
if (b1.getUpperBound().compareTo(b2.getLowerBound()) == 0) {
return b1.getUpperBoundType() == INCLUSIVE && b2.getLowerBoundType() == INCLUSIVE;
}
return false;
}
}
package de.unikoblenz.fgbks.base.utils.boundary.checker;
import de.unikoblenz.fgbks.base.utils.boundary.AbstractGrowingBoundary;
public class CheckNotInContact extends AbstractBoundaryCheck<AbstractGrowingBoundary> {
private static final CheckNotInContact instance = new CheckNotInContact();
private CheckNotInContact() {
super();
}
public static CheckNotInContact getInstance() {
return instance;
}
@Override
public BoundaryCheckType getType() {
return BoundaryCheckType.IS_NOT_IN_CONTACT;
}
@Override
public boolean check(AbstractGrowingBoundary b1, AbstractGrowingBoundary b2) {
return !CheckInContact.checkBounds(b1, b2);
}
}
package de.unikoblenz.fgbks.base.utils.boundary.checker;
import static de.unikoblenz.fgbks.core.dmn.domain.vdmn.VTypeRef.DOUBLE;
import static de.unikoblenz.fgbks.core.dmn.domain.vdmn.VTypeRef.INTEGER;
import static de.unikoblenz.fgbks.core.dmn.domain.vdmn.VTypeRef.LONG;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import de.unikoblenz.fgbks.base.utils.boundary.Boundary;
import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VTypeRef;
public class AbstractCheckerTest {
protected BoundaryCheck checker;
protected void doNumCheck(String b1, String b2, boolean expected) {
doCheck(INTEGER, b1, b2, expected);
doCheck(INTEGER, b2, b1, expected);
doCheck(LONG, b1, b2, expected);
doCheck(LONG, b2, b1, expected);
doCheck(DOUBLE, b1, b2, expected);
doCheck(DOUBLE, b2, b1, expected);
}
private void doCheck(VTypeRef type, String b1, String b2, boolean expected) {
doCheck(type.getBoundaryFromText(b1).get(), type.getBoundaryFromText(b2).get(), expected);
}
private void doCheck(Boundary b1, Boundary b2, boolean expected) {
if (expected) {
assertTrue(checker.check(b1, b2), b1.getText() + " / " + b2.getText());
} else {
assertFalse(checker.check(b1, b2), b1.getText() + " / " + b2.getText());
}
}
}
package de.unikoblenz.fgbks.base.utils.boundary.checker;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@QuarkusTest
class CheckInContactTest extends AbstractCheckerTest {
@Test
void check() {
super.checker = CheckInContact.getInstance();
doNumCheck("<1", "<5", true);
doNumCheck(">1", "<5", true);
doNumCheck("<1", ">5", false);
doNumCheck("[1..2]", ">5", false);
doNumCheck("[1..2]", ">2", false);
doNumCheck("[1..2]", "<2", true);
doNumCheck("[1..2]", "<1", false);
doNumCheck("[1..2]", "<=1", true);
doNumCheck("]1..2]", "<=1", false);
doNumCheck("]1..2]", "<1", false);
doNumCheck("[1..2]", "<1", false);
doNumCheck("[1..2]", "[1..2]", true);
doNumCheck("=1", "=1", true);
doNumCheck("[1..3]", "=1", true);
doNumCheck("[1..3]", "=2", true);
doNumCheck("[1..3]", "=3", true);
doNumCheck("[1..3]", "=0", false);
doNumCheck("[1..3]", "=4", false);
doNumCheck("[1..3]", "<=4", true);
}
}
package de.unikoblenz.fgbks.base.utils.boundary.checker;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@QuarkusTest
class CheckNotInContactTest extends AbstractCheckerTest {
@Test
void check() {
super.checker = CheckNotInContact.getInstance();
doNumCheck("<1", "<5", false);
doNumCheck(">1", "<5", false);
doNumCheck("<1", ">5", true);
doNumCheck("[1..2]", ">5", true);
doNumCheck("[1..2]", ">2", true);
doNumCheck("[1..2]", "<2", false);
doNumCheck("[1..2]", "<1", true);
doNumCheck("[1..2]", "<=1", false);
doNumCheck("]1..2]", "<=1", true);
doNumCheck("]1..2]", "<1", true);
doNumCheck("[1..2]", "<1", true);
doNumCheck("[1..2]", "[1..2]", false);
doNumCheck("=1", "=1", false);
doNumCheck("[1..3]", "=1", false);
doNumCheck("[1..3]", "=2", false);
doNumCheck("[1..3]", "=3", false);
doNumCheck("[1..3]", "=0", true);
doNumCheck("[1..3]", "=4", true);
doNumCheck("[1..3]", "<=4", false);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment