Added tests for all relation types
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
index 24bbd82..0b0a901 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/RelationSpans.java
@@ -1,7 +1,6 @@
 package de.ids_mannheim.korap.query.spans;
 
 import java.io.IOException;
-import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -10,7 +9,6 @@
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermContext;
-import org.apache.lucene.search.spans.SpanTermQuery;
 import org.apache.lucene.search.spans.Spans;
 import org.apache.lucene.search.spans.TermSpans;
 import org.apache.lucene.util.Bits;
@@ -19,7 +17,6 @@
 import org.slf4j.LoggerFactory;
 
 import de.ids_mannheim.korap.query.SpanRelationQuery;
-import de.ids_mannheim.korap.query.spans.ElementSpans.CandidateElementSpans;
 
 /**	Enumeration of spans denoting relations between two tokens/elements. The start and end of 
  * 	a RelationSpan always denote the start and end of the source token/element.
@@ -28,7 +25,7 @@
  * 	1. Token to token relation (1 int & 1 short, length: 6) 
  * 	2. Token to span (2 int & 1 short, length: 10)
  * 	3. Span to token (int, byte, int, short, length: 11)
- * 	4. Span to Span (3 int & 1 short, length: 13) 
+ * 	4. Span to Span (3 int & 1 short, length: 14) 
  * 	
  * 	Every integer value denotes the start/end position of the start/target of a relation, 
  * 	in this format:	(sourceEndPos?, startTargetPos, endTargetPos?). The end position of a token is 
@@ -63,6 +60,11 @@
 
 	@Override
 	public boolean next() throws IOException {
+		isStartEnumeration=false;
+		return advance();
+	}
+	
+	private boolean advance() throws IOException{
 		while(hasMoreSpans || !candidateList.isEmpty()){
 			if (!candidateList.isEmpty()){
 				CandidateRelationSpan cs = candidateList.get(0);
@@ -110,7 +112,7 @@
 			case 6: // Token to token
 				i = PayloadReader.readInteger(payloadBytesRef,0);
 				cs.setTargetStart(i);
-				cs.setTargetEnd(i);
+				cs.setTargetEnd(i+1);
 				break;
 	
 			case 10: // Token to span
@@ -122,10 +124,10 @@
 				cs.setEnd(PayloadReader.readInteger(payloadBytesRef,0));
 				i = PayloadReader.readInteger(payloadBytesRef,5);
 				cs.setTargetStart(i);
-				cs.setTargetEnd(i);
+				cs.setTargetEnd(i+1);
 				break;
 			
-			case 13: // Span to span
+			case 14: // Span to span
 				cs.setEnd(PayloadReader.readInteger(payloadBytesRef,0));
 				cs.setTargetStart(PayloadReader.readInteger(payloadBytesRef,4));
 				cs.setTargetEnd(PayloadReader.readInteger(payloadBytesRef,8));
@@ -136,15 +138,22 @@
 	}
 
 	@Override
-	public boolean skipTo(int arg0) throws IOException {
-		// TODO Auto-generated method stub
-		return false;
+	public boolean skipTo(int target) throws IOException {
+		if (hasMoreSpans && (firstSpans.doc() < target)){
+  			if (!firstSpans.skipTo(target)){
+  				candidateList.clear();
+  				return false;
+  			}
+  		}		
+		setCandidateList();
+		matchPayload.clear();
+		isStartEnumeration=false;
+		return advance();	
 	}
 	
 	@Override
 	public long cost() {
-		// TODO Auto-generated method stub
-		return 0;
+		return firstSpans.cost();
 	}
 
 	public short getRelationId() {
@@ -179,12 +188,6 @@
 		public CandidateRelationSpan(Spans span) throws IOException{
 			super(span);
 		}
-		
-		/*public CandidateRelationSpan(Spans span, int targetStart, int targetEnd) throws IOException{
-			super(span);
-			setTargetStart(targetStart);
-			setTargetEnd(targetEnd);
-		}*/
 
 		@Override
 		public int compareTo(CandidateSpan o) {
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
index 4bbec84..cb7be66 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
@@ -1,5 +1,7 @@
 package de.ids_mannheim.korap.index;
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.IOException;
 
 import org.apache.lucene.index.Term;
@@ -62,28 +64,106 @@
         fd.addString("ID", "doc-0");
         fd.addTV("base",
             "text",             
-            "[(0-1)s:c|_1#0-1|>:xip/syntax-dep_rel$<i>7<s>1]" +
-            "[(1-2)s:e|_2#1-2|<:xip/syntax-dep_rel$<i>10<s>1|>:xip/syntax-dep_rel$<i>5<s>1]" +             
+            "[(0-1)s:c|_1#0-1|>:xip/syntax-dep_rel$<i>6<s>1]" +
+            "[(1-2)s:e|_2#1-2|<:xip/syntax-dep_rel$<i>9<s>1|>:xip/syntax-dep_rel$<i>4<s>1]" +             
             "[(2-3)s:c|_3#2-3]" +
-            "[(3-4)s:c|s:b|_4#3-4|<:xip/syntax-dep_rel$<i>10<s>1]" + 
-            "[(4-5)s:e|s:d|_5#4-5|<:xip/syntax-dep_rel$<i>2<s>1]" +
+            "[(3-4)s:c|s:b|_4#3-4|<:xip/syntax-dep_rel$<i>9<s>1]" + 
+            "[(4-5)s:e|s:d|_5#4-5|<:xip/syntax-dep_rel$<i>1<s>1]" +
             "[(5-6)s:c|_6#5-6]" +
             "[(6-7)s:d|_7#6-7|<:xip/syntax-dep_rel$<i>1<s>1]" +
             "[(7-8)s:e|_8#7-8]" + 
             "[(8-9)s:e|s:b|_9#8-9]" + 
-            "[(9-10)s:d|_10#9-10|>:xip/syntax-dep_rel$<i>2<s>2|>:xip/syntax-dep_rel$<i>1<s>1]");
+            "[(9-10)s:d|_10#9-10|>:xip/syntax-dep_rel$<i>1<s>2|>:xip/syntax-dep_rel$<i>3<s>1]");
         return fd;
     }
 	
