Skip to content

Commit

Permalink
Update tests for science and HK for cropping
Browse files Browse the repository at this point in the history
  • Loading branch information
mfacchinelli committed Feb 1, 2024
1 parent c6d80e0 commit abdffbb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/data/+mag/HK.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ function crop(this, timeFilter)

this(i).Data = this(i).Data(timeFilter, :);

if ~isempty(this(i).Time)
if isempty(this(i).Time)
this(i).MetaData.Timestamp = NaT(TimeZone = mag.process.DateTime.TimeZone);
else
this(i).MetaData.Timestamp = this(i).Time(1);
end
end
Expand Down
4 changes: 3 additions & 1 deletion src/data/+mag/Science.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ function crop(this, timeFilter)
this.Data.Properties.Events = this.Data.Properties.Events(timePeriod, :);
end

if ~isempty(this.Time)
if isempty(this.Time)
this.MetaData.Timestamp = NaT(TimeZone = mag.process.DateTime.TimeZone);
else
this.MetaData.Timestamp = this.Time(1);
end
end
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/data/tHK.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ function cropMethod_timerange(testCase)
testCase.cropAndVerify(data, timeFilter, expectedTimes, expectedData);
end

% Test that "crop" method does not fail when no data is selected.
function cropMethod_noSelection(testCase)

% Set up.
data = testCase.createTestData();

% Exercise.
data.crop(timerange(datetime("Inf", TimeZone = "local"), datetime("-Inf", TimeZone = "local")));

% Verify.
for i = 1:numel(data)

testCase.verifyEmpty(data(i).IndependentVariable, "All data should be cropped out.");
testCase.verifyEmpty(data(i).DependentVariables, "All data should be cropped out.");

testCase.verifyTrue(ismissing(data(i).MetaData.Timestamp), "All data should be cropped out.");
end
end

% Test that "resample" method can resample to a higher frequency.
function resampleMethod_higherFrequency(testCase)

Expand Down
18 changes: 17 additions & 1 deletion tests/unit/data/tScience.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ function cropMethod_events(testCase)
testCase.verifyEqual(data.Events.Time, data.Time, "Data should be cropped as expected.");
end

% Test that "crop" method does not fail when no data is selected.
function cropMethod_noSelection(testCase)

% Set up.
data = testCase.createTestData();

% Exercise.
data.crop(timerange(datetime("Inf", TimeZone = "local"), datetime("-Inf", TimeZone = "local")));

% Verify.
testCase.verifyEmpty(data.IndependentVariable, "All data should be cropped out.");
testCase.verifyEmpty(data.DependentVariables, "All data should be cropped out.");

testCase.verifyTrue(ismissing(data.MetaData.Timestamp), "All data should be cropped out.");
end

% Test that "resample" method can resample to a lower frequency.
function resampleMethod_lowerFrequency(testCase)

Expand Down Expand Up @@ -189,7 +205,7 @@ function cropAndVerify(testCase, data, timeFilter, expectedTimes, expectedData)
function [data, rawData] = createTestData()

rawData = timetable(datetime("now", TimeZone = "UTC") + minutes(1:10)', (1:10)', (11:20)', (21:30)', 3 * ones(10, 1), (1:10)', VariableNames = ["x", "y", "z", "range", "sequence"]);
data = mag.Science(rawData, mag.meta.Science());
data = mag.Science(rawData, mag.meta.Science(Timestamp = datetime("now", TimeZone = "UTC")));
end
end
end

0 comments on commit abdffbb

Please sign in to comment.