string: pass tests 00/21300/3
Clément DAVID [Tue, 28 Jan 2020 10:55:17 +0000 (11:55 +0100)]
Change-Id: I60e057d442b9a7e36446ae8f2af6f3013bc1045b

scilab/modules/string/macros/sci2exp.sci
scilab/modules/string/tests/nonreg_tests/bug_14099.tst
scilab/modules/string/tests/nonreg_tests/bug_4768.dia.ref
scilab/modules/string/tests/nonreg_tests/bug_7879.dia.ref
scilab/modules/string/tests/unit_tests/blanks.dia.ref [deleted file]
scilab/modules/string/tests/unit_tests/blanks.tst
scilab/modules/string/tests/unit_tests/part_UTF_nw.dia.ref
scilab/modules/string/tests/unit_tests/part_UTF_nw.tst
scilab/modules/string/tests/unit_tests/part_UTF_nwni.dia.ref
scilab/modules/string/tests/unit_tests/part_UTF_nwni.tst

index 2ec0948..07eeb70 100644 (file)
@@ -409,8 +409,12 @@ function t = glist2exp(listType, l, lmax)
         if listType ~= "mlist"
             lk = l(k)
         else
-            lk = getfield(k,l)
+            try
+                lk = getfield(k,l)
+            catch
+            end
         end
+        
         if ~isdef("lk","local")
             t1 = ""
         else
index a4e4028..d1a8a3c 100644 (file)
@@ -24,33 +24,33 @@ format("v", 10);
 
 // Single polynomials
     // Constantes
-assert_checkequal(string(0*%z), ["";"0"]);
-assert_checkequal(string(0*%i*%z), ["";"0"]);
-assert_checkequal(string(3+0*%z), ["";"3"]);
-assert_checkequal(string(-3+0*%z), ["";"- 3"]);
+assert_checkequal(string(0*%z), "0");
+assert_checkequal(string(0*%i*%z), "0");
+assert_checkequal(string(3+0*%z), "3");
+assert_checkequal(string(-3+0*%z), "-3");
 
-assert_checkequal(string(3*%i+0*%z), ["";"3i"]);
-assert_checkequal(string(-3*%i+0*%z), ["";"- 3i"]);
+assert_checkequal(string(3*%i+0*%z), "3i");
+assert_checkequal(string(-3*%i+0*%z), "-3i");
 
-assert_checkequal(string(1-3*%i+0*%z), ["";"(1-3i)"]);
-assert_checkequal(string(-1+3*%i+0*%z), ["";"- (1-3i)"]);
-assert_checkequal(string(-1-3*%i+0*%z), ["";"- (1+3i)"]);
-    //
-assert_checkequal(string(-3*%i*%z), ["";"- 3iz"]);
-assert_checkequal(string((1-3*%i)*%z), ["";"(1-3i)z"]);
-assert_checkequal(string((-1+3*%i)*%z), ["";"- (1-3i)z"]);
-assert_checkequal(string((-1-3*%i)*%z), ["";"- (1+3i)z"]);
+assert_checkequal(string(1-3*%i+0*%z), "1-3i");
+assert_checkequal(string(-1+3*%i+0*%z), "-1+3i");
+assert_checkequal(string(-1-3*%i+0*%z), "-1-3i");
 
-assert_checkequal(string(-3*%i*%z^13), ["     13";"- 3iz"]);
-assert_checkequal(string((1-3*%i)*%z^13), ["       13";"(1-3i)z"]);
-assert_checkequal(string((-1+3*%i)*%z^13), ["         13";"- (1-3i)z"]);
-assert_checkequal(string((-1-3*%i)*%z^13), ["         13";"- (1+3i)z"]);
+assert_checkequal(string(-3*%i*%z), "-3iz");
+assert_checkequal(string((1-3*%i)*%z), "(1-3i)z");
+assert_checkequal(string((-1+3*%i)*%z), "(-1+3i)z");
+assert_checkequal(string((-1-3*%i)*%z), "(-1-3i)z");
+
+assert_checkequal(string(-3*%i*%z^13), "-3iz¹³");
+assert_checkequal(string((1-3*%i)*%z^13), "(1-3i)z¹³");
+assert_checkequal(string((-1+3*%i)*%z^13), "(-1+3i)z¹³");
+assert_checkequal(string((-1-3*%i)*%z^13), "(-1-3i)z¹³");
 
 p = (1-%i) - %i*%z -3*%i*%z^8 + 4*%z^15 - %i*%z^18;
-assert_checktrue(and(string(p)==["                8    15   18"; "(1-i) - iz - 3iz + 4z - iz"]));
+assert_checkequal(string(p), "1-i -iz -3iz⁸ +4z¹⁵ -iz¹⁸");
 
 p = - %i*%z -3*%i*%z^8 + 4*%z^15 - %i*%z^18;
