Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
Rather obscure error that occurred only with MixedModels and when the
point estimate was ‘mode’

Added a regression test to test_Stochastic.m
  • Loading branch information
Ben Vincent committed May 14, 2017
1 parent 95e8dc0 commit f527ccb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ddToolbox/Variables/Stochastic.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/test_Stochastic.m
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f527ccb

Please sign in to comment.