* Bug #8349 fixed - write_csv() failed to support writting complexes with %nan 65/9065/3
Sylvestre Ledru [Wed, 19 Sep 2012 09:41:06 +0000 (11:41 +0200)]
                    or %inf parts.

Change-Id: I6b18119869cc538c32ba0be4ec5f78f61946c32a

scilab/CHANGES_5.4.X
scilab/modules/spreadsheet/src/cpp/csvWrite.c
scilab/modules/spreadsheet/tests/nonreg_tests/bug_8349.dia.ref [new file with mode: 0644]
scilab/modules/spreadsheet/tests/nonreg_tests/bug_8349.tst [new file with mode: 0644]

index 336e476..2e77a81 100644 (file)
@@ -16,6 +16,9 @@ CSV features
   - Write performances improved to a 100x factor.
   - Read performances improved from 3x to 200x factor.
 
+* Bug #8349 fixed - write_csv() failed to support writting complexes with %nan
+                    or %inf parts.
+
 * Bug #8653 fixed - csvRead returns double values by default.
                     (read_csv still return string values)
 
index 46c2031..5ba5d49 100644 (file)
@@ -34,7 +34,7 @@
 #define DEFAULT_CSV_WRITE_STRING_FORMAT "%s"
 #define DEFAULT_CSV_WRITE_DOUBLE_FORMAT "%.lg"
 #define PlusStr "+"
-#define LessStr "+"
+#define LessStr "-"
 #define ComplexStr "i"
 #define EMPTY_STRING ""
 #if _MSC_VER
diff --git a/scilab/modules/spreadsheet/tests/nonreg_tests/bug_8349.dia.ref b/scilab/modules/spreadsheet/tests/nonreg_tests/bug_8349.dia.ref
new file mode 100644 (file)
index 0000000..59a75db
--- /dev/null
@@ -0,0 +1,49 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - S/E - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- JAVA NOT MANDATORY -->
+//
+// <-- Non-regression test for bug 8349 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=8349
+//
+// <-- Short Description -->
+// write_csv() failed to support writting complexes with %nan or %inf parts
+m = [7,-2,9;1,-8,2;1,-6,0];
+m = m*(1+%i);
+filename=TMPDIR+"/test.txt";
+write_csv(m,filename);
+b=mgetl(filename);
+assert_checkequal(b, ["7+7i,-2-2i,9+9i";"1+1i,-8-8i,2+2i";"1+1i,-6-6i,0+0i"]);
+b=csvRead(filename);
+assert_checkequal(b,m);
+write_csv([ 1  %nan*(1+%i)],filename);
+b=mgetl(filename);
+assert_checkequal(b,"1+0i,Nan+Nani");
+b=csvRead(filename);
+assert_checkequal(b, [1  %nan*(1+%i)]);
+write_csv([ 1.1  %nan*(1+%i)],filename);
+b=mgetl(filename);
+assert_checkequal(b,"1.1000000000000001+0i,Nan+Nani");
+b=csvRead(filename);
+assert_checkequal(b, [1.1  %nan*(1+%i)]);
+write_csv([ 1  %inf*(1+%i)],filename)
+b=mgetl(filename);
+assert_checkequal(b,"1+0i,Inf+Infi");
+b=csvRead(filename);
+assert_checkequal(b, [1  %inf*(1+%i)]);
+write_csv([ 1.1  %inf*(1+%i)],filename)
+b=mgetl(filename);
+assert_checkequal(b,"1.1000000000000001+0i,Inf+Infi");
+b=csvRead(filename);
+assert_checkequal(b, [1.1  %inf*(1+%i)]);
+write_csv([ 1.1  1+%i*%inf],filename) 
+b=mgetl(filename);
+assert_checkequal(b,"1.1000000000000001+0i,Nan+Infi");
+b=csvRead(filename);
+assert_checkequal(b, [ 1.1  1+%i*%inf]);
diff --git a/scilab/modules/spreadsheet/tests/nonreg_tests/bug_8349.tst b/scilab/modules/spreadsheet/tests/nonreg_tests/bug_8349.tst
new file mode 100644 (file)
index 0000000..a89d8ba
--- /dev/null
@@ -0,0 +1,56 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - S/E - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- JAVA NOT MANDATORY -->
+//
+// <-- Non-regression test for bug 8349 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=8349
+//
+// <-- Short Description -->
+// write_csv() failed to support writting complexes with %nan or %inf parts
+
+m = [7,-2,9;1,-8,2;1,-6,0];
+m = m*(1+%i);
+filename=TMPDIR+"/test.txt";
+write_csv(m,filename);
+b=mgetl(filename);
+assert_checkequal(b, ["7+7i,-2-2i,9+9i";"1+1i,-8-8i,2+2i";"1+1i,-6-6i,0+0i"]);
+b=csvRead(filename);
+assert_checkequal(b,m);
+
+write_csv([ 1  %nan*(1+%i)],filename);
+b=mgetl(filename);
+assert_checkequal(b,"1+0i,Nan+Nani");
+b=csvRead(filename);
+assert_checkequal(b, [1  %nan*(1+%i)]);
+
+write_csv([ 1.1  %nan*(1+%i)],filename);
+b=mgetl(filename);
+assert_checkequal(b,"1.1000000000000001+0i,Nan+Nani");
+b=csvRead(filename);
+assert_checkequal(b, [1.1  %nan*(1+%i)]);
+
+
+write_csv([ 1  %inf*(1+%i)],filename)
+b=mgetl(filename);
+assert_checkequal(b,"1+0i,Inf+Infi");
+b=csvRead(filename);
+assert_checkequal(b, [1  %inf*(1+%i)]);
+
+write_csv([ 1.1  %inf*(1+%i)],filename)
+b=mgetl(filename);
+assert_checkequal(b,"1.1000000000000001+0i,Inf+Infi");
+b=csvRead(filename);
+assert_checkequal(b, [1.1  %inf*(1+%i)]);
+
+write_csv([ 1.1  1+%i*%inf],filename) 
+b=mgetl(filename);
+assert_checkequal(b,"1.1000000000000001+0i,Nan+Infi");
+b=csvRead(filename);
+assert_checkequal(b, [ 1.1  1+%i*%inf]);