-	/** Test token-token relation
-	 * */
+	private FieldDocument createFieldDoc1(){
+    	FieldDocument fd = new FieldDocument();
+        fd.addString("ID", "doc-1");
+        fd.addTV("base",
+            "text",             
+            "[(0-1)s:c|_1#0-1|>:xip/syntax-dep_rel$<i>3<i>6<i>9<s>2|>:xip/syntax-dep_rel$<i>6<i>9<s>1]" +
+            "[(1-2)s:e|_2#1-2]" +             
+            "[(2-3)s:c|_3#2-3]" +
+            "[(3-4)s:c|s:b|_4#3-4]" + 
+            "[(4-5)s:e|s:d|_5#4-5]" +
+            "[(5-6)s:c|_6#5-6]" +
+            "[(6-7)s:d|_7#6-7|<:xip/syntax-dep_rel$<i>9<b>0<i>0<s>1|>:xip/syntax-dep_rel$<i>9<b>0<i>9<s>3|" +
+            	"<:xip/syntax-dep_rel$<i>9<i>1<i>3<s>2]" +
+            "[(7-8)s:e|_8#7-8]" + 
+            "[(8-9)s:e|s:b|_9#8-9]" + 
+            "[(9-10)s:d|_10#9-10|<:xip/syntax-dep_rel$<i>6<i>9<s>2]");
+        return fd;
+    }
+	
+	
 	@Test
 	public void testCase1() throws IOException {
 		ki.addDoc(createFieldDoc0());
+		ki.addDoc(createFieldDoc1());
 		ki.commit();
 		
 		SpanRelationQuery sq = new SpanRelationQuery(
 				new SpanTermQuery(new Term("base",">:xip/syntax-dep_rel")),true);
-		ki.search(sq,(short) 10);
+		kr = ki.search(sq,(short) 10);
+		
+		assertEquals(7, kr.getTotalResults());
+		// token to token
+		assertEquals(0,kr.getMatch(0).getLocalDocID());
+		assertEquals(0,kr.getMatch(0).getStartPos());
+		assertEquals(1,kr.getMatch(0).getEndPos());
+		assertEquals(1,kr.getMatch(1).getStartPos());
+		assertEquals(2,kr.getMatch(1).getEndPos());
+		assertEquals(9,kr.getMatch(2).getStartPos());
+		assertEquals(10,kr.getMatch(2).getEndPos());
+		assertEquals(9,kr.getMatch(3).getStartPos());
+		assertEquals(10,kr.getMatch(3).getEndPos());
+		
+		// token to span
+		assertEquals(1,kr.getMatch(4).getLocalDocID());
+		assertEquals(0,kr.getMatch(4).getStartPos());
+		assertEquals(1,kr.getMatch(4).getEndPos());
+		assertEquals(0,kr.getMatch(5).getStartPos());
+		assertEquals(3,kr.getMatch(5).getEndPos());
+		
+		// span to span
+		assertEquals(6,kr.getMatch(6).getStartPos());
+		assertEquals(9,kr.getMatch(6).getEndPos());
+		
+		// check target
+		
+	}
+	
+	@Test
+	public void testCase2() throws IOException {
+		ki.addDoc(createFieldDoc0());
+		ki.addDoc(createFieldDoc1());
+		ki.commit();
+		
+		SpanRelationQuery sq = new SpanRelationQuery(
+				new SpanTermQuery(new Term("base","<:xip/syntax-dep_rel")),true);
+		kr = ki.search(sq,(short) 10);
+		
+		assertEquals(7, kr.getTotalResults());
+		// token to token
+		assertEquals(0,kr.getMatch(0).getLocalDocID());
+		assertEquals(1,kr.getMatch(0).getStartPos());
+		assertEquals(2,kr.getMatch(0).getEndPos());
+		assertEquals(3,kr.getMatch(1).getStartPos());
+		assertEquals(4,kr.getMatch(1).getEndPos());
+		assertEquals(4,kr.getMatch(2).getStartPos());
+		assertEquals(5,kr.getMatch(2).getEndPos());
+		assertEquals(6,kr.getMatch(3).getStartPos());
+		assertEquals(7,kr.getMatch(3).getEndPos());
+		
+		assertEquals(1,kr.getMatch(4).getLocalDocID());
+		// span to token
+		assertEquals(6,kr.getMatch(4).getStartPos());
+		assertEquals(9,kr.getMatch(4).getEndPos());
+		assertEquals(6,kr.getMatch(5).getStartPos());
+		assertEquals(9,kr.getMatch(5).getEndPos());
+		// span to span
+		assertEquals(9,kr.getMatch(6).getStartPos());
+		assertEquals(10,kr.getMatch(6).getEndPos());
 	}
 }