package org.umlg.sqlg.test.aggregate;

import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.structure.Column;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assert;
import org.junit.Test;
import org.umlg.sqlg.test.BaseTest;

import java.util.Map;

/**
 * @author Pieter Martin (https://github.com/pietermartin)
 *         Date: 2017/05/02
 */
public class TestGroupCount extends BaseTest {

    @Test
    public void g_V_both_groupCountXaX_out_capXaX_selectXkeysX_unfold_both_groupCountXaX_capXaX() {
        loadModern();

        final Traversal<Vertex, Map<Vertex, Long>> traversal = this.sqlgGraph.traversal().V().both().groupCount("a").out().cap("a").select(Column.keys).unfold().both().groupCount("a").cap("a");
        printTraversalForm(traversal);
        //  [{v[1]=6, v[2]=2, v[3]=6, v[4]=6, v[5]=2, v[6]=2}]
        final Map<Vertex, Long> map = traversal.next();
        Assert.assertFalse(traversal.hasNext());
        Assert.assertEquals(6, map.size());
        Assert.assertEquals(6l, map.get(convertToVertex(this.sqlgGraph, "marko")).longValue());
        Assert.assertEquals(2l, map.get(convertToVertex(this.sqlgGraph, "vadas")).longValue());
        Assert.assertEquals(6l, map.get(convertToVertex(this.sqlgGraph, "lop")).longValue());
        Assert.assertEquals(6l, map.get(convertToVertex(this.sqlgGraph, "josh")).longValue());
        Assert.assertEquals(2l, map.get(convertToVertex(this.sqlgGraph, "ripple")).longValue());
        Assert.assertEquals(6l, map.get(convertToVertex(this.sqlgGraph, "marko")).longValue());
//        checkSideEffects(traversal.asAdmin().getSideEffects(), "a", HashMap.class);
    }
}

@@ -32,16 +32,172 @@
 egate;%0A%0A
+import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport java.util.Map;%0A%0A
 import o
@@ -253,16 +253,16 @@
 versal;%0A
-
 import o
@@ -307,16 +307,65 @@
 Column;%0A
+import org.apache.tinkerpop.gremlin.structure.T;%0A
 import o
@@ -414,33 +414,8 @@
 ex;%0A
-import org.junit.Assert;%0A
 impo
@@ -470,39 +470,16 @@
 eTest;%0A%0A
-import java.util.Map;%0A%0A
 /**%0A * @
@@ -1102,31 +1102,24 @@
 ();%0A        
-Assert.
 assertFalse(
@@ -1140,39 +1140,32 @@
 ext());%0A        
-Assert.
 assertEquals(6, 
@@ -1177,39 +1177,32 @@
 ize());%0A        
-Assert.
 assertEquals(6l,
@@ -1266,39 +1266,32 @@
 lue());%0A        
-Assert.
 assertEquals(2l,
@@ -1355,39 +1355,32 @@
 lue());%0A        
-Assert.
 assertEquals(6l,
@@ -1442,39 +1442,32 @@
 lue());%0A        
-Assert.
 assertEquals(6l,
@@ -1530,39 +1530,32 @@
 lue());%0A        
-Assert.
 assertEquals(2l,
@@ -1628,23 +1628,16 @@
         
-Assert.
 assertEq
@@ -1801,10 +1801,519 @@
 ;%0A    %7D%0A
+    %0A    @Test%0A    public void testGroupCountByLabel()%7B%0A    %09loadModern();%0A    %09final Traversal%3CVertex, Map%3CObject, Long%3E%3E traversal = this.sqlgGraph.traversal().V().groupCount().by(T.label);%0A    %09printTraversalForm(traversal);%0A    %09assertTrue(traversal.hasNext());%0A    %09Map%3CObject, Long%3E map=traversal.next();%0A    %09assertFalse(traversal.hasNext());%0A        assertEquals(2, map.size());%0A        assertEquals(Long.valueOf(4),map.get(%22person%22));%0A        assertEquals(Long.valueOf(2),map.get(%22software%22));%0A    %7D%0A
 %7D%0A

test group count for label