Commit 8cbcac32 authored by Niklas Fors's avatar Niklas Fors
Browse files

Add test cases for directed relations

parent 2795cea7
......@@ -165,7 +165,7 @@ aspect BackendDirectedAPI {
// Get
sb.append(ind(1) + "public java.util.List<" + ofTypeDecl() + "> " + toTypeDecl());
sb.append("." + name() + "() {\n");
sb.append(ind(2) + "ArrayList<List> l = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "ArrayList<" + ofTypeDecl() + "> l = get" + getImplAttributeName() + "();\n");
sb.append(ind(2) + "return l != null ? l : Collections.emptyList();\n");
sb.append(ind(1) + "}\n");
......
/AST/*
/AllBiGen.ast
/AllBiGen.jadd
/AllGen.ast
/AllGen.jadd
......@@ -2,6 +2,10 @@ Root ::= A* B*;
A ::= <Name>;
B ::= <Name>;
rel A.di1 -> B;
rel A.di2? -> B;
rel A.di3* -> B;
rel A.bi1 <-> B.bi1;
rel A.bi2 <-> B.bi2?;
rel A.bi3 <-> B.bi3*;
......
all: compile run
compile:
(cd .. && ant jar)
java -jar ../compiler.jar AllBi.relast --file
java -jar ../tools/jastadd2.jar --package=AST AllBiGen.ast AllBiGen.jadd Utils.jadd
java -jar ../compiler.jar All.relast --file
java -jar ../tools/jastadd2.jar --package=AST AllGen.ast AllGen.jadd Utils.jadd
run:
javac AST/*.java Test.java
java Test
\ No newline at end of file
......@@ -15,6 +15,10 @@ public class Test {
}
public void test() {
testDi1();
testDi2();
testDi3();
testBi1();
testBi2();
testBi3();
......@@ -26,6 +30,87 @@ public class Test {
testBi9();
}
/**
* rel A.di1 -> B;
*/
private void testDi1() {
setup();
a1.setDi1(b2);
a2.setDi1(b1);
assertSame(a1.di1(), b2);
assertSame(a2.di1(), b1);
a2.setDi1(b2);
assertSame(a1.di1(), b2);
assertSame(a2.di1(), b2);
try {
a3.setDi1(null);
check(false, "should throw exception");
} catch (Exception e) {
// OK
}
}
/**
* rel A.di2? -> B;
*/
private void testDi2() {
setup();
a1.setDi2(b2);
a2.setDi2(b1);
assertSame(a1.di2(), b2);
assertSame(a2.di2(), b1);
a2.setDi2(b2);
assertSame(a1.di2(), b2);
assertSame(a2.di2(), b2);
a2.setDi2(null);
assertSame(a1.di2(), b2);
assertNull(a2.di2());
assertTrue(a1.hasDi2());
assertFalse(a2.hasDi2());
assertFalse(a3.hasDi2());
}
/**
* rel A.di3* -> B;
*/
private void testDi3() {
setup();
a1.addToDi3(b1);
a1.addToDi3(b2);
a1.addToDi3(b3);
a2.addToDi3(b2);
assertEquals(a1.di3(), Arrays.asList(b1, b2, b3));
assertEquals(a2.di3(), Arrays.asList(b2));
assertEquals(a3.di3(), Arrays.asList());
a1.addToDi3(b1);
a2.addToDi3(b1);
a2.addToDi3(b2);
assertEquals(a1.di3(), Arrays.asList(b1, b2, b3, b1));
assertEquals(a2.di3(), Arrays.asList(b2, b1, b2));
assertEquals(a3.di3(), Arrays.asList());
a1.removeFromDi3(b1);
a2.removeFromDi3(b2);
assertEquals(a1.di3(), Arrays.asList(b2, b3, b1));
assertEquals(a2.di3(), Arrays.asList(b1, b2));
assertEquals(a3.di3(), Arrays.asList());
}
/**
......@@ -263,6 +348,12 @@ public class Test {
r.addB(b3);
}
private void assertTrue(boolean b) {
check(b, "value should be true (is false)");
}
private void assertFalse(boolean b) {
check(!b, "value should be flase (is true)");
}
private void assertNull(Object obj) {
check(obj == null, "Object not null: " + obj);
}
......
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