Java Code Examples for com.cedarsoftware.util.DeepEquals#deepEquals()

The following examples show how to use com.cedarsoftware.util.DeepEquals#deepEquals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PersistenceAPITest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testThreadedPublisher_TemporalMemoryNetwork() {
    Network network = createAndRunTestTemporalMemoryNetwork();
    Layer<?> l = network.lookup("r1").lookup("1");
    Connections cn = l.getConnections();
    
    SerialConfig config = new SerialConfig("testThreadedPublisher_TemporalMemoryNetwork", SerialConfig.SERIAL_TEST_DIR);
    PersistenceAPI api = Persistence.get(config);
    
    byte[] bytes = api.write(cn);
    Connections serializedConnections = api.read(bytes);
    
    Network network2 = createAndRunTestTemporalMemoryNetwork();
    Layer<?> l2 = network2.lookup("r1").lookup("1");
    Connections newCons = l2.getConnections();
    
    boolean b = DeepEquals.deepEquals(newCons, serializedConnections);
    deepCompare(newCons, serializedConnections);
    assertTrue(b);
}
 
Example 2
Source File: PersistenceAPITest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testThreadedPublisher_SpatialPoolerNetwork() {
    Network network = createAndRunTestSpatialPoolerNetwork(0, 6);
    Layer<?> l = network.lookup("r1").lookup("1");
    Connections cn = l.getConnections();
    
    SerialConfig config = new SerialConfig("testThreadedPublisher_SpatialPoolerNetwork", SerialConfig.SERIAL_TEST_DIR);
    PersistenceAPI api = Persistence.get(config);
    
    byte[] bytes = api.write(cn);
    //Serialize above Connections for comparison with same run but unserialized below...
    Connections serializedConnections = api.read(bytes);
    
    Network network2 = createAndRunTestSpatialPoolerNetwork(0, 6);
    Layer<?> l2 = network2.lookup("r1").lookup("1");
    Connections newCons = l2.getConnections();
    
    //Compare the two Connections (both serialized and regular runs) - should be equal
    boolean b = DeepEquals.deepEquals(newCons, serializedConnections);
    deepCompare(newCons, serializedConnections);
    assertTrue(b);
}
 
Example 3
Source File: PersistenceAPITest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testHTMSensor_DaysOfWeek() {
    Object[] n = { "some name", ResourceLocator.path("days-of-week.csv") };
    HTMSensor<File> sensor = (HTMSensor<File>)Sensor.create(
        FileSensor::create, SensorParams.create(Keys::path, n));

    Parameters p = getParameters();
    p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams());
    sensor.initEncoder(p);

    SerialConfig config = new SerialConfig("testHTMSensor_DaysOfWeek", SerialConfig.SERIAL_TEST_DIR);
    PersistenceAPI api = Persistence.get(config);
    
    byte[] bytes = api.write(sensor);
    HTMSensor<File> serializedSensor = api.read(bytes);

    boolean b = DeepEquals.deepEquals(serializedSensor, sensor);
    deepCompare(serializedSensor, sensor);
    assertTrue(b);
}
 
Example 4
Source File: PersistenceAPITest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testHTMSensor_HotGym() {
    Object[] n = { "some name", ResourceLocator.path("rec-center-hourly-small.csv") };
    HTMSensor<File> sensor = (HTMSensor<File>)Sensor.create(
        FileSensor::create, SensorParams.create(Keys::path, n));
    
    sensor.initEncoder(getTestEncoderParams());
    
    SerialConfig config = new SerialConfig("testHTMSensor_HotGym");
    PersistenceAPI api = Persistence.get(config);
    
    byte[] bytes = api.write(sensor);
    assertNotNull(bytes);
    assertTrue(bytes.length > 0);
    HTMSensor<File> serializedSensor = api.read(bytes);
    
    boolean b = DeepEquals.deepEquals(serializedSensor, sensor);
    deepCompare(serializedSensor, sensor);
    assertTrue(b);
}
 
