New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improving code coverage issue #615 #616
base: 0.4.0
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package zingg.common.core.model; | ||
|
||
import zingg.common.client.ZFrame; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import zingg.common.core.model.Model; | ||
|
||
import java.io.IOException; | ||
|
||
public class TestModel { | ||
@Test | ||
public void testGetGrid() { | ||
Model<Object, Object, Object, Object, Object> model = getInstance(); | ||
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() { | ||
Model<Object, Object, Object, Object, Object> model = getInstance(); | ||
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); | ||
} | ||
|
||
private Model<Object, Object, Object, Object, Object> getInstance() { | ||
Model<Object, Object, Object, Object, Object> model = new Model<Object, Object, Object, Object, Object>() { | ||
@Override | ||
public void register(Object spark) { | ||
} | ||
|
||
@Override | ||
public void fit(ZFrame<Object, Object, Object> pos, ZFrame<Object, Object, Object> neg) { | ||
} | ||
|
||
@Override | ||
public void load(String path) { | ||
} | ||
|
||
@Override | ||
public ZFrame<Object, Object, Object> predict(ZFrame<Object, Object, Object> data) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ZFrame<Object, Object, Object> predict(ZFrame<Object, Object, Object> data, boolean isDrop) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void save(String path) throws IOException { | ||
} | ||
|
||
@Override | ||
public ZFrame<Object, Object, Object> transform(ZFrame<Object, Object, Object> input) { | ||
return null; | ||
} | ||
}; | ||
return model; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package zingg.common.core.sink; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont use the tableoutput class anywhere in the code so can you please remove the test annotations so that this code is not run. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we start using the class, we can utilize this junit, so it makes sense to keep it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted |
||
|
||
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()); | ||
} | ||
|
||
} |
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()); | ||
} | ||
} |
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)); | ||
} | ||
|
||
} |
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 testIdentityLong1() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to testNullValue |
||
IdentityLong value = getInstance(); | ||
assertEquals(null, value.call(null)); | ||
} | ||
|
||
private IdentityLong getInstance() { | ||
return new IdentityLong(); | ||
} | ||
|
||
} |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a good test |
||
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see the value in creating a model instance here. the static method can be tested directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The model class is an abstract class. This was one of the methods to test it, or we can test it through it's implementations. But it is not being used anywhere.
Please guide me if there is any other way to test this class