package com.easyagents.store.milvus;

import com.easyagents.core.store.SearchWrapper;
import com.easyagents.core.store.condition.Connector;
import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;

public class MilvusExpressionAdaptorTest {

    @Test
    public void testGroupAndInExpression() {
        SearchWrapper wrapper = new SearchWrapper();
        wrapper.eq("akey", "avalue").eq(Connector.OR, "bkey", "bvalue").group(w -> {
            w.eq("ckey", "cvalue").in(Connector.AND_NOT, "dkey", Arrays.asList("aa", "bb"));
        }).eq("a", "b");

        String expr = "akey == \"avalue\" OR bkey == \"bvalue\" AND (ckey == \"cvalue\" AND NOT dkey IN [\"aa\",\"bb\"]) AND a == \"b\"";
        Assert.assertEquals(expr, wrapper.toFilterExpression(MilvusExpressionAdaptor.DEFAULT));
    }

    @Test
    public void testBetweenExpression() {
        SearchWrapper wrapper = new SearchWrapper();
        wrapper.eq("akey", "avalue").between(Connector.OR, "bkey", "1", "100").in("ckey", Arrays.asList("aa", "bb"));

        String expr = "akey == \"avalue\" OR (bkey >= 1 && bkey <= 100) AND ckey IN [\"aa\",\"bb\"]";
        Assert.assertEquals(expr, wrapper.toFilterExpression(MilvusExpressionAdaptor.DEFAULT));
    }
}
