Skip to content

Commit 6c6d8a9

Browse files
David EllingsworthDavid Ellingsworth
David Ellingsworth
authored and
David Ellingsworth
committed
GH-3530: Add tests for float type.
1 parent 48685c8 commit 6c6d8a9

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

src/NHibernate.Test/Async/NHSpecificTest/GH3530/Fixture.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ protected override void CreateSchema()
5353
CreateTable("DateTime");
5454
CreateTable("Double");
5555
CreateTable("Decimal");
56+
CreateTable("Float");
5657

5758
base.CreateSchema();
5859
}
@@ -181,7 +182,7 @@ public async Task TestDoubleAsync(CultureInfo from, CultureInfo to)
181182
double doubleValue = 12.3d;
182183

183184
await (PerformTestAsync<double, DoubleEntity>(from, to, doubleValue,
184-
(expected, actual) => Assert.True(Math.Abs(expected - actual) < double.Epsilon, $"Expected: {expected}\nBut was: {actual}\n")
185+
(expected, actual) => Assert.True(Math.Abs(expected - actual) < double.Epsilon, $"Expected {expected} but was {actual}\n")
185186
));
186187
}
187188

@@ -194,6 +195,16 @@ public async Task TestIntegerAsync(CultureInfo from, CultureInfo to)
194195
await (PerformTestAsync<int, IntegerEntity>(from, to, integerValue, (expected, actual) => Assert.AreEqual(expected, actual)));
195196
}
196197

198+
[Test, TestCaseSource(nameof(GetTestCases))]
199+
public async Task TestFloatAsync(CultureInfo from, CultureInfo to)
200+
{
201+
float floatValue = 12.3f;
202+
203+
await (PerformTestAsync<float, FloatEntity>(from, to, floatValue,
204+
(expected, actual) => Assert.True(Math.Abs(expected - actual) < float.Epsilon, $"Expected {expected} but was {actual}\n")
205+
));
206+
}
207+
197208
private CultureInfo CurrentCulture
198209
{
199210
get => CultureInfo.CurrentCulture;

src/NHibernate.Test/NHSpecificTest/GH3530/Entities.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public class DateTimeEntity : DataEntity<DateTime> { }
1717

1818
public class DoubleEntity : DataEntity<double> { }
1919
public class DecimalEntity : DataEntity<decimal> { }
20+
public class FloatEntity : DataEntity<float> { }
2021
public class NHDateTimeEntity : DataEntity<DateTime> { }

src/NHibernate.Test/NHSpecificTest/GH3530/Fixture.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected override void CreateSchema()
4141
CreateTable("DateTime");
4242
CreateTable("Double");
4343
CreateTable("Decimal");
44+
CreateTable("Float");
4445

4546
base.CreateSchema();
4647
}
@@ -169,7 +170,7 @@ public void TestDouble(CultureInfo from, CultureInfo to)
169170
double doubleValue = 12.3d;
170171

171172
PerformTest<double, DoubleEntity>(from, to, doubleValue,
172-
(expected, actual) => Assert.True(Math.Abs(expected - actual) < double.Epsilon, $"Expected: {expected}\nBut was: {actual}\n")
173+
(expected, actual) => Assert.True(Math.Abs(expected - actual) < double.Epsilon, $"Expected {expected} but was {actual}\n")
173174
);
174175
}
175176

@@ -182,6 +183,16 @@ public void TestInteger(CultureInfo from, CultureInfo to)
182183
PerformTest<int, IntegerEntity>(from, to, integerValue, (expected, actual) => Assert.AreEqual(expected, actual));
183184
}
184185

186+
[Test, TestCaseSource(nameof(GetTestCases))]
187+
public void TestFloat(CultureInfo from, CultureInfo to)
188+
{
189+
float floatValue = 12.3f;
190+
191+
PerformTest<float, FloatEntity>(from, to, floatValue,
192+
(expected, actual) => Assert.True(Math.Abs(expected - actual) < float.Epsilon, $"Expected {expected} but was {actual}\n")
193+
);
194+
}
195+
185196
private CultureInfo CurrentCulture
186197
{
187198
get => CultureInfo.CurrentCulture;

src/NHibernate.Test/NHSpecificTest/GH3530/Mappings.hbm.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<id name="Id" generator="guid.comb" />
2424
<property name="DataValue" column="DataValue"/>
2525
</class>
26+
<class name="FloatEntity" schema-action="none">
27+
<id name="Id" generator="guid.comb"/>
28+
<property name="DataValue" column="DataValue"/>
29+
</class>
2630

2731
<!--
2832
The following classes will be exported as expected by the SchemaExport.

0 commit comments

Comments
 (0)