package ch.ethz.globis.distindex.mapping.zorder;

import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;

public class ZMappingTest {

    @Test
    public void testRangeQuerySimple() {
        int dim = 2;
        ZMapping mapping = new ZMapping(dim);
        mapping.add("one");
        mapping.add("two");
        mapping.add("three");
        mapping.add("four");
        String host;
        host = mapping.get(new long[] {1L, 1L});
        System.out.println(host);
        host = mapping.get(new long[] {-1L, 1L});
        System.out.println(host);
        host = mapping.get(new long[] {1L, -1L});
        System.out.println(host);
        host = mapping.get(new long[] {-1L, -1L});
        System.out.println(host);

        List<String> hosts;
        hosts = mapping.get(new long[]{1L, 1L}, new long[]{100L, 100L});
        System.out.println(hosts);
        assertEquals(1, hosts.size());

        hosts = mapping.get(new long[]{-1L, 1L}, new long[]{-100L, 100L});
        System.out.println(hosts);
        assertEquals(1, hosts.size());

        hosts = mapping.get(new long[]{1L, -1L}, new long[]{100L, -100L});
        System.out.println(hosts);
        assertEquals(1, hosts.size());

        hosts = mapping.get(new long[]{-1L, -1L}, new long[]{-100L, -100L});
        System.out.println(hosts);
        assertEquals(1, hosts.size());

        hosts = mapping.get(new long[]{-1L, -1L}, new long[] {-1L, 1L});
        System.out.println(hosts);
        assertEquals(2, hosts.size());

        hosts = mapping.get(new long[]{-1L, -1L}, new long[] {1L, -1L});
        System.out.println(hosts);
        assertEquals(2, hosts.size());

//        hosts = mapping.get(new long[]{-1L, 1L}, new long[] {1L, -1L});
//        System.out.println(hosts);
//        assertEquals(4, hosts.size());

        hosts = mapping.get(new long[]{-1L, -1L}, new long[] {1L, 1L});
        System.out.println(hosts);
        assertEquals(4, hosts.size());
    }


}

@@ -43,16 +43,41 @@
 order;%0A%0A
+import org.junit.Ignore;%0A
 import o
@@ -1706,18 +1706,16 @@
 ze());%0A%0A
-//
         
@@ -1742,32 +1742,33 @@
 new long%5B%5D%7B-1L, 
+-
 1L%7D, new long%5B%5D 
@@ -1776,17 +1776,644 @@
 1L, 
--
 1L%7D);%0A
-//
+        System.out.println(hosts);%0A        assertEquals(4, hosts.size());%0A    %7D%0A%0A    @Test%0A    @Ignore%0A    public void testReversedArguments() %7B%0A        /*%0A            Both bounds represent the same square, but the second one is not%0A             represented in lower-left, upper right manner.%0A         */%0A        //ToDo handle wrong square bounds%0A        int dim = 2;%0A        ZMapping mapping = new ZMapping(dim);%0A        mapping.add(%22one%22);%0A        mapping.add(%22two%22);%0A        mapping.add(%22three%22);%0A        mapping.add(%22four%22);%0A        List%3CString%3E hosts;%0A        hosts = mapping.get(new long%5B%5D %7B-1L, -1L%7D, new long%5B%5D%7B1L, 1L%7D );%0A
     
@@ -2443,18 +2443,16 @@
 hosts);%0A
-//
         
@@ -2513,39 +2513,39 @@
 g.get(new long%5B%5D
+ 
 %7B-1L, 
--
 1L%7D, new long%5B%5D 
@@ -2539,33 +2539,34 @@
 , new long%5B%5D
- 
 %7B1L, 
+-
 1L%7D
+ 
 );%0A        S

Index distribution Split tests for the mapping.