Skip to content

Commit

Permalink
Merge pull request #758 from gnanaprakash-ravi/0.4.1
Browse files Browse the repository at this point in the history
0.4.1 review comments implemented for pr code coverage
  • Loading branch information
sonalgoyal authored Jan 2, 2024
2 parents 26640dc + 1d46f2f commit 547f98a
Show file tree
Hide file tree
Showing 11 changed files with 606 additions and 0 deletions.
22 changes: 22 additions & 0 deletions common/core/src/test/java/zingg/common/core/model/TestModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package zingg.common.core.model;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import org.junit.jupiter.api.Test;

public class TestModel {

@Test
public void testGetGrid() {
double[] result = Model.getGrid(1.0, 10.0, 2.0, false);
double[] expected = {1.0, 3.0, 5.0, 7.0, 9.0};
assertArrayEquals(expected, result, 0.0);
}

@Test
public void testGetGridForMultiples() {
double[] result = Model.getGrid(1.0, 10.0, 2.0, true);
double[] expected = {1.0, 2.0, 4.0, 8.0};
assertArrayEquals(expected, result, 0.0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package zingg.common.core.sink;

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

import org.junit.jupiter.api.Test;

import zingg.common.core.sink.TableOutput;


public class TestTableOutput {

private TableOutput getInstance() {
return new TableOutput(3, 234456L, 87654L, "Company X");
}

@Test
public void testGetMethods() {
String ans = "Company X";
TableOutput value = getInstance();
assertEquals(3, value.getJobId());
assertEquals(234456L, value.getTimestamp());
assertEquals(87654L, value.getClusterId());
assertEquals(ans, value.getRecord());
}

@Test
public void testSetMethods() {
TableOutput value = getInstance();
int newJobId = 5;
long newTimestamp = 778899L;
long newClusterId = 9876L;
String newRecord = "Company Y";

value.setJobId(newJobId);
value.setTimestamp(newTimestamp);
value.setClusterId(newClusterId);
value.setRecord(newRecord);

assertEquals(5, value.getJobId());
assertEquals(778899L, value.getTimestamp());
assertEquals(9876L, value.getClusterId());
assertEquals(newRecord, value.getRecord());
}

}
25 changes: 25 additions & 0 deletions common/core/src/test/java/zingg/hash/TestHashFnFromConf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package zingg.hash;

import static org.junit.jupiter.api.Assertions.assertEquals;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.junit.jupiter.api.Test;

import zingg.common.core.hash.HashFnFromConf;

@JsonInclude(Include.NON_NULL)
public class TestHashFnFromConf {
@Test
public void testHashFnFromConf() {
HashFnFromConf hashFnFromConf = new HashFnFromConf();
hashFnFromConf.setName("Micheal");
assertEquals("Micheal", hashFnFromConf.getName());
}

@Test
public void testHashFnFromConf1() {
HashFnFromConf hashFnFromConf = new HashFnFromConf();
hashFnFromConf.setName(null);
assertEquals(null, hashFnFromConf.getName());
}
}
150 changes: 150 additions & 0 deletions common/core/src/test/java/zingg/hash/TestHashFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package zingg.hash;

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

import org.junit.jupiter.api.Test;

import zingg.common.client.ZFrame;
import zingg.common.core.hash.HashFunction;


public class TestHashFunction {
@Test
public void testGetName() {
HashFunction<String, Integer, Boolean, Long> hashFunction = new HashFunction<String, Integer, Boolean, Long>("initialName") {
@Override
public ZFrame<String, Integer, Boolean> apply(ZFrame<String, Integer, Boolean> ds, String column, String newColumn) {
return null;
}

@Override
public Object getAs(Integer integer, String column) {
return null;
}

@Override
public Object getAs(String s, Integer integer, String column) {
return null;
}

@Override
public Object apply(Integer integer, String column) {
return null;
}

@Override
public Object apply(String s, Integer integer, String column) {
return null;
}
};

String expectedName = "hashFunction";
hashFunction.setName(expectedName);
assertEquals(expectedName, hashFunction.getName());
}
@Test
public void testGetReturnType() {
HashFunction<String, Integer, Boolean, Long> hashFunction = new HashFunction<String, Integer, Boolean, Long>("Name", 999L, 888L) {
@Override
public ZFrame<String, Integer, Boolean> apply(ZFrame<String, Integer, Boolean> ds, String column, String newColumn) {
return null;
}

@Override
public Object getAs(Integer integer, String column) {
return null;
}

@Override
public Object getAs(String s, Integer integer, String column) {
return null;
}

@Override
public Object apply(Integer integer, String column) {
return null;
}

@Override
public Object apply(String s, Integer integer, String column) {
return null;
}
};

long returnType = 9999L;
hashFunction.setReturnType(returnType);
assertEquals(returnType, hashFunction.getReturnType());

long dataType = 888L;
hashFunction.setDataType(dataType);
assertEquals(dataType, hashFunction.getDataType());
}

@Test
public void testIsUdf() {
HashFunction<String, Integer, Boolean, Long> hashFunction = new HashFunction<String, Integer, Boolean, Long>("Name", 999L, 888L, true) {
@Override
public ZFrame<String, Integer, Boolean> apply(ZFrame<String, Integer, Boolean> ds, String column, String newColumn) {
return null;
}

@Override
public Object getAs(Integer integer, String column) {
return null;
}

@Override
public Object getAs(String s, Integer integer, String column) {
return null;
}

@Override
public Object apply(Integer integer, String column) {
return null;
}

@Override
public Object apply(String s, Integer integer, String column) {
return null;
}
};

Boolean isUdf = false;
hashFunction.setUdf(isUdf);
assertEquals(false, hashFunction.isUdf());
}

@Test
public void testGetAs() {
HashFunction<String, Integer, Boolean, Long> hashFunction = new HashFunction<String, Integer, Boolean, Long>() {
@Override
public ZFrame<String, Integer, Boolean> apply(ZFrame<String, Integer, Boolean> ds, String column, String newColumn) {
return null;
}

@Override
public Object getAs(Integer integer, String column) {
return null;
}

@Override
public Object getAs(String s, Integer integer, String column) {
return null;
}

@Override
public Object apply(Integer integer, String column) {
return null;
}

@Override
public Object apply(String s, Integer integer, String column) {
return null;
}
};
Integer value = 10;
String column = "inputColumn";
assertEquals(null, hashFunction.getAs(value, column));
}

}
27 changes: 27 additions & 0 deletions common/core/src/test/java/zingg/hash/TestIdentityLong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package zingg.hash;

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

import org.junit.jupiter.api.Test;

import zingg.common.core.hash.IdentityLong;

public class TestIdentityLong {

@Test
public void testIdentityLong() {
IdentityLong value = getInstance();
assertEquals(12345L, value.call(12345L));
}

@Test
public void testNullValue() {
IdentityLong value = getInstance();
assertEquals(null, value.call(null));
}

private IdentityLong getInstance() {
return new IdentityLong();
}

}
40 changes: 40 additions & 0 deletions common/core/src/test/java/zingg/hash/TestLessThanZeroFloat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package zingg.hash;

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

import org.junit.jupiter.api.Test;

import zingg.common.core.hash.LessThanZeroFloat;

public class TestLessThanZeroFloat {

@Test
public void testLessThanZeroFloatForValueZero() {
LessThanZeroFloat value = getInstance();
assertFalse(value.call(0.0f));
}

@Test
public void testLessThanZeroFloatForValueNull() {
LessThanZeroFloat value = getInstance();
assertFalse(value.call(null));
}

@Test
public void testLessThanZeroFloatNegativeValue() {
LessThanZeroFloat value = getInstance();
assertTrue(value.call(-5435.45f));
}

@Test
public void testLessThanZeroFloatPositiveValue() {
LessThanZeroFloat value = getInstance();
assertFalse(value.call(876.457f));
}

private LessThanZeroFloat getInstance() {
LessThanZeroFloat value = new LessThanZeroFloat();
return value;
}
}
40 changes: 40 additions & 0 deletions common/core/src/test/java/zingg/hash/TestLessThanZeroLong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package zingg.hash;

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

import org.junit.jupiter.api.Test;

import zingg.common.core.hash.LessThanZeroLong;

public class TestLessThanZeroLong {

@Test
public void testLessThanZeroLongForValueZero() {
LessThanZeroLong value = getInstance();
assertFalse(value.call(0L));
}

@Test
public void testLessThanZeroLongForValueNull() {
LessThanZeroLong value = getInstance();
assertFalse(value.call(null));
}

@Test
public void testLessThanZeroLongNegativeValue() {
LessThanZeroLong value = getInstance();
assertTrue(value.call(-543545L));
}

@Test
public void testLessThanZeroLongPositiveValue() {
LessThanZeroLong value = getInstance();
assertFalse(value.call(876457L));
}

private LessThanZeroLong getInstance() {
LessThanZeroLong value = new LessThanZeroLong();
return value;
}
}
Loading

0 comments on commit 547f98a

Please sign in to comment.