From f527ccb2b83e858a967f7293457f759715212745 Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sun, 14 May 2017 18:51:43 +0100 Subject: [PATCH] bug fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather obscure error that occurred only with MixedModels and when the point estimate was ‘mode’ Added a regression test to test_Stochastic.m --- ddToolbox/Variables/Stochastic.m | 4 ++-- tests/test_Stochastic.m | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/test_Stochastic.m diff --git a/ddToolbox/Variables/Stochastic.m b/ddToolbox/Variables/Stochastic.m index 16121605..d90be719 100644 --- a/ddToolbox/Variables/Stochastic.m +++ b/ddToolbox/Variables/Stochastic.m @@ -205,8 +205,8 @@ function panOptions(obj) function obj = calculateModeAndDensity(obj) if any(isnan(obj.samples)) - obj.mode = []; - obj.density = []; + obj.mode = NaN; + obj.density = NaN; else obj.xi = linspace( min(obj.samples(:)), max(obj.samples(:)), 1000); obj.xi = [obj.xi(1) obj.xi obj.xi(end)]; % fix to avoid plotting artifacts diff --git a/tests/test_Stochastic.m b/tests/test_Stochastic.m new file mode 100644 index 00000000..fa6d37c5 --- /dev/null +++ b/tests/test_Stochastic.m @@ -0,0 +1,19 @@ +classdef test_Stochastic < matlab.unittest.TestCase + + properties + end + + methods (Test, TestTags = {'Unit'}) + + function check_mode_is_NaN_when_NaN_samples_provided(testCase) + % when we provide NaN as samples to a Stochastic object, check + % we set obj.mode as NaN + univariateObject = Stochastic('testVariable'); + samples = NaN; + univariateObject.addSamples(samples); + + testCase.verifyEqual( univariateObject.mode, NaN ) + end + + end +end \ No newline at end of file