From aa79bb8719adb3018f4c712516b4f5abdb379965 Mon Sep 17 00:00:00 2001
From: Federico Felici <federico.felici@epfl.ch>
Date: Sat, 16 Nov 2019 14:14:06 +0100
Subject: [PATCH] Add methods for compiling and simulating algo and expcode

---
 code/classes/SCDclass_algo.m    | 14 ++++++++++++++
 code/classes/SCDclass_expcode.m | 11 ++++++++++-
 tests/test_expcodes.m           | 17 +++++++++--------
 3 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/code/classes/SCDclass_algo.m b/code/classes/SCDclass_algo.m
index 9cee69a..9a4bb6b 100644
--- a/code/classes/SCDclass_algo.m
+++ b/code/classes/SCDclass_algo.m
@@ -296,6 +296,20 @@ classdef SCDclass_algo
           end
        end
        
+       function compile(obj)
+         try
+           eval(sprintf('%s([],[],[],''compile'')',obj.modelname));
+         catch
+           eval(sprintf('%s([],[],[],''term'')',obj.modelname));
+         end
+         eval(sprintf('%s([],[],[],''term'')',obj.modelname));
+         
+       end
+       
+       function sim(obj)
+         sim(obj.modelname);
+       end
+       
     end
 end
 
diff --git a/code/classes/SCDclass_expcode.m b/code/classes/SCDclass_expcode.m
index b7ba781..e8647ee 100644
--- a/code/classes/SCDclass_expcode.m
+++ b/code/classes/SCDclass_expcode.m
@@ -531,7 +531,16 @@ classdef SCDclass_expcode
             fprintf(" }\n");
             fprintf("}\n");
         end
-        
+       
+        function tcvcompile(obj)
+          try
+            tcv([],[],[],'compile');
+            tcv([],[],[],'term');
+          catch ME
+            tcv([],[],[],'term');
+            rethrow(ME)
+          end
+        end
     end
    
     methods (Access = private)
diff --git a/tests/test_expcodes.m b/tests/test_expcodes.m
index 0d0515e..5f55e69 100644
--- a/tests/test_expcodes.m
+++ b/tests/test_expcodes.m
@@ -31,16 +31,17 @@ classdef test_expcodes < matlab.unittest.TestCase
   end
   
   methods(Test)
+    function test_callinits(testCase)
+      testCase.expcode_obj.callinits;
+    end
+    
+    function test_setup(testCase)
+      testCase.expcode_obj.setup; % run setup this exp code
+    end
+    
     function test_expcode(testCase)
       % attempt compiling tcv.slx for this expcode
-      try
-        tcv([],[],[],'compile');
-        tcv([],[],[],'term');
-      catch ME
-        tcv([],[],[],'term');
-        rethrow(ME)
-      end
-      testCase.assertTrue(true); % dummy
+      testCase.expcode_obj.tcvcompile; % compile tcv.slx with this expcode
     end
     
   end
-- 
GitLab