-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert to format understood by runtests
- Loading branch information
1 parent
7e62e39
commit a72e174
Showing
3 changed files
with
251 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,151 @@ | ||
function test_IntervalArray() | ||
% Test constructor | ||
myIntervalArray = IntervalArray([0,5;10,15]); | ||
assert(isequal(myIntervalArray.intervals,[0,5;10,15]),'Error: constructor not working'); | ||
|
||
% Test validate_intervals | ||
myIntervalArray.intervals = [10,5;10,15]; | ||
try | ||
myIntervalArray.validate_intervals(); | ||
error('Error: validate_intervals not working') | ||
catch | ||
end | ||
|
||
% Test sort | ||
myIntervalArray.intervals = [10,15;0,5]; | ||
myIntervalArray.sort(); | ||
assert(isequal(myIntervalArray.intervals,[0,5;10,15]),'Error: sort not working'); | ||
|
||
% Test starts | ||
assert(isequal(myIntervalArray.starts(),[0;10]),'Error: starts not working'); | ||
|
||
% Test stops | ||
assert(isequal(myIntervalArray.stops(),[5;15]),'Error: stops not working'); | ||
|
||
% Test n_intervals | ||
assert(isequal(myIntervalArray.n_intervals(),2),'Error: n_intervals not working'); | ||
|
||
% Test expand | ||
myIntervalArray = myIntervalArray.expand(1); | ||
assert(isequal(myIntervalArray.intervals,[-1,6;9,16]),'Error: expand not working'); | ||
|
||
% Test isempty | ||
assert(isequal(myIntervalArray.isempty(),false),'Error: isempty not working'); | ||
|
||
% Test lengths | ||
assert(isequal(myIntervalArray.lengths(),[7;7]),'Error: lengths not working'); | ||
|
||
% Test duration | ||
assert(isequal(myIntervalArray.duration(),14),'Error: duration not working'); | ||
|
||
% Test intersect | ||
otherIntervalArray = IntervalArray([-2,2;8,12]); | ||
myIntervalArray = myIntervalArray.intersect(otherIntervalArray); | ||
assert(isequal(myIntervalArray.intervals,[-1,2;9,12]),'Error: intersect not working'); | ||
|
||
% Test union | ||
otherIntervalArray = IntervalArray([-2,2;8,12]); | ||
myIntervalArray = myIntervalArray.union(otherIntervalArray); | ||
assert(isequal(myIntervalArray.intervals,[-2,2;8,12]),'Error: union not working'); | ||
|
||
% Test setdiff | ||
otherIntervalArray = IntervalArray([-2,2;18,20]); | ||
myIntervalArray = myIntervalArray.setdiff(otherIntervalArray); | ||
assert(isequal(myIntervalArray.intervals,[8,12]),'Error: setdiff not working'); | ||
|
||
% Test complement | ||
myIntervalArray = myIntervalArray.complement(); | ||
assert(isequal(myIntervalArray.intervals,[-inf,8;12,inf]),'Error: complement not working'); | ||
|
||
% Test merge | ||
myIntervalArray = IntervalArray([10,20;15,25]); | ||
myIntervalArray = myIntervalArray.merge(); | ||
assert(isequal(myIntervalArray.intervals,[10,25]),'Error: merge not working'); | ||
|
||
% Test plus | ||
otherIntervalArray = IntervalArray([-2,2;8,12]); | ||
myIntervalArray = myIntervalArray.plus(otherIntervalArray); | ||
assert(isequal(myIntervalArray.intervals,[-2,2;8,12;10,25]),'Error: plus not working'); | ||
|
||
% Test remove_empty | ||
myIntervalArray = IntervalArray([0,2;5,5;8,12]); | ||
myIntervalArray = myIntervalArray.remove_empty(); | ||
assert(isequal(myIntervalArray.intervals,[0,2;8,12]),'Error: remove_empty not working'); | ||
|
||
% Test eq | ||
myIntervalArray = IntervalArray([0,2;8,12]); | ||
otherIntervalArray = IntervalArray([0,2;8,12]); | ||
is_equal = myIntervalArray.eq(otherIntervalArray); | ||
assert(isequal(is_equal,true),'Error: eq not working'); | ||
|
||
% Test in | ||
myIntervalArray = IntervalArray([0,2;8,12]); | ||
point = 9; | ||
contain = myIntervalArray.in(point); | ||
assert(isequal(contain,true),'Error: in not working'); | ||
|
||
% Test empty interval | ||
myIntervalArray = IntervalArray([]); | ||
assert(isequal(myIntervalArray.isempty,true),'Error: empty intervals not working'); | ||
end | ||
function tests = test_IntervalArray | ||
% Create a test suite for the IntervalArray class | ||
tests = functiontests(localfunctions); | ||
end | ||
|
||
function testConstructor(testCase) | ||
% Test constructor | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
verifyEqual(testCase, myIntervalArray.intervals, [0, 5; 10, 15], 'Error: constructor not working'); | ||
end | ||
|
||
function testValidateIntervals(testCase) | ||
% Test validate_intervals | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
myIntervalArray.intervals = [10, 5; 10, 15]; | ||
% Try to validate intervals and catch any error | ||
try | ||
myIntervalArray.validate_intervals(); | ||
% If no error is thrown, the test should fail | ||
testCase.verifyFail('Expected an error but did not receive one.'); | ||
catch ME | ||
% Check if the caught error message is the expected one | ||
testCase.verifyEqual(ME.message, 'Invalid intervals: start time must be less than end time', ... | ||
'Error: validate_intervals did not throw the expected message.'); | ||
end | ||
end | ||
|
||
function testSort(testCase) | ||
% Test sort | ||
myIntervalArray = IntervalArray([10, 15; 0, 5]); | ||
myIntervalArray.sort(); | ||
verifyEqual(testCase, myIntervalArray.intervals, [0, 5; 10, 15], 'Error: sort not working'); | ||
end | ||
|
||
function testStarts(testCase) | ||
% Test starts | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
verifyEqual(testCase, myIntervalArray.starts(), [0; 10], 'Error: starts not working'); | ||
end | ||
|
||
function testStops(testCase) | ||
% Test stops | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
verifyEqual(testCase, myIntervalArray.stops(), [5; 15], 'Error: stops not working'); | ||
end | ||
|
||
function testNIntervals(testCase) | ||
% Test n_intervals | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
verifyEqual(testCase, myIntervalArray.n_intervals(), 2, 'Error: n_intervals not working'); | ||
end | ||
|
||
function testExpand(testCase) | ||
% Test expand | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
myIntervalArray = myIntervalArray.expand(1); | ||
verifyEqual(testCase, myIntervalArray.intervals, [-1, 6; 9, 16], 'Error: expand not working'); | ||
end | ||
|
||
function testIsEmpty(testCase) | ||
% Test isempty | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
verifyEqual(testCase, myIntervalArray.isempty(), false, 'Error: isempty not working'); | ||
end | ||
|
||
function testLengths(testCase) | ||
% Test lengths | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
verifyEqual(testCase, myIntervalArray.lengths(), [5; 5], 'Error: lengths not working'); | ||
end | ||
|
||
function testDuration(testCase) | ||
% Test duration | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
verifyEqual(testCase, myIntervalArray.duration(), 10, 'Error: duration not working'); | ||
end | ||
|
||
function testIntersect(testCase) | ||
% Test intersect | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
otherIntervalArray = IntervalArray([-2, 2; 8, 12]); | ||
myIntervalArray = myIntervalArray.intersect(otherIntervalArray); | ||
verifyEqual(testCase, myIntervalArray.intervals, [0, 2; 10, 12], 'Error: intersect not working'); | ||
end | ||
|
||
function testUnion(testCase) | ||
% Test union | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
otherIntervalArray = IntervalArray([-2, 2; 8, 12]); | ||
myIntervalArray = myIntervalArray.union(otherIntervalArray); | ||
verifyEqual(testCase, myIntervalArray.intervals, [-2, 5; 8, 15], 'Error: union not working'); | ||
end | ||
|
||
function testSetDiff(testCase) | ||
% Test setdiff | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
otherIntervalArray = IntervalArray([-2, 2; 18, 20]); | ||
myIntervalArray = myIntervalArray.setdiff(otherIntervalArray); | ||
verifyEqual(testCase, myIntervalArray.intervals, [10, 15], 'Error: setdiff not working'); | ||
end | ||
|
||
function testComplement(testCase) | ||
% Test complement | ||
myIntervalArray = IntervalArray([0, 5; 10, 15]); | ||
myIntervalArray = myIntervalArray.complement(); | ||
verifyEqual(testCase, myIntervalArray.intervals, [-inf, 0; 5, 10; 15, inf], 'Error: complement not working'); | ||
end | ||
|
||
function testMerge(testCase) | ||
% Test merge | ||
myIntervalArray = IntervalArray([10, 20; 15, 25]); | ||
myIntervalArray = myIntervalArray.merge(); | ||
verifyEqual(testCase, myIntervalArray.intervals, [10, 25], 'Error: merge not working'); | ||
end | ||
|
||
function testPlus(testCase) | ||
% Test plus | ||
myIntervalArray = IntervalArray([10, 20; 15, 25]); | ||
otherIntervalArray = IntervalArray([-2, 2; 8, 12]); | ||
myIntervalArray = myIntervalArray.plus(otherIntervalArray); | ||
verifyEqual(testCase, myIntervalArray.intervals, [-2, 2; 8, 25], 'Error: plus not working'); | ||
end | ||
|
||
function testRemoveEmpty(testCase) | ||
% Test remove_empty | ||
myIntervalArray = IntervalArray([0, 2; 5, 5; 8, 12]); | ||
myIntervalArray = myIntervalArray.remove_empty(); | ||
verifyEqual(testCase, myIntervalArray.intervals, [0, 2; 8, 12], 'Error: remove_empty not working'); | ||
end | ||
|
||
function testEq(testCase) | ||
% Test eq | ||
myIntervalArray = IntervalArray([0, 2; 8, 12]); | ||
otherIntervalArray = IntervalArray([0, 2; 8, 12]); | ||
is_equal = myIntervalArray.eq(otherIntervalArray); | ||
verifyEqual(testCase, is_equal, true, 'Error: eq not working'); | ||
end | ||
|
||
function testIn(testCase) | ||
% Test in | ||
myIntervalArray = IntervalArray([0, 2; 8, 12]); | ||
point = 9; | ||
contain = myIntervalArray.in(point); | ||
verifyEqual(testCase, contain, true, 'Error: in not working'); | ||
end | ||
|
||
function testEmptyInterval(testCase) | ||
% Test empty interval | ||
myIntervalArray = IntervalArray([]); | ||
verifyEqual(testCase, myIntervalArray.isempty(), true, 'Error: empty intervals not working'); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,106 @@ | ||
function test_SpikeArray() | ||
function tests = test_SpikeArray | ||
% Create a test suite for the SpikeArray class | ||
tests = functiontests(localfunctions); | ||
end | ||
|
||
function testConstructor(testCase) | ||
% Test SpikeArray constructor | ||
spikes_cell = {[1, 2, 3], [4, 5, 6], [7, 8, 9]}; | ||
spike_array = SpikeArray(spikes_cell); | ||
assert(isequal(spike_array.spikes, [1, 2, 3, 4, 5, 6, 7, 8, 9])); | ||
assert(isequal(spike_array.uid, [1, 1, 1, 2, 2, 2, 3, 3, 3])); | ||
verifyEqual(testCase, spike_array.spikes, [1, 2, 3, 4, 5, 6, 7, 8, 9], 'Error: SpikeArray constructor not working'); | ||
verifyEqual(testCase, spike_array.uid, [1, 1, 1, 2, 2, 2, 3, 3, 3], 'Error: UID not working'); | ||
|
||
uid = [1, 1, 3, 1, 3]; | ||
spike_array = SpikeArray([1, 2, 3, 4, 5], uid); | ||
assert(isequal(spike_array.spikes, [1, 2, 3, 4, 5])); | ||
assert(isequal(spike_array.uid, uid)); | ||
verifyEqual(testCase, spike_array.spikes, [1, 2, 3, 4, 5], 'Error: SpikeArray constructor with UID not working'); | ||
verifyEqual(testCase, spike_array.uid, uid, 'Error: UID not working'); | ||
end | ||
|
||
function testRestrict(testCase) | ||
% Test restrict method | ||
spikes_cell = {[1, 2, 3], [4, 5, 6], [7, 8, 9]}; | ||
spike_array = SpikeArray(spikes_cell); | ||
interval_array = IntervalArray([3, 5; 7, 10]); | ||
spike_array = SpikeArray({[1, 2, 3], [4, 5, 6], [7, 8, 9]}); | ||
restricted_spike_array = spike_array(interval_array); | ||
assert(isequal(restricted_spike_array.spikes, [3, 4, 5, 7, 8, 9])); | ||
assert(isequal(restricted_spike_array.uid, [1, 2, 2, 3, 3, 3])); | ||
verifyEqual(testCase, restricted_spike_array.spikes, [3, 4, 5, 7, 8, 9], 'Error: restrict method not working'); | ||
verifyEqual(testCase, restricted_spike_array.uid, [1, 2, 2, 3, 3, 3], 'Error: restrict method UID not working'); | ||
end | ||
|
||
function testNCells(testCase) | ||
% Test n_cells method | ||
assert(spike_array.n_cells() == 3); | ||
spike_array = SpikeArray({[1, 2, 3], [4, 5, 6], [7, 8, 9]}); | ||
verifyEqual(testCase, spike_array.n_cells(), 3, 'Error: n_cells not working'); | ||
end | ||
|
||
function testIds(testCase) | ||
% Test ids method | ||
assert(isequal(spike_array.ids(), [1, 2, 3]')); | ||
spike_array = SpikeArray({[1, 2, 3], [4, 5, 6], [7, 8, 9]}); | ||
verifyEqual(testCase, spike_array.ids(), [1, 2, 3]', 'Error: ids not working'); | ||
end | ||
|
||
function testNSpikes(testCase) | ||
% Test n_spikes method | ||
assert(isequal(spike_array.n_spikes(), [3, 3, 3]')); | ||
spike_array = SpikeArray({[1, 2, 3], [4, 5, 6], [7, 8, 9]}); | ||
verifyEqual(testCase, spike_array.n_spikes(), [3, 3, 3]', 'Error: n_spikes not working'); | ||
end | ||
|
||
function testFirstEvent(testCase) | ||
% Test first_event method | ||
assert(spike_array.first_event() == 1); | ||
spike_array = SpikeArray({[1, 2, 3], [4, 5, 6], [7, 8, 9]}); | ||
verifyEqual(testCase, spike_array.first_event(), 1, 'Error: first_event not working'); | ||
end | ||
|
||
function testLastEvent(testCase) | ||
% Test last_event method | ||
assert(spike_array.last_event() == 9); | ||
spike_array = SpikeArray({[1, 2, 3], [4, 5, 6], [7, 8, 9]}); | ||
verifyEqual(testCase, spike_array.last_event(), 9, 'Error: last_event not working'); | ||
end | ||
|
||
function testIsSorted(testCase) | ||
% Test issorted method | ||
assert(spike_array.issorted() == 1); | ||
spike_array = SpikeArray({[1, 2, 3], [4, 5, 6], [7, 8, 9]}); | ||
verifyEqual(testCase, spike_array.issorted(), true, 'Error: issorted not working'); | ||
end | ||
|
||
function testIsEmpty(testCase) | ||
% Test isempty method | ||
assert(spike_array.isempty() == 0); | ||
|
||
spike_array = SpikeArray({[1, 2, 3], [4, 5, 6], [7, 8, 9]}); | ||
verifyEqual(testCase, spike_array.isempty(), false, 'Error: isempty not working'); | ||
end | ||
|
||
function testCellSelection(testCase) | ||
% Test cell selection method | ||
spike_array = SpikeArray({[1, 2, 3], [4, 5, 6], [7, 8, 9]}); | ||
first_cell_array = spike_array(1); | ||
assert(first_cell_array.n_cells() == 3); | ||
assert(first_cell_array.n_active_cells() == 1); | ||
assert(all(first_cell_array.ids() == [1,2,3]')); | ||
assert(all(first_cell_array.n_spikes() == [3,0,0]')); | ||
assert(first_cell_array.first_event() == 1); | ||
assert(first_cell_array.last_event() == 3); | ||
assert(first_cell_array.issorted() == 1); | ||
assert(first_cell_array.isempty() == 0); | ||
|
||
verifyEqual(testCase, first_cell_array.n_cells(), 3, 'Error: cell selection n_cells not working'); | ||
verifyEqual(testCase, first_cell_array.n_active_cells(), 1, 'Error: cell selection n_active_cells not working'); | ||
verifyEqual(testCase, first_cell_array.ids(), [1, 2, 3]', 'Error: cell selection ids not working'); | ||
verifyEqual(testCase, first_cell_array.n_spikes(), [3, 0, 0]', 'Error: cell selection n_spikes not working'); | ||
verifyEqual(testCase, first_cell_array.first_event(), 1, 'Error: cell selection first_event not working'); | ||
verifyEqual(testCase, first_cell_array.last_event(), 3, 'Error: cell selection last_event not working'); | ||
verifyEqual(testCase, first_cell_array.issorted(), true, 'Error: cell selection issorted not working'); | ||
verifyEqual(testCase, first_cell_array.isempty(), false, 'Error: cell selection isempty not working'); | ||
end | ||
|
||
function testBin(testCase) | ||
% Test bin | ||
spikes_cell = {[1, 2, 3], [4, 5, 6], [7, 8, 9]}; | ||
spike_array = SpikeArray(spikes_cell); | ||
bst = spike_array.bin('ds',1); | ||
X = [1,0,0;... | ||
1,0,0;... | ||
1,0,0;... | ||
0,1,0;... | ||
0,1,0;... | ||
0,1,0;... | ||
0,0,1;... | ||
0,0,1;... | ||
0,0,1]; | ||
assert(isequal(bst.data,X)) | ||
|
||
spike_array = SpikeArray({[1, 2, 3], [4, 5, 6], [7, 8, 9]}); | ||
bst = spike_array.bin('ds', 1); | ||
X = [1, 0, 0;... | ||
1, 0, 0;... | ||
1, 0, 0;... | ||
0, 1, 0;... | ||
0, 1, 0;... | ||
0, 1, 0;... | ||
0, 0, 1;... | ||
0, 0, 1;... | ||
0, 0, 1]; | ||
verifyEqual(testCase, bst.data, X, 'Error: bin method not working'); | ||
end | ||
|
||
function testToCellArray(testCase) | ||
% Test to_cell_array | ||
spikes_cell = {[1, 2, 3], [4, 5, 6], [7, 8, 9]}; | ||
spike_array = SpikeArray(spikes_cell); | ||
spikes_cell_2 = spike_array.to_cell_array(); | ||
assert(isequal(spikes_cell,spikes_cell_2)) | ||
verifyEqual(testCase, spikes_cell, spikes_cell_2, 'Error: to_cell_array not working'); | ||
end |
Oops, something went wrong.