lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [09/47] lucenenet git commit: Codecs.SimpleText.SimpleTextStoredFieldsWriter: Fixed formatting bugs that were causing loss of precision on float/double types when converting to string.
Date Tue, 11 Oct 2016 18:34:54 GMT
Codecs.SimpleText.SimpleTextStoredFieldsWriter: Fixed formatting bugs that were causing loss
of precision on float/double types when converting to string.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/f5cebafd
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/f5cebafd
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/f5cebafd

Branch: refs/heads/master
Commit: f5cebafd057f4f7a59377ae68603892609982d0e
Parents: 450e647
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sat Oct 8 16:21:05 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sat Oct 8 17:15:42 2016 +0700

----------------------------------------------------------------------
 .../SimpleText/SimpleTextStoredFieldsWriter.cs         | 13 ++++++++-----
 .../Index/BaseStoredFieldsFormatTestCase.cs            |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f5cebafd/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
index 7f0fb50..ebfc9b5 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsWriter.cs
@@ -19,6 +19,7 @@ namespace Lucene.Net.Codecs.SimpleText
 {
 
     using System;
+    using System.Globalization;
 
 	using FieldInfo = Index.FieldInfo;
 	using FieldInfos = Index.FieldInfos;
@@ -98,7 +99,7 @@ namespace Lucene.Net.Codecs.SimpleText
         public override void WriteField(FieldInfo info, IndexableField field)
         {
             Write(FIELD);
-            Write(Convert.ToString(info.Number));
+            Write(info.Number.ToString(CultureInfo.InvariantCulture));
             NewLine();
 
             Write(NAME);
@@ -117,7 +118,7 @@ namespace Lucene.Net.Codecs.SimpleText
                     NewLine();
 
                     Write(VALUE);
-                    Write(Convert.ToString((int) n));
+                    Write(((int)n).ToString(CultureInfo.InvariantCulture));
                     NewLine();
                 }
                 else if (n is long?)
@@ -126,7 +127,7 @@ namespace Lucene.Net.Codecs.SimpleText
                     NewLine();
 
                     Write(VALUE);
-                    Write(Convert.ToString((long) n));
+                    Write(((long)n).ToString(CultureInfo.InvariantCulture));
                     NewLine();
                 }
                 else if (n is float?)
@@ -135,7 +136,8 @@ namespace Lucene.Net.Codecs.SimpleText
                     NewLine();
 
                     Write(VALUE);
-                    Write(Convert.ToString((float) n));
+                    // LUCENENET: Need to specify the "R" for round-trip: http://stackoverflow.com/a/611564/181087
+                    Write(((float)n).ToString("R", CultureInfo.InvariantCulture));
                     NewLine();
                 }
                 else if (n is double?)
@@ -144,7 +146,8 @@ namespace Lucene.Net.Codecs.SimpleText
                     NewLine();
 
                     Write(VALUE);
-                    Write(Convert.ToString((double) n));
+                    // LUCENENET: Need to specify the "R" for round-trip: http://stackoverflow.com/a/611564/181087
+                    Write(((double)n).ToString("R", CultureInfo.InvariantCulture));
                     NewLine();
                 }
                 else

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f5cebafd/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs b/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
index 0b11f29..a63eb84 100644
--- a/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
@@ -179,7 +179,7 @@ namespace Lucene.Net.Index
                         Document docExp = docs[testID];
                         for (int i = 0; i < fieldCount; i++)
                         {
-                            Assert.AreEqual("doc " + testID + ", field f" + fieldCount +
" is wrong", docExp.Get("f" + i), doc.Get("f" + i));
+                            assertEquals("doc " + testID + ", field f" + fieldCount + " is
wrong", docExp.Get("f" + i), doc.Get("f" + i));
                         }
                     }
                     r.Dispose();


Mime
View raw message