Skip to content

Commit 7d0f682

Browse files
authored
Merge pull request #503 from cogmission/gradle_build_fix
Gradle build fix
2 parents 07e5c23 + 3880652 commit 7d0f682

File tree

7 files changed

+181
-4
lines changed

7 files changed

+181
-4
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ apply plugin: 'eclipse'
44
apply plugin: 'signing'
55

66
group = 'org.numenta'
7-
version = '0.6.10'
7+
version = '0.6.11'
88
archivesBaseName = 'htm.java'
99

1010
sourceCompatibility = 1.8
1111
targetCompatibility = 1.8
1212

1313
jar {
1414
manifest {
15-
attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.9-SNAPSHOT'
15+
attributes 'Implementation-Title': 'htm.java', 'Implementation-Version': '0.6.11'
1616
}
1717
}
1818

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.numenta</groupId>
66
<artifactId>htm.java</artifactId>
7-
<version>0.6.10</version>
7+
<version>0.6.11</version>
88
<name>htm.java</name>
99
<description>The Java version of Numenta's HTM technology</description>
1010

src/main/java/org/numenta/nupic/network/Layer.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ public Layer<T> postDeSerialize() {
344344
public void setNetwork(Network network) {
345345
this.parentNetwork = network;
346346
}
347+
348+
/**
349+
* Returns the parent {@link Network}
350+
* @return the parent Network;
351+
*/
352+
public Network getNetwork() {
353+
return this.parentNetwork;
354+
}
347355

348356
/**
349357
* Creates a new {@code Layer} initialized with the specified algorithmic
@@ -415,6 +423,15 @@ public CheckPointOp<byte[]> delegateCheckPointCall() {
415423
public void setRegion(Region r) {
416424
this.parentRegion = r;
417425
}
426+
427+
/**
428+
* Returns the parent {@link Region}
429+
*
430+
* @return the parent Region
431+
*/
432+
public Region getRegion() {
433+
return this.parentRegion;
434+
}
418435

419436
/**
420437
* Finalizes the initialization in one method call so that side effect
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.numenta.nupic.datagen;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertNotNull;
6+
import static org.junit.Assert.fail;
7+
8+
import java.net.URI;
9+
10+
import org.junit.Test;
11+
12+
13+
public class ResourceLocatorTest {
14+
15+
@Test
16+
public void testURICreation() {
17+
try {
18+
ResourceLocator.uri(".");
19+
fail();
20+
}catch(Exception e) {
21+
assertEquals(IllegalStateException.class, e.getClass());
22+
assertEquals(java.net.MalformedURLException.class, e.getCause().getClass());
23+
}
24+
25+
try {
26+
URI uri = ResourceLocator.uri("file:///.");
27+
assertNotNull(uri);
28+
29+
assertFalse(uri.isOpaque());
30+
}catch(Exception e) {
31+
fail();
32+
}
33+
}
34+
35+
}

src/test/java/org/numenta/nupic/network/LayerTest.java

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.numenta.nupic.algorithms.TemporalMemory;
4949
import org.numenta.nupic.datagen.ResourceLocator;
5050
import org.numenta.nupic.encoders.MultiEncoder;
51+
import org.numenta.nupic.model.Connections;
5152
import org.numenta.nupic.model.SDR;
5253
import org.numenta.nupic.network.Layer.FunctionFactory;
5354
import org.numenta.nupic.network.sensor.FileSensor;
@@ -111,6 +112,108 @@ public void testMasking() {
111112
algo_content_mask ^= Layer.CLA_CLASSIFIER;
112113
assertEquals(0, algo_content_mask);
113114
}
115+
116+
@Test
117+
public void callsOnClosedLayer() {
118+
Parameters p = NetworkTestHarness.getParameters().copy();
119+
p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams());
120+
p.set(KEY.RANDOM, new UniversalRandom(42));
121+
122+
Network n = new Network("AlreadyClosed", p)
123+
.add(Network.createRegion("AlreadyClosed")
124+
.add(Network.createLayer("AlreadyClosed", p)));
125+
126+
Layer<?> l = n.lookup("AlreadyClosed").lookup("AlreadyClosed");
127+
l.using(new Connections());
128+
l.using(p);
129+
130+
l.close();
131+
132+
try {
133+
l.using(new Connections());
134+
135+
fail(); // Should fail here, disallowing "using" call on closed layer
136+
}catch(Exception e) {
137+
assertEquals(IllegalStateException.class, e.getClass());
138+
assertEquals("Layer already \"closed\"", e.getMessage());
139+
}
140+
141+
try {
142+
l.using(p);
143+
144+
fail(); // Should fail here, disallowing "using" call on closed layer
145+
}catch(Exception e) {
146+
assertEquals(IllegalStateException.class, e.getClass());
147+
assertEquals("Layer already \"closed\"", e.getMessage());
148+
}
149+
}
150+
151+
@Test
152+
public void testNoName() {
153+
Parameters p = Parameters.getAllDefaultParameters();
154+
155+
try {
156+
new Network("", p)
157+
.add(Network.createRegion("")
158+
.add(Network.createLayer("", p)
159+
.add(Sensor.create(
160+
FileSensor::create,
161+
SensorParams.create(
162+
Keys::path, "", ResourceLocator.path("rec-center-hourly-small.csv"))))));
163+
164+
fail(); // Fails due to no name...
165+
}catch(Exception e) {
166+
assertEquals(IllegalStateException.class, e.getClass());
167+
assertEquals("All Networks must have a name. Increases digestion, and overall happiness!",
168+
e.getMessage());
169+
}
170+
171+
try {
172+
new Network("Name", p)
173+
.add(Network.createRegion("")
174+
.add(Network.createLayer("", p)
175+
.add(Sensor.create(
176+
FileSensor::create,
177+
SensorParams.create(
178+
Keys::path, "", ResourceLocator.path("rec-center-hourly-small.csv"))))));
179+
180+
fail(); // Fails due to no name on Region...
181+
}catch(Exception e) {
182+
assertEquals(IllegalArgumentException.class, e.getClass());
183+
assertEquals("Name may not be null or empty. ...not that anyone here advocates name calling!",
184+
e.getMessage());
185+
}
186+
}
187+
188+
@Test
189+
public void testAddSensor() {
190+
Parameters p = NetworkTestHarness.getParameters().copy();
191+
p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams());
192+
p.set(KEY.RANDOM, new UniversalRandom(42));
193+
194+
try {
195+
PublisherSupplier supplier = PublisherSupplier.builder()
196+
.addHeader("dayOfWeek")
197+
.addHeader("int")
198+
.addHeader("B").build();
199+
200+
Network n = new Network("Name", p)
201+
.add(Network.createRegion("Name")
202+
.add(Network.createLayer("Name", p)));
203+
204+
Layer<?> l = n.lookup("Name").lookup("Name");
205+
l.add(Sensor.create(
206+
ObservableSensor::create,
207+
SensorParams.create(
208+
Keys::obs, "", supplier)));
209+
210+
assertEquals(n, l.getNetwork());
211+
assertTrue(l.getRegion() != null);
212+
213+
}catch(Exception e) {
214+
e.printStackTrace();
215+
}
216+
}
114217

115218
@Test
116219
public void testGetAllValues() {

src/test/java/org/numenta/nupic/network/NetworkTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,11 @@ public void onNext(Inference inf) {
450450
});
451451

452452
network.halt();
453-
try { network.lookup("r1").lookup("1").getLayerThread().join(3000); }catch(Exception e) { e.printStackTrace(); }
453+
try {
454+
network.lookup("r1").lookup("1").getLayerThread().join(3000);
455+
// Add a little more wait time
456+
Thread.sleep(3000);
457+
}catch(Exception e) { e.printStackTrace(); }
454458
network.restart();
455459

456460
Publisher newPub = network.getPublisher();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.numenta.nupic.util;
2+
3+
import static org.junit.Assert.*;
4+
5+
import org.junit.Test;
6+
7+
8+
public class ConditionTest {
9+
10+
@Test
11+
public void testRqwAdapterReturnsFalse() {
12+
Condition.Adapter<Object> adapter = new Condition.Adapter<>();
13+
assertFalse(adapter.eval(1.0d));
14+
assertFalse(adapter.eval(1));
15+
assertFalse(adapter.eval(new Object()));
16+
}
17+
18+
}

0 commit comments

Comments
 (0)