Skip to content

Commit 49323f2

Browse files
author
Ivan Matantsev
committed
clean test code
1 parent ef950eb commit 49323f2

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

test/Microsoft.ML.Tests/CollectionDataSourceTests.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,9 @@ public class ConversionNullalbeClass
241241

242242
public bool CompareObjectValues(object x, object y, Type type)
243243
{
244-
//handle string conversion.
245-
//by default behaviour for DvText is to be empty string, while for string is null.
246-
//so if we do roundtrip string-> DvText -> string all null string become empty strings.
247-
//therefore replace all null values to empty string if field is string.
244+
// By default behaviour for DvText is to be empty string, while for string is null.
245+
// So if we do roundtrip string-> DvText -> string all null string become empty strings.
246+
// Therefore replace all null values to empty string if field is string.
248247
if (type == typeof(string) && x == null)
249248
x = "";
250249
if (type == typeof(string) && y == null)
@@ -272,7 +271,6 @@ public bool CompareThrougReflection<T>(T x, T y)
272271
if (!CompareObjectValues(xvalue, yvalue, field.FieldType))
273272
return false;
274273
}
275-
276274
}
277275
return true;
278276
}
@@ -323,9 +321,9 @@ public void BackAndForthConversionWithBasicTypes()
323321
new ConversionNullalbeClass(){ fInt=int.MaxValue, fuInt=uint.MaxValue, fBool=true, fsByte=sbyte.MaxValue, fByte = byte.MaxValue,
324322
fDouble =double.MaxValue, fFloat=float.MaxValue, fLong=long.MaxValue, fuLong = ulong.MaxValue,
325323
fShort =short.MaxValue, fuShort = ushort.MaxValue, fString="ooh"},
326-
new ConversionNullalbeClass(){ fInt=int.MinValue+1, fuInt=uint.MinValue+1, fBool=true, fsByte=sbyte.MinValue+1, fByte = byte.MinValue+1,
327-
fDouble =double.MinValue+1, fFloat=float.MinValue+1, fLong=long.MinValue+1, fuLong = ulong.MinValue+1,
328-
fShort =short.MinValue+1, fuShort = ushort.MinValue+1, fString=""},
324+
new ConversionNullalbeClass(){ fInt=int.MinValue+1, fuInt=uint.MinValue, fBool=false, fsByte=sbyte.MinValue+1, fByte = byte.MinValue,
325+
fDouble =double.MinValue+1, fFloat=float.MinValue+1, fLong=long.MinValue+1, fuLong = ulong.MinValue,
326+
fShort =short.MinValue+1, fuShort = ushort.MinValue, fString=""},
329327
new ConversionNullalbeClass()
330328
};
331329

@@ -406,10 +404,8 @@ public void ConversionMinValueToNullBehavior()
406404
new ConversionLossMinValueClass(){ fSByte = null,fInt = null,fLong = null,fShort = null},
407405
new ConversionLossMinValueClass(){fSByte = sbyte.MinValue,fInt = int.MinValue,fLong = long.MinValue,fShort = short.MinValue}
408406
};
409-
410407
foreach (var field in typeof(ConversionLossMinValueClass).GetFields())
411408
{
412-
413409
var dataView = ComponentCreation.CreateDataView(env, data);
414410
var enumerator = dataView.AsEnumerable<ConversionLossMinValueClass>(env, false).GetEnumerator();
415411
while (enumerator.MoveNext())
@@ -430,16 +426,14 @@ public void ClassWithConstFieldsConversion()
430426
new ClassWithConstField(){ fInt=-1, fString ="" },
431427
new ClassWithConstField(){ fInt=0, fString =null }
432428
};
429+
433430
using (var env = new TlcEnvironment())
434431
{
435432
var dataView = ComponentCreation.CreateDataView(env, data);
436433
var enumeratorSimple = dataView.AsEnumerable<ClassWithConstField>(env, false).GetEnumerator();
437-
438434
var originalEnumerator = data.GetEnumerator();
439435
while (enumeratorSimple.MoveNext() && originalEnumerator.MoveNext())
440-
{
441436
Assert.True(CompareThrougReflection(enumeratorSimple.Current, originalEnumerator.Current));
442-
}
443437
Assert.True(!enumeratorSimple.MoveNext() && !originalEnumerator.MoveNext());
444438
}
445439
}
@@ -459,6 +453,7 @@ public class ClassWithArrays
459453
public double[] fDouble;
460454
public bool[] fBool;
461455
}
456+
462457
public class ClassWithNullableArrays
463458
{
464459
public string[] fString;
@@ -475,7 +470,6 @@ public class ClassWithNullableArrays
475470
public bool?[] fBool;
476471
}
477472

478-
479473
[Fact]
480474
public void BackAndForthConversionWithArrays()
481475
{
@@ -500,6 +494,7 @@ public void BackAndForthConversionWithArrays()
500494
new ClassWithNullableArrays(){ fInt = new int?[3]{ -2,1,0}, fFloat = new float?[3]{ 0.99f, 0f, -0.99f}, fString =new string[2]{ "lola","hola"} },
501495
new ClassWithNullableArrays()
502496
};
497+
503498
using (var env = new TlcEnvironment())
504499
{
505500
var dataView = ComponentCreation.CreateDataView(env, data);
@@ -521,7 +516,5 @@ public void BackAndForthConversionWithArrays()
521516
Assert.True(!enumeratorNullable.MoveNext() && !originalNullalbleEnumerator.MoveNext());
522517
}
523518
}
524-
525-
526519
}
527520
}

0 commit comments

Comments
 (0)