Example 5
Source File: PersistenceAPITest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testSerializeObservableSensor() {
    PublisherSupplier supplier = PublisherSupplier.builder()
        .addHeader("dayOfWeek")
        .addHeader("darr")
        .addHeader("B").build();
    
    ObservableSensor<String[]> oSensor = new ObservableSensor<>(SensorParams.create(Keys::obs, new Object[] {"name", supplier}));
    
    SerialConfig config = new SerialConfig("testSerializeObservableSensor", SerialConfig.SERIAL_TEST_DIR);
    PersistenceAPI api = Persistence.get(config);
    
    byte[] bytes = api.write(oSensor);
    ObservableSensor<String[]> serializedOSensor = api.read(bytes);
    
    boolean b = DeepEquals.deepEquals(serializedOSensor, oSensor);
    deepCompare(serializedOSensor, oSensor);
    assertTrue(b);
}
 
Example 6
Source File: JvmAuthTokenProviderTest.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
private void assertToken(String token, String expectedToken, Map<String, Object> expectedAuth)
    throws IOException {
  assertTrue(token.startsWith("gauth|"));
  String jsonString = token.substring(6);
  Map<String, Object> map = JsonMapper.parseJson(jsonString);

  assertEquals(expectedToken, map.get("token"));

  Map<String, Object> auth = (Map)map.get("auth");
  DeepEquals.deepEquals(expectedAuth, auth);
}
 
Example 7
Source File: DockerPostgresDatabaseProvider.java    From embedded-database-spring-test with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    DatabaseConfig that = (DatabaseConfig) o;
    return tmpfsEnabled == that.tmpfsEnabled &&
            Objects.equals(dockerImage, that.dockerImage) &&
            Objects.equals(tmpfsOptions, that.tmpfsOptions) &&
            Objects.equals(initdbProperties, that.initdbProperties) &&
            Objects.equals(configProperties, that.configProperties) &&
            DeepEquals.deepEquals(customizers, that.customizers);
}
 
Example 8
Source File: Value.java    From gsc-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean cmp(Value o) {
    return DeepEquals.deepEquals(this, o);
}
 
Example 9
Source File: Value.java    From BlockchainWallet-Crypto with GNU General Public License v3.0 4 votes vote down vote up
public boolean cmp(Value o) {
    return DeepEquals.deepEquals(this, o);
}
 
Example 10
Source File: Parameters.java    From htm.java with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This implementation skips over any native comparisons (i.e. "==")
 * because their hashcodes will not be equal.
 */
@Override
public boolean equals(Object obj) {
    if(this == obj)
        return true;
    if(obj == null)
        return false;
    if(getClass() != obj.getClass())
        return false;
    Parameters other = (Parameters)obj;
    if(paramMap == null) {
        if(other.paramMap != null)
            return false;
    } else {
        Class<?>[] classArray = new Class[] { Object.class };
        try {
            for(KEY key : paramMap.keySet()) {
                if(paramMap.get(key) == null || other.paramMap.get(key) == null) continue;
                
                Class<?> thisValueClass = paramMap.get(key).getClass();
                Class<?> otherValueClass = other.paramMap.get(key).getClass();
                boolean isSpecial = isSpecial(key, thisValueClass);
                if(!isSpecial && (thisValueClass.getMethod("equals", classArray).getDeclaringClass() != thisValueClass ||
                    otherValueClass.getMethod("equals", classArray).getDeclaringClass() != otherValueClass)) {
                        continue;
                }else if(isSpecial) {
                    if(int[].class.isAssignableFrom(thisValueClass)) {
                        if(!Arrays.equals((int[])paramMap.get(key), (int[])other.paramMap.get(key))) return false;
                    }else if(key == KEY.FIELD_ENCODING_MAP) {
                        if(!DeepEquals.deepEquals(paramMap.get(key), other.paramMap.get(key))) {
                            return false;
                        }
                    }
                }else if(!other.paramMap.containsKey(key) || !paramMap.get(key).equals(other.paramMap.get(key))) {
                    return false;
                }
            }
        }catch(Exception e) { return false; }
    }
    return true;
}
 
Example 11
Source File: Value.java    From ethereumj with MIT License 4 votes vote down vote up
public boolean cmp(Value o) {
    return DeepEquals.deepEquals(this, o);
}