Skip to content

Commit

Permalink
Merge pull request #503 from cogmission/gradle_build_fix
Browse files Browse the repository at this point in the history
Gradle build fix
  • Loading branch information
cogmission committed Oct 17, 2016
2 parents 07e5c23 + 3880652 commit 7d0f682
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 4 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Expand Up @@ -4,15 +4,15 @@ apply plugin: 'eclipse'
apply plugin: 'signing'

group = 'org.numenta'
version = '0.6.10'
version = '0.6.11'
archivesBaseName = 'htm.java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

jar {
manifest {
attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.9-SNAPSHOT'
attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.11'
}
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -4,7 +4,7 @@

<groupId>org.numenta</groupId>
<artifactId>htm.java</artifactId>
<version>0.6.10</version>
<version>0.6.11</version>
<name>htm.java</name>
<description>The Java version of Numenta's HTM technology</description>

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/numenta/nupic/network/Layer.java
Expand Up @@ -344,6 +344,14 @@ public Layer<T> postDeSerialize() {
public void setNetwork(Network network) {
this.parentNetwork = network;
}

/**
* Returns the parent {@link Network}
* @return the parent Network;
*/
public Network getNetwork() {
return this.parentNetwork;
}

/**
* Creates a new {@code Layer} initialized with the specified algorithmic
Expand Down Expand Up @@ -415,6 +423,15 @@ public CheckPointOp<byte[]> delegateCheckPointCall() {
public void setRegion(Region r) {
this.parentRegion = r;
}

/**
* Returns the parent {@link Region}
*
* @return the parent Region
*/
public Region getRegion() {
return this.parentRegion;
}

/**
* Finalizes the initialization in one method call so that side effect
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/org/numenta/nupic/datagen/ResourceLocatorTest.java
@@ -0,0 +1,35 @@
package org.numenta.nupic.datagen;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import java.net.URI;

import org.junit.Test;


public class ResourceLocatorTest {

@Test
public void testURICreation() {
try {
ResourceLocator.uri(".");
fail();
}catch(Exception e) {
assertEquals(IllegalStateException.class, e.getClass());
assertEquals(java.net.MalformedURLException.class, e.getCause().getClass());
}

try {
URI uri = ResourceLocator.uri("file:///.");
assertNotNull(uri);

assertFalse(uri.isOpaque());
}catch(Exception e) {
fail();
}
}

}
103 changes: 103 additions & 0 deletions src/test/java/org/numenta/nupic/network/LayerTest.java
Expand Up @@ -48,6 +48,7 @@
import org.numenta.nupic.algorithms.TemporalMemory;
import org.numenta.nupic.datagen.ResourceLocator;
import org.numenta.nupic.encoders.MultiEncoder;
import org.numenta.nupic.model.Connections;
import org.numenta.nupic.model.SDR;
import org.numenta.nupic.network.Layer.FunctionFactory;
import org.numenta.nupic.network.sensor.FileSensor;
Expand Down Expand Up @@ -111,6 +112,108 @@ public void testMasking() {
algo_content_mask ^= Layer.CLA_CLASSIFIER;
assertEquals(0, algo_content_mask);
}

@Test
public void callsOnClosedLayer() {
Parameters p = NetworkTestHarness.getParameters().copy();
p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams());
p.set(KEY.RANDOM, new UniversalRandom(42));

Network n = new Network("AlreadyClosed", p)
.add(Network.createRegion("AlreadyClosed")
.add(Network.createLayer("AlreadyClosed", p)));

Layer<?> l = n.lookup("AlreadyClosed").lookup("AlreadyClosed");
l.using(new Connections());
l.using(p);

l.close();

try {
l.using(new Connections());

fail(); // Should fail here, disallowing "using" call on closed layer
}catch(Exception e) {
assertEquals(IllegalStateException.class, e.getClass());
assertEquals("Layer already \"closed\"", e.getMessage());
}

try {
l.using(p);

fail(); // Should fail here, disallowing "using" call on closed layer
}catch(Exception e) {
assertEquals(IllegalStateException.class, e.getClass());
assertEquals("Layer already \"closed\"", e.getMessage());
}
}

@Test
public void testNoName() {
Parameters p = Parameters.getAllDefaultParameters();

try {
new Network("", p)
.add(Network.createRegion("")
.add(Network.createLayer("", p)
.add(Sensor.create(
FileSensor::create,
SensorParams.create(
Keys::path, "", ResourceLocator.path("rec-center-hourly-small.csv"))))));

fail(); // Fails due to no name...
}catch(Exception e) {
assertEquals(IllegalStateException.class, e.getClass());
assertEquals("All Networks must have a name. Increases digestion, and overall happiness!",
e.getMessage());
}

try {
new Network("Name", p)
.add(Network.createRegion("")
.add(Network.createLayer("", p)
.add(Sensor.create(
FileSensor::create,
SensorParams.create(
Keys::path, "", ResourceLocator.path("rec-center-hourly-small.csv"))))));

fail(); // Fails due to no name on Region...
}catch(Exception e) {
assertEquals(IllegalArgumentException.class, e.getClass());
assertEquals("Name may not be null or empty. ...not that anyone here advocates name calling!",
e.getMessage());
}
}

@Test
public void testAddSensor() {
Parameters p = NetworkTestHarness.getParameters().copy();
p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams());
p.set(KEY.RANDOM, new UniversalRandom(42));

try {
PublisherSupplier supplier = PublisherSupplier.builder()
.addHeader("dayOfWeek")
.addHeader("int")
.addHeader("B").build();

Network n = new Network("Name", p)
.add(Network.createRegion("Name")
.add(Network.createLayer("Name", p)));

Layer<?> l = n.lookup("Name").lookup("Name");
l.add(Sensor.create(
ObservableSensor::create,
SensorParams.create(
Keys::obs, "", supplier)));

assertEquals(n, l.getNetwork());
assertTrue(l.getRegion() != null);

}catch(Exception e) {
e.printStackTrace();
}
}

@Test
public void testGetAllValues() {
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/org/numenta/nupic/network/NetworkTest.java
Expand Up @@ -450,7 +450,11 @@ public void onNext(Inference inf) {
});

network.halt();
try { network.lookup("r1").lookup("1").getLayerThread().join(3000); }catch(Exception e) { e.printStackTrace(); }
try {
network.lookup("r1").lookup("1").getLayerThread().join(3000);
// Add a little more wait time
Thread.sleep(3000);
}catch(Exception e) { e.printStackTrace(); }
network.restart();

Publisher newPub = network.getPublisher();
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/numenta/nupic/util/ConditionTest.java
@@ -0,0 +1,18 @@
package org.numenta.nupic.util;

import static org.junit.Assert.*;

import org.junit.Test;


public class ConditionTest {

@Test
public void testRqwAdapterReturnsFalse() {
Condition.Adapter<Object> adapter = new Condition.Adapter<>();
assertFalse(adapter.eval(1.0d));
assertFalse(adapter.eval(1));
assertFalse(adapter.eval(new Object()));
}

}

0 comments on commit 7d0f682

Please sign in to comment.