-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #864 from Nitish1814/testRefactor
Test refactor
- Loading branch information
Showing
40 changed files
with
1,912 additions
and
1,102 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
common/client/src/main/java/zingg/common/client/util/DFObjectUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package zingg.common.client.util; | ||
|
||
import java.util.List; | ||
|
||
import zingg.common.client.ZFrame; | ||
|
||
public abstract class DFObjectUtil<S, D, R, C> { | ||
|
||
protected final IWithSession<S> iWithSession; | ||
|
||
protected DFObjectUtil(IWithSession<S> iWithSession) { | ||
this.iWithSession = iWithSession; | ||
} | ||
|
||
public abstract ZFrame<D, R, C> getDFFromObjectList(List objList, Class objClass) throws Exception; | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
common/client/src/main/java/zingg/common/client/util/IWithSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package zingg.common.client.util; | ||
|
||
public interface IWithSession<S> { | ||
|
||
public void setSession(S s); | ||
|
||
public S getSession(); | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
common/client/src/main/java/zingg/common/client/util/PojoToArrayConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package zingg.common.client.util; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public class PojoToArrayConverter { | ||
|
||
public static Object[] getObjectArray(Object object) throws IllegalAccessException { | ||
Field[] fieldsInChildClass = object.getClass().getDeclaredFields(); | ||
Field[] fieldsInParentClass = null; | ||
|
||
int fieldCountInChildClass = fieldsInChildClass.length; | ||
int fieldCount = fieldCountInChildClass; | ||
|
||
if (object.getClass().getSuperclass() != null) { | ||
fieldCount += object.getClass().getSuperclass().getDeclaredFields().length; | ||
fieldsInParentClass = object.getClass().getSuperclass().getDeclaredFields(); | ||
} | ||
|
||
//fieldCount = fieldCountChild + fieldCountParent | ||
Object[] objArr = new Object[fieldCount]; | ||
|
||
int idx = 0; | ||
|
||
//iterate through child class fields | ||
for (; idx < fieldCountInChildClass; idx++) { | ||
Field field = fieldsInChildClass[idx]; | ||
field.setAccessible(true); | ||
objArr[idx] = field.get(object); | ||
} | ||
|
||
//iterate through super class fields | ||
for (; idx < fieldCount; idx++) { | ||
Field field = fieldsInParentClass[idx - fieldCountInChildClass]; | ||
field.setAccessible(true); | ||
objArr[idx] = field.get(object); | ||
} | ||
|
||
return objArr; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
common/client/src/main/java/zingg/common/client/util/StructTypeFromPojoClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package zingg.common.client.util; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public abstract class StructTypeFromPojoClass<ST, SF, T> { | ||
|
||
public abstract ST getStructType(Class<?> objClass) throws Exception; | ||
|
||
public List<SF> getFields(Class<?> objClass) { | ||
List<SF> structFields = new ArrayList<SF>(); | ||
Field[] fields = objClass.getDeclaredFields(); | ||
|
||
//add child class fields in struct | ||
for (Field f : fields) { | ||
structFields.add(getStructField(f)); | ||
} | ||
|
||
//add parent class fields in struct | ||
if (objClass.getSuperclass() != null) { | ||
Field[] fieldsSuper = objClass.getSuperclass().getDeclaredFields(); | ||
for (Field f : fieldsSuper) { | ||
structFields.add(getStructField(f)); | ||
} | ||
} | ||
return structFields; | ||
} | ||
|
||
public abstract SF getStructField(Field field); | ||
|
||
public abstract T getSFType(Class<?> t); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
common/client/src/main/java/zingg/common/client/util/WithSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package zingg.common.client.util; | ||
|
||
public class WithSession<S> implements IWithSession<S> { | ||
|
||
S session; | ||
@Override | ||
public void setSession(S session) { | ||
this.session = session; | ||
} | ||
|
||
@Override | ||
public S getSession() { | ||
return session; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
common/core/src/test/java/zingg/common/core/block/TestBlockBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package zingg.common.core.block; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import zingg.common.client.ArgumentsUtil; | ||
import zingg.common.client.FieldDefinition; | ||
import zingg.common.client.IArguments; | ||
import zingg.common.client.MatchType; | ||
import zingg.common.client.ZFrame; | ||
import zingg.common.client.ZinggClientException; | ||
import zingg.common.client.util.DFObjectUtil; | ||
import zingg.common.core.util.BlockingTreeUtil; | ||
import zingg.common.core.util.HashUtil; | ||
import zingg.common.core.model.Event; | ||
import zingg.common.core.model.EventPair; | ||
import zingg.common.core.data.EventTestData; | ||
|
||
public abstract class TestBlockBase<S, D, R, C, T> { | ||
|
||
public ArgumentsUtil argumentsUtil = new ArgumentsUtil(); | ||
public final DFObjectUtil<S, D, R, C> dfObjectUtil; | ||
public final HashUtil<S, D, R, C, T> hashUtil; | ||
public final BlockingTreeUtil<S, D, R, C, T> blockingTreeUtil; | ||
|
||
public TestBlockBase(DFObjectUtil<S, D, R, C> dfObjectUtil, HashUtil<S, D, R, C, T> hashUtil, BlockingTreeUtil<S, D, R, C, T> blockingTreeUtil) { | ||
this.dfObjectUtil = dfObjectUtil; | ||
this.hashUtil = hashUtil; | ||
this.blockingTreeUtil = blockingTreeUtil; | ||
} | ||
|
||
@Test | ||
public void testTree() throws Throwable { | ||
|
||
// form tree | ||
ZFrame<D, R, C> zFrameEvent = dfObjectUtil.getDFFromObjectList(EventTestData.createSampleEventData(), Event.class); | ||
ZFrame<D, R, C> zFrameEventCluster = dfObjectUtil.getDFFromObjectList(EventTestData.createSampleClusterEventData(), EventPair.class); | ||
IArguments args = getArguments(); | ||
|
||
Tree<Canopy<R>> blockingTree = blockingTreeUtil.createBlockingTreeFromSample(zFrameEvent, zFrameEventCluster, 0.5, -1, | ||
args, hashUtil.getHashFunctionList()); | ||
|
||
// primary deciding is unique year so identityInteger should have been picked | ||
Canopy<R> head = blockingTree.getHead(); | ||
assertEquals("identityInteger", head.getFunction().getName()); | ||
blockingTree.toString(); | ||
} | ||
|
||
private IArguments getArguments() throws ZinggClientException { | ||
String configFilePath = Objects.requireNonNull(getClass().getResource("../../../../testFebrl/config.json")).getFile(); | ||
|
||
IArguments args = argumentsUtil.createArgumentsFromJSON(configFilePath, "trainMatch"); | ||
|
||
List<FieldDefinition> fdList = getFieldDefList(); | ||
|
||
args.setFieldDefinition(fdList); | ||
return args; | ||
} | ||
|
||
private List<FieldDefinition> getFieldDefList() { | ||
List<FieldDefinition> fdList = new ArrayList<FieldDefinition>(4); | ||
|
||
FieldDefinition idFD = new FieldDefinition(); | ||
idFD.setDataType("integer"); | ||
idFD.setFieldName("id"); | ||
ArrayList<MatchType> matchTypelistId = new ArrayList<MatchType>(); | ||
matchTypelistId.add(MatchType.DONT_USE); | ||
idFD.setMatchType(matchTypelistId); | ||
fdList.add(idFD); | ||
|
||
ArrayList<MatchType> matchTypelistFuzzy = new ArrayList<MatchType>(); | ||
matchTypelistFuzzy.add(MatchType.FUZZY); | ||
|
||
|
||
FieldDefinition yearFD = new FieldDefinition(); | ||
yearFD.setDataType("integer"); | ||
yearFD.setFieldName("year"); | ||
yearFD.setMatchType(matchTypelistFuzzy); | ||
fdList.add(yearFD); | ||
|
||
FieldDefinition eventFD = new FieldDefinition(); | ||
eventFD.setDataType("string"); | ||
eventFD.setFieldName("event"); | ||
eventFD.setMatchType(matchTypelistFuzzy); | ||
fdList.add(eventFD); | ||
|
||
FieldDefinition commentFD = new FieldDefinition(); | ||
commentFD.setDataType("string"); | ||
commentFD.setFieldName("comment"); | ||
commentFD.setMatchType(matchTypelistFuzzy); | ||
fdList.add(commentFD); | ||
return fdList; | ||
} | ||
|
||
} |
6 changes: 1 addition & 5 deletions
6
...e/src/test/java/zingg/block/TestTree.java → ...ava/zingg/common/core/block/TestTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.