-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_netlists.m
74 lines (65 loc) · 2.62 KB
/
test_netlists.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
classdef test_netlists < matlab.unittest.TestCase
properties
tmpFileName
end
methods(TestMethodSetup)
function createTmpFile(testCase)
testCase.tmpFileName = tempname;
end
end
methods(TestMethodTeardown)
function deleteTmpFile(testCase)
delete(testCase.tmpFileName)
end
end
methods
function lines = readResultLines(testCase)
text = fileread(testCase.tmpFileName);
lines = strsplit(text, '\n');
end
end
methods(Test)
function dumpDefaultNodeNames(testCase)
G = [1, -1; -1, 1];
netlists.dump(testCase.tmpFileName, G, [])
result = testCase.readResultLines();
% First line should be comment
testCase.verifyEqual(result{1}(1), '*')
testCase.verifyEqual(result{2}, 'R1 1 2 1')
end
function dumpCustomNodeNames(testCase)
G = [1.5, -0.5, -1; -0.5, 1, -0.5; -1, -1, 2];
netlists.dump(testCase.tmpFileName, G, [], 4:6)
result = testCase.readResultLines();
% First line should be comment
testCase.verifyEqual(result{1}(1), '*')
testCase.verifyEqual(result{2}, 'R1 4 5 2')
testCase.verifyEqual(result{3}, 'R2 4 6 1')
testCase.verifyEqual(result{4}, 'R3 5 6 2')
end
function dumpComposite(testCase)
G = [1, -1; -1, 1];
netlists.dump_composite(testCase.tmpFileName, G, [], 1:2, G, [], 4:5)
result = testCase.readResultLines();
% First line should be comment
testCase.verifyEqual(result{1}(1), '*')
% Each connected component should be commented
testCase.verifyEqual(result{2}, '* Connected component 1')
testCase.verifyEqual(result{3}, 'R1 1 2 1')
testCase.verifyEqual(result{4}, '* Connected component 2')
testCase.verifyEqual(result{5}, 'R2 4 5 1')
end
function dumpWithTerminals(testCase)
G = [1.5, -0.5, -1; -0.5, 1, -0.5; -1, -1, 2];
rng(0); % freeze rng seed
netlists.dump(testCase.tmpFileName, G, [1 0 0], 4:6)
result = testCase.readResultLines();
% First line should be comment
testCase.verifyEqual(result{1}(1), '*')
testCase.verifyEqual(result{2}, 'R1 4 5 2')
testCase.verifyEqual(result{3}, 'R2 4 6 1')
testCase.verifyEqual(result{4}, 'R3 5 6 2')
testCase.verifyEqual(result{5}, 'V1 4 0 0.814724')
end
end
end