unit tests added
Serge Steer [Fri, 11 Jul 2008 17:09:10 +0000 (17:09 +0000)]
scilab/modules/cacsd/tests/unit_tests/dscr.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/dscr.tst [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/ss2tf.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/ss2tf.tst [new file with mode: 0644]

diff --git a/scilab/modules/cacsd/tests/unit_tests/dscr.dia.ref b/scilab/modules/cacsd/tests/unit_tests/dscr.dia.ref
new file mode 100644 (file)
index 0000000..8cd7627
--- /dev/null
@@ -0,0 +1,31 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) ????-2008 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+a=-1/3;b=1;c=1;
+sl=syslin('c',a,b,c);
+sld=dscr(sl,0.1);
+if sld.dt<>0.1 then bugmes();quit;end
+if sld.A<>exp(sl.A*0.1) then bugmes();quit;end
+if norm(sld.B-sl.A\(sld.A-eye())*sl.B)>1d-15 then bugmes();quit;end
+a=[0.9,0,0.6,-1.4,-4.2;
+   0.2,0.1,-0.2,0.5,0.6;
+   -4.3,0,2.2,0,2.4;
+   -3.7,-0.5,2.4,-0.6,2.7;
+   6.4,0.1,-4,-0.5,-4];
+b=[-0.1,-0.1,0;
+   0,0,0.1;
+   -0.1,0.2,-0.1;
+   0.2,0.2,-0.6;
+   0.2,-0.1,0.1];
+c=[2,7,-2,5,1
+   0,-1,3,0,2];
+d=[1,0,0
+   0,0,0];
+sl=syslin('c',a,b,c,d);
+sld=dscr(sl,0.1);
+if sld.dt<>0.1 then bugmes();quit;end
+if norm(sld.A-expm(sl.A*0.1))>1d-15 then bugmes();quit;end
+if norm(sld.B-sl.A\(sld.A-eye())*sl.B)>1d-14 then bugmes();quit;end
diff --git a/scilab/modules/cacsd/tests/unit_tests/dscr.tst b/scilab/modules/cacsd/tests/unit_tests/dscr.tst
new file mode 100644 (file)
index 0000000..d7012ab
--- /dev/null
@@ -0,0 +1,38 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) ????-2008 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+a=-1/3;b=1;c=1;
+sl=syslin('c',a,b,c);
+sld=dscr(sl,0.1);
+if sld.dt<>0.1 then pause,end
+if sld.A<>exp(sl.A*0.1) then pause,end
+if norm(sld.B-sl.A\(sld.A-eye())*sl.B)>1d-15 then pause,end
+
+
+a=[0.9,0,0.6,-1.4,-4.2;
+   0.2,0.1,-0.2,0.5,0.6;
+   -4.3,0,2.2,0,2.4;
+   -3.7,-0.5,2.4,-0.6,2.7;
+   6.4,0.1,-4,-0.5,-4];
+
+b=[-0.1,-0.1,0;
+   0,0,0.1;
+   -0.1,0.2,-0.1;
+   0.2,0.2,-0.6;
+   0.2,-0.1,0.1];
+c=[2,7,-2,5,1
+   0,-1,3,0,2];
+d=[1,0,0
+   0,0,0];
+
+sl=syslin('c',a,b,c,d);
+
+sld=dscr(sl,0.1);
+if sld.dt<>0.1 then pause,end
+if norm(sld.A-expm(sl.A*0.1))>1d-15 then pause,end
+if norm(sld.B-sl.A\(sld.A-eye())*sl.B)>1d-14 then pause,end
+
diff --git a/scilab/modules/cacsd/tests/unit_tests/ss2tf.dia.ref b/scilab/modules/cacsd/tests/unit_tests/ss2tf.dia.ref
new file mode 100644 (file)
index 0000000..39e2edf
--- /dev/null
@@ -0,0 +1,84 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) ????-2008 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+a=0.5;b=1;c=2;
+sl=syslin('c',a,b,c);
+h1=ss2tf(sl);
+if h1.num<>2 then bugmes();quit;end
+if h1.den<>poly([-0.5 1],'s','c') then bugmes();quit;end
+d=1;
+sl=syslin('c',a,b,c,d);
+h2=ss2tf(sl);
+if h2<>h1+1 then bugmes();quit;end
+b=[b b];
+sl=syslin('c',a,b,c);
+h2=ss2tf(sl);
+if or(h2<>[h1 h1]) then bugmes();quit;end
+a=[0.9,0,0.6,-1.4,-4.2;
+   0.2,0.1,-0.2,0.5,0.6;
+   -4.3,0,2.2,0,2.4;
+   -3.7,-0.5,2.4,-0.6,2.7;
+   6.4,0.1,-4,-0.5,-4];
+b=[-0.1,-0.1,0;
+   0,0,0.1;
+   -0.1,0.2,-0.1;
+   0.2,0.2,-0.6;
+   0.2,-0.1,0.1];
+c=[2,7,-2,5,1
+   0,-1,3,0,2];
+d=[1,0,0
+   0,0,0];
+sl=syslin('c',a,b,c,d);
+h=ss2tf(sl)
+ h  =
+         column 1
+                               2       3      4   5   
+    1.3986 + 41.9012s + 64.737s + 26.3s + 2.6s + s    
+    ----------------------------------------------    
+                               2        3      4   5  
+  - 0.6296 + 15.4568s + 35.104s + 25.39s + 1.4s + s   
+                                                      
+                                 2       3      4     
+       0.38308 - 8.1212s + 2.283s - 0.29s + 0.1s      
+    -----------------------------------------------   
+                               2        3      4   5  
+  - 0.6296 + 15.4568s + 35.104s + 25.39s + 1.4s + s   
+         column 2
+                                 2       3      4     
+       3.9545 + 14.2365s + 8.024s + 0.52s + 0.3s      
+    -----------------------------------------------   
+                               2        3      4   5  
+  - 0.6296 + 15.4568s + 35.104s + 25.39s + 1.4s + s   
+                                                      
+                                 2       3      4     
+     - 0.09758 + 5.4601s + 9.735s + 0.19s + 0.4s      
+    -----------------------------------------------   
+                               2        3      4   5  
+  - 0.6296 + 15.4568s + 35.104s + 25.39s + 1.4s + s   
+         column 3
+                                  2       3    4      
+       0.7293 - 40.8154s - 49.552s - 1.58s - 2s       
+    ----------------------------------------------    
+                               2        3      4   5  
+  - 0.6296 + 15.4568s + 35.104s + 25.39s + 1.4s + s   
+                                                      
+                                 2       3      4     
+    - 0.58334 + 15.1342s - 4.929s + 0.61s - 0.2s      
+    ----------------------------------------------    
+                               2        3      4   5  
+  - 0.6296 + 15.4568s + 35.104s + 25.39s + 1.4s + s   
+if or(degree(h.den)<>5) then bugmes();quit;end
+if or(degree(h.num)<>[5,4,4;4,4,4]) then bugmes();quit;end
+r1=spec(a);R1=gsort([real(r1) imag(r1)],'lr','i');
+r2=roots(h.den(1,1));R2=gsort([real(r2) imag(r2)],'lr','i');
+if norm(R2-R1,'inf')>1d-14 then bugmes();quit;end
diff --git a/scilab/modules/cacsd/tests/unit_tests/ss2tf.tst b/scilab/modules/cacsd/tests/unit_tests/ss2tf.tst
new file mode 100644 (file)
index 0000000..3747fe8
--- /dev/null
@@ -0,0 +1,50 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) ????-2008 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+a=0.5;b=1;c=2;
+sl=syslin('c',a,b,c);
+h1=ss2tf(sl);
+if h1.num<>2 then pause,end
+if h1.den<>poly([-0.5 1],'s','c') then pause,end
+d=1;
+sl=syslin('c',a,b,c,d);
+h2=ss2tf(sl);
+if h2<>h1+1 then pause,end
+
+b=[b b];
+sl=syslin('c',a,b,c);
+h2=ss2tf(sl);
+if or(h2<>[h1 h1]) then pause,end
+
+
+a=[0.9,0,0.6,-1.4,-4.2;
+   0.2,0.1,-0.2,0.5,0.6;
+   -4.3,0,2.2,0,2.4;
+   -3.7,-0.5,2.4,-0.6,2.7;
+   6.4,0.1,-4,-0.5,-4];
+
+b=[-0.1,-0.1,0;
+   0,0,0.1;
+   -0.1,0.2,-0.1;
+   0.2,0.2,-0.6;
+   0.2,-0.1,0.1];
+c=[2,7,-2,5,1
+   0,-1,3,0,2];
+d=[1,0,0
+   0,0,0];
+
+sl=syslin('c',a,b,c,d);
+
+h=ss2tf(sl)
+if or(degree(h.den)<>5) then pause,end
+if or(degree(h.num)<>[5,4,4;4,4,4]) then pause,end
+
+r1=spec(a);R1=gsort([real(r1) imag(r1)],'lr','i');
+r2=roots(h.den(1,1));R2=gsort([real(r2) imag(r2)],'lr','i');
+if norm(R2-R1,'inf')>1d-14 then pause,end
+
+