Skip to content
Snippets Groups Projects
Commit 017e56a9 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman :boom:
Browse files

Added some more unit tests.

Change-Id: Icedcbd5e96043453f467f2bf578ad06aa4a1e75a
parent ec80d62f
No related merge requests found
Showing
with 261 additions and 3 deletions
......@@ -46,8 +46,7 @@ public class TypedIncidenceMethodHandler implements MethodHandler<TypedIncidence
if( ! (element instanceof Vertex) )
throw new IllegalStateException("element is not a type of Vertex " + element.getClass().getName());
if(annotation.label() == null)
throw new IllegalStateException("method " + method.getName() + " label must be specified on @TypedIncidence annotation");
assert annotation.label() != null;
if( ClassUtilities.isGetMethod(method) ) {
if( arguments == null )
......
......@@ -23,7 +23,7 @@ import com.tinkerpop.frames.annotations.gremlin.GremlinGroovy;
import com.tinkerpop.frames.modules.typedgraph.TypeValue;
@TypeValue("GodExtended")
public interface GodExtended extends God {
public interface GodExtended extends GodIntermediate {
@GremlinGroovy("it.in('father').in('father')")
God getGrandson();
}
/******************************************************************************
* *
* Copyright: (c) Syncleus, Inc. *
* *
* You may redistribute and modify this source code under the terms and *
* conditions of the Open Source Community License - Type C version 1.0 *
* or any later version as published by Syncleus, Inc. at www.syncleus.com. *
* There should be a copy of the license included with this file. If a copy *
* of the license is not included you are granted no right to distribute or *
* otherwise use this file except through a legal and valid license. You *
* should also contact Syncleus, Inc. at the information below if you cannot *
* find a license: *
* *
* Syncleus, Inc. *
* 2604 South 12th Street *
* Philadelphia, PA 19148 *
* *
******************************************************************************/
package com.syncleus.grail.graph;
import com.tinkerpop.frames.modules.typedgraph.TypeValue;
@TypeValue("GodIntermediate")
public interface GodIntermediate extends God {
}
/******************************************************************************
* *
* Copyright: (c) Syncleus, Inc. *
* *
* You may redistribute and modify this source code under the terms and *
* conditions of the Open Source Community License - Type C version 1.0 *
* or any later version as published by Syncleus, Inc. at www.syncleus.com. *
* There should be a copy of the license included with this file. If a copy *
* of the license is not included you are granted no right to distribute or *
* otherwise use this file except through a legal and valid license. You *
* should also contact Syncleus, Inc. at the information below if you cannot *
* find a license: *
* *
* Syncleus, Inc. *
* 2604 South 12th Street *
* Philadelphia, PA 19148 *
* *
******************************************************************************/
package com.syncleus.grail.graph;
import com.tinkerpop.frames.FramedTransactionalGraph;
import com.tinkerpop.frames.modules.javahandler.JavaHandlerModule;
import junit.framework.Assert;
import org.junit.Test;
import java.util.Collections;
public class GrailGraphFactoryTest {
@Test
public void testCustomModules() {
final GrailGraphFactory factory = new GrailGraphFactory(Collections.singleton(new JavaHandlerModule()));
final FramedTransactionalGraph<?> graph = factory.create(new MockTransactionalTinkerGraph());
Assert.assertTrue( !graph.getVertices().iterator().hasNext() );
}
}
......@@ -49,6 +49,20 @@ public class TypedAdjacencyMethodHandlerTest {
HANDLER.processElement(MOCK_FRAME, GET_SON_METHOD, new Object[]{God.class}, TYPED_ANNOTATION, framedGraph, MOCK_ELEMENT);
}
@Test(expected = IllegalStateException.class)
public void testWrongArgument() {
final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
HANDLER.processElement(MOCK_FRAME, GET_SON_METHOD, new Object[]{new Object()}, TYPED_ANNOTATION, framedGraph, MOCK_VERTEX);
}
@Test(expected = IllegalStateException.class)
public void testToManyArgument() {
final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
HANDLER.processElement(MOCK_FRAME, GET_SON_METHOD, new Object[]{new Object(), new Object()}, TYPED_ANNOTATION, framedGraph, MOCK_VERTEX);
}
@Test(expected = IllegalStateException.class)
public void testNullArguments() {
final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
......
......@@ -27,6 +27,7 @@ import java.lang.reflect.Method;
public class TypedIncidenceMethodHandlerTest {
private static final TypedIncidenceMethodHandler HANDLER = new TypedIncidenceMethodHandler(null);
private static final Method GET_SON_EDGE_METHOD;
private static final Method ADD_SON_EDGE_METHOD;
private static final TypedIncidence TYPED_ANNOTATION;
private static final Object MOCK_FRAME = new Object();
private static final Element MOCK_ELEMENT = new MockElement();
......@@ -40,6 +41,13 @@ public class TypedIncidenceMethodHandlerTest {
throw new IllegalStateException(caught);
}
try {
ADD_SON_EDGE_METHOD = God.class.getMethod("addSonEdge", Class.class);
}
catch( final NoSuchMethodException caught ) {
throw new IllegalStateException(caught);
}
TYPED_ANNOTATION = GET_SON_EDGE_METHOD.getAnnotation(TypedIncidence.class);
}
......@@ -50,6 +58,27 @@ public class TypedIncidenceMethodHandlerTest {
HANDLER.processElement(MOCK_FRAME, GET_SON_EDGE_METHOD, new Object[]{God.class}, TYPED_ANNOTATION, framedGraph, MOCK_ELEMENT);
}
@Test(expected = IllegalStateException.class)
public void testWrongArgument() {
final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
HANDLER.processElement(MOCK_FRAME, GET_SON_EDGE_METHOD, new Object[]{new Object()}, TYPED_ANNOTATION, framedGraph, MOCK_VERTEX);
}
@Test(expected = IllegalStateException.class)
public void testTooManyArgument() {
final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
HANDLER.processElement(MOCK_FRAME, GET_SON_EDGE_METHOD, new Object[]{new Object(), new Object()}, TYPED_ANNOTATION, framedGraph, MOCK_VERTEX);
}
@Test(expected = IllegalStateException.class)
public void testTooBadPrefix() {
final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
HANDLER.processElement(MOCK_FRAME, ADD_SON_EDGE_METHOD, new Object[]{God.class}, TYPED_ANNOTATION, framedGraph, MOCK_VERTEX);
}
@Test(expected = IllegalStateException.class)
public void testNullArguments() {
final FramedGraph framedGraph = BlankGraphFactory.makeTinkerGraph();
......
/******************************************************************************
* *
* Copyright: (c) Syncleus, Inc. *
* *
* You may redistribute and modify this source code under the terms and *
* conditions of the Open Source Community License - Type C version 1.0 *
* or any later version as published by Syncleus, Inc. at www.syncleus.com. *
* There should be a copy of the license included with this file. If a copy *
* of the license is not included you are granted no right to distribute or *
* otherwise use this file except through a legal and valid license. You *
* should also contact Syncleus, Inc. at the information below if you cannot *
* find a license: *
* *
* Syncleus, Inc. *
* 2604 South 12th Street *
* Philadelphia, PA 19148 *
* *
******************************************************************************/
package com.syncleus.grail.neural;
import com.syncleus.grail.graph.BlankGraphFactory;
import com.syncleus.grail.neural.activation.*;
import com.tinkerpop.frames.FramedTransactionalGraph;
import junit.framework.Assert;
import org.junit.Test;
import java.lang.reflect.*;
public class AbstractActivationNeuronTest {
@Test( expected = UndeclaredThrowableException.class )
public void testBadAccessActivation() {
final FramedTransactionalGraph<?> graph = BlankGraphFactory.makeTinkerGraph();
final ActivationNeuron neuron = graph.addVertex(null, ActivationNeuron.class);
neuron.setActivationFunctionClass(BadAccessActivationFunction.class);
try {
neuron.propagate();
}
catch( final UndeclaredThrowableException caught ) {
Assert.assertTrue(InvocationTargetException.class.equals(caught.getUndeclaredThrowable().getClass()));
throw caught;
}
}
@Test( expected = UndeclaredThrowableException.class )
public void testNoDefaultConstructorActivation() {
final FramedTransactionalGraph<?> graph = BlankGraphFactory.makeTinkerGraph();
final ActivationNeuron neuron = graph.addVertex(null, ActivationNeuron.class);
neuron.setActivationFunctionClass(NoDefaultConstructorActivationFunction.class);
try {
neuron.propagate();
}
catch( final UndeclaredThrowableException caught ) {
Assert.assertTrue(InvocationTargetException.class.equals(caught.getUndeclaredThrowable().getClass()));
throw caught;
}
}
}
/******************************************************************************
* *
* Copyright: (c) Syncleus, Inc. *
* *
* You may redistribute and modify this source code under the terms and *
* conditions of the Open Source Community License - Type C version 1.0 *
* or any later version as published by Syncleus, Inc. at www.syncleus.com. *
* There should be a copy of the license included with this file. If a copy *
* of the license is not included you are granted no right to distribute or *
* otherwise use this file except through a legal and valid license. You *
* should also contact Syncleus, Inc. at the information below if you cannot *
* find a license: *
* *
* Syncleus, Inc. *
* 2604 South 12th Street *
* Philadelphia, PA 19148 *
* *
******************************************************************************/
package com.syncleus.grail.neural.activation;
public class BadAccessActivationFunction implements ActivationFunction {
private BadAccessActivationFunction() {
}
@Override
public double activate(final double activity) {
return 0;
}
@Override
public double activateDerivative(final double activity) {
return 0;
}
@Override
public boolean isBound() {
return false;
}
@Override
public double getUpperLimit() {
return 0;
}
@Override
public double getLowerLimit() {
return 0;
}
}
/******************************************************************************
* *
* Copyright: (c) Syncleus, Inc. *
* *
* You may redistribute and modify this source code under the terms and *
* conditions of the Open Source Community License - Type C version 1.0 *
* or any later version as published by Syncleus, Inc. at www.syncleus.com. *
* There should be a copy of the license included with this file. If a copy *
* of the license is not included you are granted no right to distribute or *
* otherwise use this file except through a legal and valid license. You *
* should also contact Syncleus, Inc. at the information below if you cannot *
* find a license: *
* *
* Syncleus, Inc. *
* 2604 South 12th Street *
* Philadelphia, PA 19148 *
* *
******************************************************************************/
package com.syncleus.grail.neural.activation;
public class NoDefaultConstructorActivationFunction implements ActivationFunction {
public NoDefaultConstructorActivationFunction(String something) {
}
@Override
public double activate(final double activity) {
return 0;
}
@Override
public double activateDerivative(final double activity) {
return 0;
}
@Override
public boolean isBound() {
return false;
}
@Override
public double getUpperLimit() {
return 0;
}
@Override
public double getLowerLimit() {
return 0;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment