MCMCResultsMemoryUsageModel extends AbstractValueModel implements MCMCResultsListener { public String getValue() { NumberFormat format = new DecimalFormat("0.0"); if(d_results.getNumberOfSamples() > 0) { if(getKiloByteSize() < 100) { return format.format(getKiloByteSize()) + " KB"; } return format.format(getKiloByteSize() / 1000.0) + " MB"; } return "0.0 KB"; } MCMCResultsMemoryUsageModel(MCMCResults results); String getValue(); void setValue(Object newValue); void resultsEvent(MCMCResultsEvent event);  }
@Test public void testInitialValueEmpty() { MCMCResultsMemoryUsageModel model = new MCMCResultsMemoryUsageModel(d_results); assertEquals("0.0 KB", model.getValue()); }
@Test public void testInitialValueFull() { d_results.makeSamplesAvailable(); MCMCResultsMemoryUsageModel model = new MCMCResultsMemoryUsageModel(d_results); assertEquals("0.7 MB", model.getValue()); }
@Test public void testInitialValueOther() { FakeResults results = new FakeResults(3, 100, 3); MCMCResultsMemoryUsageModel model = new MCMCResultsMemoryUsageModel(results); assertEquals("7.2 KB", model.getValue()); }
@Test public void testInitialValueLarge() { MCMCResults results = new FakeResults(3, 100 * 1000, 3); MCMCResultsMemoryUsageModel model = new MCMCResultsMemoryUsageModel(results); assertEquals("7.2 MB", model.getValue()); }
@Test public void testInitialValueVeryLarge() { MCMCResults results = new FakeResults(3, 1000 * 1000 * 10, 3); MCMCResultsMemoryUsageModel model = new MCMCResultsMemoryUsageModel(results); assertEquals("720.0 MB", model.getValue()); }
@Test public void testInitialValueTiny() { MCMCResults results = new FakeResults(3, 1, 3); MCMCResultsMemoryUsageModel model = new MCMCResultsMemoryUsageModel(results); assertEquals("0.1 KB", model.getValue()); }
@Test public void testValueUpdate() { MCMCResultsMemoryUsageModel model = new MCMCResultsMemoryUsageModel(d_results); PropertyChangeListener listener = JUnitUtil.mockStrictListener(model, "value", null, "0.7 MB"); model.addValueChangeListener(listener); d_results.makeSamplesAvailable(); assertEquals("0.7 MB", model.getValue()); EasyMock.verify(listener); }