Skip to content

Commit

Permalink
Merge pull request #4 from lensesio/feat/NGN-1216_DocumentUdfInstalla…
Browse files Browse the repository at this point in the history
…tion

NGN-1216: Added test example for udafs
  • Loading branch information
cmcmteixeira authored Aug 26, 2021
2 parents 3beeb8d + 4d8781f commit 90c34b2
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/test/java/io/lenses/sql/udaf/count_doubleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.lenses.sql.udaf;

import io.lenses.sql.udf.UdfException;
import io.lenses.sql.udf.datatype.DataType;
import io.lenses.sql.udf.value.LongValue;
import io.lenses.sql.udf.value.Value;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class count_doubleTest {
private count_double func = new count_double();

@Test
public void typesTheUdaf() throws UdfException {
assertTrue(func.typer(DataType.ltDouble()).isLong());
assertTrue(func.typer(DataType.ltFloat()).isLong());
assertTrue(func.typer(DataType.ltInt()).isLong());
assertTrue(func.typer(DataType.ltLong()).isLong());

assertTrue(func.typer(DataType.ltOptional(DataType.ltDouble())).isLong());
assertTrue(func.typer(DataType.ltOptional(DataType.ltFloat())).isLong());
assertTrue(func.typer(DataType.ltOptional(DataType.ltInt())).isLong());
assertTrue(func.typer(DataType.ltOptional(DataType.ltLong())).isLong());
}

@Test
public void correctlyCalculatesEmpty() throws UdfException {
assertEquals(func.empty().get(), 0L);
}

@Test
public void correctlyAddsElements() throws UdfException {
Value added1 = func.add(func.empty(), func.empty(), null);
assertEquals(added1.get(), 2L);
}

@Test
public void correctlyMergesElements() throws UdfException {
Value merge = func.merge(null, new LongValue(3), new LongValue(2));
assertEquals(merge.get(), 5L);
}


}

0 comments on commit 90c34b2

Please sign in to comment.