-assert_checktrue(and(string(p)==["          8    15   18"; "- iz - 3iz + 4z - iz"]));
+assert_checkequal(string(p), "-iz -3iz⁸ +4z¹⁵ -iz¹⁸");
 
 // Matrix of polynomials
 ps = "[0*z, 3+0*%i*z; -z, -%i*z;  -z^17, -%i*z^17;  "+..
@@ -58,47 +58,36 @@ ps = "[0*z, 3+0*%i*z; -z, -%i*z;  -z^17, -%i*z^17;  "+..
      "-z+z^3+3*z^4, (%i-2)-3*z-3*%i*z^13+(1+7*%i)*z^20; ]";
 z = poly(0,"x");
 p = evstr(ps);
-refS = [" "                   " "
-        "0"                   "3"
-        "   "                 "    "
-        "- x"                 "- ix"
-        "   17"               "    17"
-        "- x"                 "- ix"
-        "          3     20"  "             2         3"
-        "1 - x + 5x + 41x"    "(3-3i)x - 6ix - (2+2i)x"
-        "       3    4"       "                  13        20"
-        "- x + x + 3x"        "- (2-i) - 3x - 3ix + (1+7i)x"
+refS = ["0"                   "3"
+        "-x"                 "-ix"
+        "-x¹⁷"                 "-ix¹⁷"
+        "1 -x +5x³ +41x²⁰"    "(3-3i)x -6ix² -(2+2i)x³"
+        "-x +x³ +3x⁴"        "-2+i -3x -3ix¹³ +(1+7i)x²⁰"
         ];
-assert_checktrue(and(string(p)==refS));
+assert_checkequal(string(p), refS);
 
 x = poly(0,"x");
 p = "[64.692+38.966*x-36.580*x^2+90.044*x^3-93.111*x^4;64.381-74.963*x+52.75*x^2-1.8822*x^3+32.721*x^4]";
 p = evstr(p);
 format(6);
-refS = ["                       2        3        4"
-        "64.69 + 38.97x - 36.58x + 90.04x - 93.11x"
-        "                       2        3        4"
-        "64.38 - 74.96x + 52.75x - 1.882x + 32.72x"
+refS = ["64.69 +38.97x -36.58x² +90.04x³ -93.11x⁴"
+        "64.38 -74.96x +52.75x² -1.882x³ +32.72x⁴"
        ];
-assert_checktrue(and(string(p)==refS));
+assert_checkequal(string(p), refS);
 
 p = p/3+p*%i/4;
 format(5);
-refS = ["                                          2             3             4"
-        "(21.6+16.2i) + (13+9.74i)x - (12.2+9.14i)x + (30+22.5i)x - (31+23.3i)x"
-        "                                          2               3               4"
-        "(21.5+16.1i) - (25+18.7i)x + (17.6+13.2i)x - (0.63+0.47i)x + (10.9+8.18i)x"
+refS = ["21.6+16.2i +(13+9.74i)x -(12.2+9.14i)x² +(30+22.5i)x³ -(31+23.3i)x⁴"
+        "21.5+16.1i -(25+18.7i)x +(17.6+13.2i)x² -(0.63+0.47i)x³ +(10.9+8.18i)x⁴"
         ];
-assert_checktrue(and(string(p)==refS));
+assert_checkequal(string(p), refS);
 
 // with %nan and %inf
 p = poly([%nan 2 3 -%nan 8],"x","coeff");
 p = p+%i*p/2;
 //""""+string(p)+""""
-refS = ["                               2             3         4"
-        "(Nan+Nani) + (2+i)x + (3+1.5i)x + (Nan+Nani)x + (8+4i)x"
-        ];
-assert_checktrue(and(string(p)==refS));
+refS = "Nan+Nani +(2+i)x +(3+1.5i)x² -(Nan+Nani)x³ +(8+4i)x⁴";
+assert_checkequal(string(p), refS);
 
 // with format("e")
 format("e",8);
@@ -107,28 +96,20 @@ ps = "[0*z, 3+0*%i*z; -z, -%i*z;"+..
      "(1+(1-%i)*z)^3-1+%e*%i*z^11, -%i*z^17]";
 z = poly(0,"x");
 p = evstr(ps);
-if getos()=="Windows" then // The exponential notation may depend on the OS
-    refS = [" "                                                                        "       "
-            "0"                                                                        "3.0D+00"
-            "   "                                                                      "    "
-            "- x"                                                                      "- ix"
-            "                  3          17"                                          "   17"
-            "1.0D+00 + 5.0D+00x - 3.1D+00x"                                            "- x"
-            "                                 2                       3           11"  "    17"
-            "(3.0D+00 - 3.0D+00i)x - 6.0D+00ix - (2.0D+00 + 2.0D+00i)x + 2.7D+00ix"    "- ix"
-            ];
-    assert_checktrue(and(string(p)==refS));
-end
+refS = ["0"                                                                        "3.0D+00"
+        "-1.0D+00x"                                                                "-1.0D+00ix"
+        "1.0D+00 +5.0D+00x³ -3.1D+00x¹⁷"                                           "-1.0D+00x¹⁷"
+        "(3.0D+00-3.0D+00i)x -6.0D+00ix² -(2.0D+00+2.0D+00i)x³ +2.7D+00ix¹¹"       "-1.0D+00ix¹⁷"
+        ];
+assert_checkequal(string(p), refS);
 
 // With a name of variable longer than 1 character:
 x = poly(0,"ABC");
 p = (2-%i+x).^[2 4 ; 1 3];
 format("v",10);
 //""""+string(p)+""""
-refS = ["                        2"  "                                    2           3     4"
-        "(3-4i) + (4-2i)ABC + ABC"   "- (7+24i) + (8-44i)ABC + (18-24i)ABC + (8-4i)ABC + ABC"
-        "           "                "                                2     3"
-        "(2-i) + ABC"                "(2-11i) + (9-12i)ABC + (6-3i)ABC + ABC"
+refS = ["3-4i +(4-2i)ABC +ABC²"  "-7-24i +(8-44i)ABC +(18-24i)ABC² +(8-4i)ABC³ +ABC⁴"
+        "2-i +ABC"               "2-11i +(9-12i)ABC +(6-3i)ABC² +ABC³"
        ];
-assert_checktrue(and(string(p)==refS));
+assert_checkequal(string(p), refS);
 
index b9846b5..408dcac 100644 (file)
@@ -18,34 +18,29 @@ ref_res1 = ["世";"界您好"];
 ref_res3 = ["世界您";"好"];
 r = strsplit(v,1)
  r  = 
-!世    !
-!     !
-!界您好  !
+  "世"  
+  "界您好"
 if r <> ref_res1 then bugmes();quit;end
 r = strsplit(v,3)
  r  = 
-!世界您  !
-!     !
-!好    !
+  "世界您"
+  "好"  
 if r <> ref_res3 then bugmes();quit;end
 //======================================================================================== 
 v = "азеазея";
 ref_res1 = ["а";"зеазея"]
  ref_res1  = 
-!а       !
-!        !
-!зеазея  !
+  "а"     
+  "зеазея"
 ref_res3 = ["азе";"азея"];
 r = strsplit(v,1)
  r  = 
-!а       !
-!        !
-!зеазея  !
+  "а"     
+  "зеазея"
 if r <> ref_res1 then bugmes();quit;end
 r = strsplit(v,3)
  r  = 
-!азе   !
-!      !
-!азея  !
+  "азе" 
+  "азея"
 if r <> ref_res3 then bugmes();quit;end
 //======================================================================================== 
index 19ac301..7ca87f7 100644 (file)
@@ -26,20 +26,12 @@ params = add_param(params, "stringval", "1");
 params = add_param(params, "stringmat", ["1" "2"]);
 string(params)
  ans  =
-!Parameters list:                  !
-!                                  !
-!================                  !
-!                                  !
-!Number of fields = 6              !
-!                                  !
-!boolval = F ("boolean")           !
-!                                  !
-!funval = "function"               !
-!                                  !
-!doubleval = 1 ("constant")        !
-!                                  !
-!doublematrix = "constant" 10x10   !
-!                                  !
-!stringval = 1 ("string")          !
-!                                  !
-!stringmat = "string" 1x2          !
+  "Parameters list:"                
+  "================"                
+  "Number of fields = 6"            
+  "boolval = F ("boolean")"         
+  "funval = "function""             
+  "doubleval = 1 ("constant")"      
+  "doublematrix = "constant" 10x10 "
+  "stringval = 1 ("string")"        
+  "stringmat = "string" 1x2 "       
diff --git a/scilab/modules/string/tests/unit_tests/blanks.dia.ref b/scilab/modules/string/tests/unit_tests/blanks.dia.ref
deleted file mode 100644 (file)
index d8096ad..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// =============================================================================
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2007-2008 - INRIA - Allan CORNET <allan.cornet@inria.fr>
-//
-//  This file is distributed under the same license as the Scilab package.
-// =============================================================================
-// <-- CLI SHELL MODE -->
-//==============================================================================
-// blank unit tests
-//==============================================================================
-disp(["xxx" blanks(20) "yyy"]);
-!xxx                        yyy  !
-// Test 1
-//LEN_MAX = 20000000; too slow
-LEN_MAX = 2000;
-r = blanks(LEN_MAX);
-l = length(r);
-if ( l <> LEN_MAX) then bugmes();quit;end
-// Test 2
-// check first and last characters
-FIRST_CHAR = part(r,1);
-LAST_CHAR = part(r,LEN_MAX);
-if (FIRST_CHAR <> " ") then bugmes();quit;end
-if (LAST_CHAR <> " ") then bugmes();quit;end
-// Test 3
-A = floor(abs(2^8  * rand()));
-B = floor(abs(2^16 * rand()));
-C = floor(abs(2^16 * rand()));
-D = floor(abs(2^7  * rand()));
-E = floor(abs(2^15 * rand()));
-F = floor(abs(2^15 * rand()));
-if blanks(A) <> blanks(uint8(A))  then bugmes();quit;end
-if blanks(B) <> blanks(uint16(B)) then bugmes();quit;end
-if blanks(C) <> blanks(uint32(C)) then bugmes();quit;end
-if blanks(D) <> blanks(int8(D))  then bugmes();quit;end
-if blanks(E) <> blanks(int16(E)) then bugmes();quit;end
-if blanks(F) <> blanks(int32(F)) then bugmes();quit;end
index bb98813..8ba4a11 100644 (file)
@@ -6,28 +6,29 @@
 // =============================================================================
 
 // <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
 
 //==============================================================================
 // blank unit tests
 //==============================================================================
 
-disp(["xxx" blanks(20) "yyy"]);
+x = (["xxx" blanks(20) "yyy"]);
+assert_checkequal(x, ["xxx" "                    " "yyy"]);
 
 // Test 1
-//LEN_MAX = 20000000; too slow
-
-LEN_MAX = 2000;
+//LEN_MAX = 20000000;
+LEN_MAX = 20000000;
 r = blanks(LEN_MAX);
 l = length(r);
-if ( l <> LEN_MAX) then pause,end
+assert_checkequal(l, LEN_MAX);
 
 // Test 2
 // check first and last characters
 
 FIRST_CHAR = part(r,1);
 LAST_CHAR = part(r,LEN_MAX);
-if (FIRST_CHAR <> " ") then pause,end
-if (LAST_CHAR <> " ") then pause,end
+assert_checkequal(FIRST_CHAR, " ");
+assert_checkequal(LAST_CHAR, " ");
 
 // Test 3
 
@@ -39,10 +40,10 @@ D = floor(abs(2^7  * rand()));
 E = floor(abs(2^15 * rand()));
 F = floor(abs(2^15 * rand()));
 
-if blanks(A) <> blanks(uint8(A))  then pause, end
-if blanks(B) <> blanks(uint16(B)) then pause, end
-if blanks(C) <> blanks(uint32(C)) then pause, end
+assert_checkequal(blanks(A), blanks(uint8(A)));
+assert_checkequal(blanks(B), blanks(uint16(B)));
+assert_checkequal(blanks(C), blanks(uint32(C)));
 
-if blanks(D) <> blanks(int8(D))  then pause, end
-if blanks(E) <> blanks(int16(E)) then pause, end
-if blanks(F) <> blanks(int32(F)) then pause, end
+assert_checkequal(blanks(D), blanks(int8(D)));
+assert_checkequal(blanks(E), blanks(int16(E)));
+assert_checkequal(blanks(F), blanks(int32(F)));
index 84b45fc..8c330f5 100644 (file)
@@ -10,4 +10,4 @@ current_field_length           = regexp(txt,"/:\s/","o");
 current_field                  = part(txt,1:current_field_length-1);
 assert_checkequal(current_field, "Angel");
 disp(txt);
- Angel: Raphaël Archange
+  "Angel: Raphaël Archange"
index 1c68f54..10cce19 100644 (file)
@@ -12,4 +12,4 @@ current_field                  = part(txt,1:current_field_length-1);
 
 assert_checkequal(current_field, "Angel");
 
-disp(txt);
\ No newline at end of file
+disp(txt);
index 828e0bf..d69632e 100644 (file)
@@ -10,4 +10,4 @@ current_field_length           = regexp(txt,"/:\s/","o");
 current_field                  = part(txt,1:current_field_length-1);
 assert_checkequal(current_field, "Angel");
 disp(txt);
- Angel: Raphaël Archange
+  "Angel: Raphaël Archange"
index 502e799..6f2a19d 100644 (file)
@@ -13,4 +13,4 @@ current_field                  = part(txt,1:current_field_length-1);
 
 assert_checkequal(current_field, "Angel");
 
-disp(txt);
\ No newline at end of file
+disp(txt);