Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Vincent committed May 14, 2017
1 parent 229d050 commit 95e8dc0
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 67 deletions.
2 changes: 1 addition & 1 deletion ddToolbox/Data/Data.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
% user supplied metaTable
if ~isempty(p.Results.metaTable)
% Check 1: metaTable must have Row names equal to those in files
assert(numel(p.Results.metaTable.Row) == numel(p.Results.files),...
assert(numel(p.Results.metaTable.Properties.RowNames) == numel(p.Results.files),...
'metaTable must have same number of rows as number of files passed in')
% Check 2: they actually match up
warning('Implement this validation check for extra safety.')
Expand Down
16 changes: 16 additions & 0 deletions demo/datasets/test_data/kirby-experiment-data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
filename,id
AC-kirby27.txt,AC
BL-kirby27.txt,BL
bv-kirby27.txt,BV
CS-kirby27.txt,CS
EP-kirby27.txt,EP
JR-kirby27.txt,JR
KA-kirby27.txt,KA
LJ-kirby27.txt,LJ
LY-kirby27.txt,LY
NA-kirby27.txt,NA
rm-kirby27.txt,RM
SB-kirby27.txt,SB
SK-kirby27.txt,SK
VD-kirby27.txt,VD
vs-kirby27.txt,VS
4 changes: 2 additions & 2 deletions tests/getAllParametricModelNames.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'ModelHierarchicalLogK', 'ModelMixedLogK', 'ModelSeparateLogK',...
'ModelHierarchicalHyperboloid', 'ModelMixedHyperboloid', 'ModelSeparateHyperboloid',...
'ModelHierarchicalExp1', 'ModelMixedExp1', 'ModelSeparateExp1',...
'ModelSeparateExpPower', 'ModelMixedExpPower', 'ModelHierarchicalExpPower',...
'ModelSeparateEbertPrelec', 'ModelMixedEbertPrelec'};
'ModelSeparateExpPower', 'ModelMixedExpPower',... % no hierarchical model
'ModelSeparateEbertPrelec', 'ModelMixedEbertPrelec'}; % no hierarchical model
warning('temp removed ExpPower models from consideration... they are dealt with elsewhere')
end
32 changes: 16 additions & 16 deletions tests/test_DF_Hyperbolic1.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

methods (Test, TestTags = {'Unit'})

function scalarInput(testCase)
% evaluate with these paraams
logk = 1/365;
delay = 365;
expected_discount_fraction = 0.5;

% construct discount function object
my_func = DF_Hyperbolic1('samples', struct('logk', logk) );

testCase.verifyEqual(...
my_func.eval(delay),...
expected_discount_fraction,...
'RelTol', 0.0001)

end
% TODO: update this test as I changed the API

% function scalarInput(testCase)
% % evaluate with these paraams
% logk = 1/365;
% delay = 365;
% expected_discount_fraction = 0.5;
%
% % construct discount function object
% my_func = DF_Hyperbolic1('samples', struct('logk', logk) );
%
% testCase.verifyEqual(...
% my_func.eval(delay),...
% expected_discount_fraction,...
% 'RelTol', 0.0001)
% end

end
end
4 changes: 2 additions & 2 deletions tests/test_Data.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ function create_without_experiment_info(testCase)
function create_with_experiment_info_import_table(testCase)
data = Data(testCase.datapath,...
'files', testCase.filesToAnalyse,...
'metaTableFile', fullfile('tests','kirby-experiment-data.csv'));
'metaTableFile', fullfile('demo','datasets','test_data','kirby-experiment-data.csv'));
end

function create_with_experiment_info_provided_table(testCase)
% build a Table. It must have row names equal to the filenames
expTable = readtable(fullfile('tests','kirby-experiment-data.csv'));
expTable = readtable(fullfile('demo','datasets','test_data','kirby-experiment-data.csv'));
expTable.Properties.RowNames = expTable.filename;

data = Data(testCase.datapath,...
Expand Down
83 changes: 37 additions & 46 deletions tests/test_PlotAllModels.m
Original file line number Diff line number Diff line change
@@ -1,80 +1,71 @@
classdef test_PlotAllModels < matlab.unittest.TestCase

properties
data
savePath = tempname(); % matlab auto-generated temp folders
end

properties (TestParameter)
% model = {'ModelHierarchicalME_MVNORM',...
% 'ModelHierarchicalME',...
% 'ModelHierarchicalMEUpdated',...
% 'ModelMixedME',...
% 'ModelSeparateME',...
% 'ModelHierarchicalLogK',...
% 'ModelMixedLogK',...
% 'ModelSeparateLogK',...
% 'ModelSeparateNonParametric',...
% 'ModelHierarchicalExp1', 'ModelMixedExp1', 'ModelSeparateExp1'}
model = getAllParametricModelNames;
pointEstimateType = {'mean','median','mode'}
model = getAllParametricModelNames;
pointEstimateType = {'mean','median','mode'};
dataset = {'kirby', 'non_parametric'};
chains = {2,3}
end

%% CLASS-LEVEL SETUP/TEARDOWN -----------------------------------------
methods (TestClassSetup)
function setup(testCase)
% assuming this is running on my maching
addpath('~/git-local/delay-discounting-analysis/ddToolbox')
%datapath = '~/git-local/delay-discounting-analysis/demo/datasets/kirby';
datapath = '~/git-local/delay-discounting-analysis/demo/datasets/non_parametric';

% only analyse 2 people, for speed of running tests
filesToAnalyse = allFilesInFolder(datapath, 'txt');
filesToAnalyse = filesToAnalyse(1:2);

testCase.data = Data(datapath, 'files', filesToAnalyse);
end
end


% methods (TestClassSetup)
% function setup(testCase)
% end
% end


methods(TestClassTeardown)

function remove_temp_directory(testCase)
rmdir(testCase.savePath,'s')
end

function delete_stan_related_outputs(testCase)
delete('*.data.R')
delete('*.csv')
end

function close_figures(testCase)
close all
end

end


%% THE ACTUAL TESTS ---------------------------------------------------

methods (Test)

function plot(testCase, model)
% make model

function plot(testCase, model, dataset)

%% Set up data
datapath = ['~/git-local/delay-discounting-analysis/demo/datasets/' dataset];
% assuming this is running on my maching
addpath('~/git-local/delay-discounting-analysis/ddToolbox')
% only analyse 2 people, for speed of running tests
filesToAnalyse = allFilesInFolder(datapath, 'txt');
filesToAnalyse = filesToAnalyse(1:2);
testCase.data = Data(datapath, 'files', filesToAnalyse);

%% Run model
makeModelFunction = str2func(model);
model = makeModelFunction(testCase.data,...
'savePath', testCase.savePath,...
'shouldPlot','yes',...
'shouldExportPlots', false,...
'mcmcParams', struct('nsamples', 1000,...
'nchains', 2,...
'nburnin', 1000));
'nchains', 2,...
'nburnin', 1000));
%model.plot();

% TODO: DO AN ACTUAL TEST HERE !!!!!!!!!!!!!!!!!!!!!!
end

end

end

0 comments on commit 95e8dc0

Please sign in to comment.