ProxyMultivariateNormalSummary extends AbstractObservable implements MultivariateNormalSummary { public void setNested(MultivariateNormalSummary summary) { boolean wasDefined = getDefined(); if (d_nested != null) { d_nested.removePropertyChangeListener(d_listener); } d_nested = summary; if (d_nested != null) { d_nested.addPropertyChangeListener(d_listener); } if (wasDefined != getDefined()) { firePropertyChange(PROPERTY_DEFINED, wasDefined, getDefined()); } if (getDefined() || wasDefined) { firePropertyChange(PROPERTY_MEAN_VECTOR, null, getDefined() ? getMeanVector() : null); firePropertyChange(PROPERTY_COVARIANCE_MATRIX, null, getDefined() ? getCovarianceMatrix() : null); } }  boolean getDefined(); double[] getMeanVector(); double[][] getCovarianceMatrix(); void setNested(MultivariateNormalSummary summary);  }
@Test public void testSetNested() { d_summary.setNested(new SimpleMultivariateNormalSummary(new double[]{0, 0}, new double[][]{ {1, 1}, {0, 1} })); assertTrue(d_summary.getDefined()); assertArrayEquals(new double[]{0, 0}, d_summary.getMeanVector(), EPSILON); assertArrayEquals(new double[]{1, 1}, d_summary.getCovarianceMatrix()[0], EPSILON); assertArrayEquals(new double[]{0, 1}, d_summary.getCovarianceMatrix()[1], EPSILON); }
@Test public void testEventPropagation() throws IOException { ExampleResults results = new ExampleResults(); MultivariateNormalSummary summary = new MCMCMultivariateNormalSummary(results, results.getParameters()); d_summary.setNested(summary); PropertyChangeListener listener = createStrictMock(PropertyChangeListener.class); listener.propertyChange(JUnitUtil.eqPropertyChangeEvent( new PropertyChangeEvent(d_summary, Summary.PROPERTY_DEFINED, false, true))); listener.propertyChange(JUnitUtil.eqPropertyChangeEventIgnoreValues( new PropertyChangeEvent(d_summary, MultivariateNormalSummary.PROPERTY_MEAN_VECTOR, null, null))); listener.propertyChange(JUnitUtil.eqPropertyChangeEventIgnoreValues( new PropertyChangeEvent(d_summary, MultivariateNormalSummary.PROPERTY_COVARIANCE_MATRIX, null, null))); replay(listener); d_summary.addPropertyChangeListener(listener); results.makeSamplesAvailable(); verify(listener); }
@Test public void testRemoveListener() throws IOException { ExampleResults results = new ExampleResults(); MultivariateNormalSummary summary = new MCMCMultivariateNormalSummary(results, results.getParameters()); d_summary.setNested(summary); d_summary.setNested(new SimpleMultivariateNormalSummary(new double[]{0}, new double[][]{ {1} })); PropertyChangeListener listener = createStrictMock(PropertyChangeListener.class); replay(listener); d_summary.addPropertyChangeListener(listener); results.makeSamplesAvailable(); verify(listener); }
@Test public void testSetNestedEvents() throws IOException { ExampleResults results = new ExampleResults(); results.makeSamplesAvailable(); MultivariateNormalSummary summary = new MCMCMultivariateNormalSummary(results, results.getParameters()); PropertyChangeListener listener = createStrictMock(PropertyChangeListener.class); listener.propertyChange(JUnitUtil.eqPropertyChangeEvent( new PropertyChangeEvent(d_summary, Summary.PROPERTY_DEFINED, false, true))); listener.propertyChange(JUnitUtil.eqPropertyChangeEventIgnoreValues( new PropertyChangeEvent(d_summary, MultivariateNormalSummary.PROPERTY_MEAN_VECTOR, null, null))); listener.propertyChange(JUnitUtil.eqPropertyChangeEventIgnoreValues( new PropertyChangeEvent(d_summary, MultivariateNormalSummary.PROPERTY_COVARIANCE_MATRIX, null, null))); replay(listener); d_summary.addPropertyChangeListener(listener); d_summary.setNested(summary); verify(listener); }
@Test public void testSetNestedEventsUndefined() throws IOException { ExampleResults results = new ExampleResults(); MultivariateNormalSummary summary = new MCMCMultivariateNormalSummary(results, results.getParameters()); PropertyChangeListener listener = createStrictMock(PropertyChangeListener.class); replay(listener); d_summary.addPropertyChangeListener(listener); d_summary.setNested(summary); d_summary.setNested(null); verify(listener); }
@Test public void testSetNestedEventsUndefined2() throws IOException { ExampleResults results = new ExampleResults(); MultivariateNormalSummary summary = new MCMCMultivariateNormalSummary(results, results.getParameters()); d_summary.setNested(new SimpleMultivariateNormalSummary(new double[]{0}, new double[][]{ {1} })); PropertyChangeListener listener = createStrictMock(PropertyChangeListener.class); listener.propertyChange(JUnitUtil.eqPropertyChangeEvent( new PropertyChangeEvent(d_summary, Summary.PROPERTY_DEFINED, true, false))); listener.propertyChange(JUnitUtil.eqPropertyChangeEvent( new PropertyChangeEvent(d_summary, MultivariateNormalSummary.PROPERTY_MEAN_VECTOR, null, null))); listener.propertyChange(JUnitUtil.eqPropertyChangeEvent( new PropertyChangeEvent(d_summary, MultivariateNormalSummary.PROPERTY_COVARIANCE_MATRIX, null, null))); replay(listener); d_summary.addPropertyChangeListener(listener); d_summary.setNested(summary); verify(listener); }