Permalink
Browse files

Adding a test for high precision decimals on queries

  • Loading branch information...
1 parent ae34c88 commit 98276f511266baf6472b54cf77657571607552d7 @ayende ayende committed Aug 3, 2010
@@ -0,0 +1,61 @@
+using System;
+using Raven.Database.Indexing;
+using Xunit;
+using System.Linq;
+
+namespace Raven.Client.Tests.Bugs
+{
+ public class DecimalPrecision : BaseClientTest
+ {
+ [Fact]
+ public void CanDetectHighPrecision_Decimal()
+ {
+ using(var store = NewDocumentStore())
+ {
+ store.DatabaseCommands.PutIndex("Precision",
+ new IndexDefinition
+ {
+ Map = "from doc in docs select new { doc.M }"
+ });
+
+
+ using(var session = store.OpenSession())
+ {
+
+ session.Store
+ (
+ new Foo
+ {
+ D = 1.33d,
+ F = 1.33f,
+ M = 1.33m
+ }
+ );
+
+ session.SaveChanges();
+
+ var count = session.Query<Foo>("Precision")
+ .Customize(x => x.WaitForNonStaleResults(TimeSpan.MaxValue))
+ .Where(x => x.M < 1.331m)
+ .Count();
+
+ Assert.Equal(1, count);
+
+ count = session.Query<Foo>("Precision")
+ .Customize(x => x.WaitForNonStaleResults(TimeSpan.MaxValue))
+ .Where(x => x.M > 1.331m)
+ .Count();
+
+ Assert.Equal(0, count);
+ }
+ }
+ }
+
+ public class Foo
+ {
+ public decimal M { get; set; }
+ public float F { get; set; }
+ public double D { get; set; }
+ }
+ }
+}
@@ -101,6 +101,7 @@
<Compile Include="Bugs\BaseClientTest.cs" />
<Compile Include="Bugs\CanDetectChanges.cs" />
<Compile Include="Bugs\CustomEntityName.cs" />
+ <Compile Include="Bugs\DecimalPrecision.cs" />
<Compile Include="Bugs\Etag.cs" />
<Compile Include="Bugs\ExplicitTransaction.cs" />
<Compile Include="Bugs\ExtendingClientSideViaListeners.cs" />
@@ -17,12 +17,12 @@ public static string NumberToString(long number)
public static string NumberToString(float number)
{
- return "Fx" + number.ToString("F", CultureInfo.InvariantCulture);
+ return "Fx" + number.ToString("G", CultureInfo.InvariantCulture);
}
public static string NumberToString(double number)
{
- return "Dx" + number.ToString("F",CultureInfo.InvariantCulture);
+ return "Dx" + number.ToString("G",CultureInfo.InvariantCulture);
}
public static object StringToNumber(string number)

0 comments on commit 98276f5

Please sign in to comment.