Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 21600b7

Browse files
authored
Test Random Number Generation
1 parent 5a1ad3b commit 21600b7

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

TestRand.m

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
classdef TestRand < matlab.unittest.TestCase
2+
properties (ClassSetupParameter)
3+
generator = {'twister','combRecursive','multFibonacci'};
4+
end
5+
6+
properties (MethodSetupParameter)
7+
seed = {0, 123};
8+
end
9+
10+
properties (TestParameter)
11+
dim1 = struct('small', 1,'medium', 2, 'large', 3);
12+
dim2 = struct('small', 2,'medium', 3, 'large', 4);
13+
dim3 = struct('small', 3,'medium', 4, 'large', 5);
14+
type = {'single','double'};
15+
end
16+
17+
methods (TestClassSetup)
18+
function ClassSetup(testCase, generator)
19+
orig = rng;
20+
testCase.addTeardown(@rng, orig)
21+
rng(0, generator)
22+
end
23+
end
24+
25+
methods (TestMethodSetup)
26+
function MethodSetup(testCase, seed)
27+
orig = rng;
28+
testCase.addTeardown(@rng, orig)
29+
rng(seed)
30+
end
31+
end
32+
33+
methods (Test, ParameterCombination='sequential')
34+
function testSize(testCase,dim1,dim2,dim3)
35+
testCase.verifySize(rand(dim1,dim2,dim3),[dim1 dim2 dim3])
36+
end
37+
end
38+
39+
methods (Test, ParameterCombination='pairwise')
40+
function testRepeatable(testCase,dim1,dim2,dim3)
41+
state = rng;
42+
firstRun = rand(dim1,dim2,dim3);
43+
rng(state)
44+
secondRun = rand(dim1,dim2,dim3);
45+
testCase.verifyEqual(firstRun,secondRun);
46+
end
47+
end
48+
49+
methods (Test)
50+
function testClass(testCase,dim1,dim2,type)
51+
testCase.verifyClass(rand(dim1,dim2,type), type)
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)