Skip to content

Commit

Permalink
separate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze committed Jun 22, 2021
1 parent 535878e commit 80b950b
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions src/libraries/System.Runtime/tests/System/ArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4271,38 +4271,52 @@ private static Bar[] CreateBarArray()
};
}

private static int[] CreateInt32Array() => new int[] { 0, 1, 2, 3 };

[Fact]
public static void Fill_Casting()
public static void Fill_Downcast()
{
Bar[] barArray1 = CreateBarArray();
Array.Fill<object>(barArray1, new Bar() { Value = "x" });
Assert.Equal(new string[] { 'x', 'x', 'x', 'x' }), barArray1.Select(e => e.Value));
Bar[] barArray = CreateBarArray();
Array.Fill<object>(barArray, new Bar() { Value = "x" });
Assert.Equal(new string[] { "x", "x", "x", "x" }, barArray.Select(e => e.Value));
}

Bar[] barArray2 = CreateBarArray();
Array.Fill<object>(barArray2, new Bar() { Value = "x" }, 1, 2);
Assert.Equal(new string[] { "0", "x", "x", "3" }, barArray2.Select(e => e.Value));
[Fact]
public static void FillWithStartIndexAndCount_Downcast()
{
Bar[] barArray = CreateBarArray();
Array.Fill<object>(barArray, new Bar() { Value = "x" }, 1, 2);
Assert.Equal(new string[] { "0", "x", "x", "3" }, barArray.Select(e => e.Value));
}

uint[] uintArray1 = (uint[])(object)CreateInt32Array();
Array.Fill<uint>(uintArray1, 42);
Assert.Equal(new int[] { 42, 42, 42, 42 }, uintArray1);
[Fact]
public static void Fill_Sidecast()
{
uint[] uintArray = (uint[])(object)new int[] { 0, 1, 2, 3 };
Array.Fill<uint>(uintArray, 42);
Assert.Equal(new int[] { 42, 42, 42, 42 }, uintArray);
}

uint[] uintArray2 = (uint[])(object)CreateInt32Array();
Array.Fill<uint>(uintArray2, 42, 1, 2);
Assert.Equal(new int[] { 0, 42, 42, 3 }, uintArray2);
[Fact]
public static void FillWithStartIndexAndCount_Sidecast()
{
uint[] uintArray = (uint[])(object)new int[] { 0, 1, 2, 3 };
Array.Fill<uint>(uintArray, 42, 1, 2);
Assert.Equal(new int[] { 0, 42, 42, 3 }, uintArray);
}

[Fact]
public static void Fill_Casting_Invalid()
public static void Fill_ThrowsArrayTypeMismatchException()
{
Bar[] barArray1 = CreateBarArray();
Assert.Throws<ArrayTypeMismatchException>(() => Array.Fill<object>(barArray1, new Foo()));
Assert.Equal(CreateBarArray(), barArray1);
Bar[] barArray = CreateBarArray();
Assert.Throws<ArrayTypeMismatchException>(() => Array.Fill<object>(barArray, new Foo()));
Assert.Equal(CreateBarArray(), barArray);
}

Bar[] barArray2 = CreateBarArray();
Assert.Throws<ArrayTypeMismatchException>(() => Array.Fill<object>(barArray2, new Foo(), 1, 2));
Assert.Equal(CreateBarArray(), barArray2);
[Fact]
public static void FillWithStartIndexAndCount_ThrowsArrayTypeMismatchException()
{
Bar[] barArray = CreateBarArray();
Assert.Throws<ArrayTypeMismatchException>(() => Array.Fill<object>(barArray, new Foo(), 1, 2));
Assert.Equal(CreateBarArray(), barArray);
}

public static IEnumerable<object[]> Reverse_Generic_Int_TestData()
Expand Down

0 comments on commit 80b950b

Please sign in to comment.