Skip to content

Commit

Permalink
Fix first-class Span breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz committed Oct 11, 2024
1 parent f399e33 commit 3b2bf41
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public void PeekRef_Empty()
protected override IEnumerable<T> GetEnumerableOf<T>(params T[] contents)
{
ImmutableStack<T> stack = ImmutableStack<T>.Empty;
foreach (T value in contents.Reverse())
foreach (T value in Enumerable.Reverse(contents))
{
stack = stack.Push(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static void Set_CustomComparerTest()

int visited = s_dictionaryData.Length;

Assert.All(s_dictionaryData.Reverse(), element =>
Assert.All(Enumerable.Reverse(s_dictionaryData), element =>
{
string newValue = "new" + element.Value;
Assert.True(ld.Contains(element.Key));
Expand All @@ -154,7 +154,7 @@ public static void Remove_CustomComparerTest()
ObservableStringComparer comparer = new ObservableStringComparer();
ListDictionary ld = Fill(new ListDictionary(comparer), s_dictionaryData);

Assert.All(s_dictionaryData.Reverse(), element =>
Assert.All(Enumerable.Reverse(s_dictionaryData), element =>
{
int originalSize = ld.Count;
Assert.True(ld.Contains(element.Key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ public void Queue_Generic_ToArray_NonWrappedQueue(int count)
Queue<T> collection = new Queue<T>(count + 1);
AddToCollection(collection, count);
T[] elements = collection.ToArray();
elements.Reverse();
Assert.True(Enumerable.SequenceEqual(elements, collection.ToArray<T>()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void Stack_Generic_Constructor_IEnumerable(EnumerableType enumerableType,
_ = numberOfMatchingElements;
IEnumerable<T> enumerable = CreateEnumerable(enumerableType, null, enumerableLength, 0, numberOfDuplicateElements);
Stack<T> stack = new Stack<T>(enumerable);
Assert.Equal(enumerable.ToArray().Reverse(), stack.ToArray());
Assert.Equal(Enumerable.Reverse(enumerable.ToArray()), stack.ToArray());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private static CompositionError CreateCompositionError(CompositionErrorId id, st
private static CompositionError CreateCompositionError(params string[] messages)
{
CompositionError error = null;
foreach (string message in messages.Reverse())
foreach (string message in Enumerable.Reverse(messages))
{
CompositionException exception = null;
if (error != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public void WriteFooterTest_LogicalOperationStack()
listener.Flush();

Assert.Contains("LogicalOperationStack=", listener.Output);
Assert.Contains(string.Join(", ", items.Reverse()), listener.Output);
Assert.Contains(string.Join(", ", Enumerable.Reverse(items)), listener.Output);
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Memory/tests/Memory/CopyTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void TryCopyToArraySegmentImplicit()
Memory<int> srcMemory = src;
bool success = srcMemory.TryCopyTo(segment);
Assert.True(success);
Assert.Equal(src, segment);
Assert.Equal(src.AsSpan(), segment);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Memory/tests/ReadOnlySpan/CopyTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void TryCopyToArraySegmentImplicit()
ReadOnlySpan<int> srcSpan = new ReadOnlySpan<int>(src);
bool success = srcSpan.TryCopyTo(segment);
Assert.True(success);
Assert.Equal(src, segment);
Assert.Equal(src.AsSpan(), segment);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Memory/tests/Span/CopyTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void TryCopyToArraySegmentImplicit()
Span<int> srcSpan = new Span<int>(src);
bool success = srcSpan.TryCopyTo(segment);
Assert.True(success);
Assert.Equal(src, segment);
Assert.Equal(src.AsSpan(), segment);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ internal static void GetStoreValuesAsStringOrStringArray(HeaderDescriptor descri
else
{
Debug.Assert(length > 1, "The header should have been removed when it became empty");
values = multiValue = new string[length];
values = (multiValue = new string[length])!;
}

int currentIndex = 0;
Expand Down Expand Up @@ -1205,8 +1205,8 @@ internal static int GetStoreValuesIntoStringArray(HeaderDescriptor descriptor, o
}

int currentIndex = 0;
ReadStoreValues<object?>(values, info.ParsedAndInvalidValues, descriptor.Parser, ref currentIndex);
ReadStoreValues<string?>(values, info.RawValue, null, ref currentIndex);
ReadStoreValues<object?>(values!, info.ParsedAndInvalidValues, descriptor.Parser, ref currentIndex);
ReadStoreValues<string?>(values!, info.RawValue, null, ref currentIndex);
Debug.Assert(currentIndex == length);

return length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2658,7 +2658,7 @@ public static Tensor<T> PermuteDimensions<T>(this Tensor<T> tensor, params ReadO

if (dimensions.IsEmpty)
{
lengths = tensor._lengths.Reverse().ToArray();
lengths = Enumerable.Reverse(tensor._lengths).ToArray();
permutation = Enumerable.Range(0, tensor.Rank).Reverse().ToArray();
}
else
Expand Down
40 changes: 20 additions & 20 deletions src/libraries/System.Numerics.Tensors/tests/TensorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public static void TensorMultiplyTests()
Tensor<int> t1 = Tensor.Create(Enumerable.Range(0, 3), [3, 1]);
Tensor<int> t2 = Tensor.Multiply(t0.AsReadOnlyTensorSpan(), t1);

Assert.Equal([3,3], t2.Lengths.ToArray());
Assert.Equal([3,3], t2.Lengths);
Assert.Equal(0, t2[0, 0]);
Assert.Equal(0, t2[0, 1]);
Assert.Equal(0, t2[0, 2]);
Expand All @@ -697,7 +697,7 @@ public static void TensorMultiplyTests()

t2 = Tensor.Multiply(t1.AsReadOnlyTensorSpan(), t0);

Assert.Equal([3, 3], t2.Lengths.ToArray());
Assert.Equal([3, 3], t2.Lengths);
Assert.Equal(0, t2[0, 0]);
Assert.Equal(0, t2[0, 1]);
Assert.Equal(0, t2[0, 2]);
Expand All @@ -711,7 +711,7 @@ public static void TensorMultiplyTests()
t1 = Tensor.Create(Enumerable.Range(0, 9), [3, 3]);
t2 = Tensor.Multiply(t0.AsReadOnlyTensorSpan(), t1);

Assert.Equal([3, 3], t2.Lengths.ToArray());
Assert.Equal([3, 3], t2.Lengths);
Assert.Equal(0, t2[0, 0]);
Assert.Equal(1, t2[0, 1]);
Assert.Equal(4, t2[0, 2]);
Expand All @@ -729,7 +729,7 @@ public static void TensorBroadcastTests()
Tensor<int> t0 = Tensor.Create(Enumerable.Range(0, 3), [1, 3, 1, 1, 1]);
Tensor<int> t1 = Tensor.Broadcast<int>(t0, [1, 3, 1, 2, 1]);

Assert.Equal([1, 3, 1, 2, 1], t1.Lengths.ToArray());
Assert.Equal([1, 3, 1, 2, 1], t1.Lengths);

Assert.Equal(0, t1[0, 0, 0, 0, 0]);
Assert.Equal(0, t1[0, 0, 0, 1, 0]);
Expand All @@ -739,7 +739,7 @@ public static void TensorBroadcastTests()
Assert.Equal(2, t1[0, 2, 0, 1, 0]);

t1 = Tensor.Broadcast<int>(t0, [1, 3, 2, 1, 1]);
Assert.Equal([1, 3, 2, 1, 1], t1.Lengths.ToArray());
Assert.Equal([1, 3, 2, 1, 1], t1.Lengths);

Assert.Equal(0, t1[0, 0, 0, 0, 0]);
Assert.Equal(0, t1[0, 0, 1, 0, 0]);
Expand All @@ -751,7 +751,7 @@ public static void TensorBroadcastTests()
t0 = Tensor.Create(Enumerable.Range(0, 3), [1, 3]);
t1 = Tensor.Create(Enumerable.Range(0, 3), [3, 1]);
var t2 = Tensor.Broadcast<int>(t0, [3, 3]);
Assert.Equal([3, 3], t2.Lengths.ToArray());
Assert.Equal([3, 3], t2.Lengths);

Assert.Equal(0, t2[0, 0]);
Assert.Equal(1, t2[0, 1]);
Expand All @@ -765,7 +765,7 @@ public static void TensorBroadcastTests()

t1 = Tensor.Create(Enumerable.Range(0, 3), [3, 1]);
t2 = Tensor.Broadcast<int>(t1, [3, 3]);
Assert.Equal([3, 3], t2.Lengths.ToArray());
Assert.Equal([3, 3], t2.Lengths);

Assert.Equal(0, t2[0, 0]);
Assert.Equal(0, t2[0, 1]);
Expand All @@ -789,11 +789,11 @@ public static void TensorBroadcastTests()
Assert.Equal(2, s1[2, 2]);

var t3 = t2.Slice(0..1, ..);
Assert.Equal([1, 3], t3.Lengths.ToArray());
Assert.Equal([1, 3], t3.Lengths);

t1 = Tensor.Create(Enumerable.Range(0, 3), default);
t2 = Tensor.Broadcast<int>(t1, [3, 3]);
Assert.Equal([3, 3], t2.Lengths.ToArray());
Assert.Equal([3, 3], t2.Lengths);

Assert.Equal(0, t2[0, 0]);
Assert.Equal(1, t2[0, 1]);
Expand All @@ -811,15 +811,15 @@ public static void TensorResizeTests()
{
Tensor<int> t0 = Tensor.Create(Enumerable.Range(0, 8), [2, 2, 2]);
var t1 = Tensor.Resize(t0, [1]);
Assert.Equal([1], t1.Lengths.ToArray());
Assert.Equal([1], t1.Lengths);
Assert.Equal(0, t1[0]);

t1 = Tensor.Resize(t0, [1, 1]);
Assert.Equal([1, 1], t1.Lengths.ToArray());
Assert.Equal([1, 1], t1.Lengths);
Assert.Equal(0, t1[0, 0]);

t1 = Tensor.Resize(t0, [6]);
Assert.Equal([6], t1.Lengths.ToArray());
Assert.Equal([6], t1.Lengths);
Assert.Equal(0, t1[0]);
Assert.Equal(1, t1[1]);
Assert.Equal(2, t1[2]);
Expand All @@ -828,7 +828,7 @@ public static void TensorResizeTests()
Assert.Equal(5, t1[5]);

t1 = Tensor.Resize(t0, [10]);
Assert.Equal([10], t1.Lengths.ToArray());
Assert.Equal([10], t1.Lengths);
Assert.Equal(0, t1[0]);
Assert.Equal(1, t1[1]);
Assert.Equal(2, t1[2]);
Expand All @@ -841,7 +841,7 @@ public static void TensorResizeTests()
Assert.Equal(0, t1[9]);

t1 = Tensor.Resize(t0, [2, 5]);
Assert.Equal([2, 5], t1.Lengths.ToArray());
Assert.Equal([2, 5], t1.Lengths);
Assert.Equal(0, t1[0, 0]);
Assert.Equal(1, t1[0, 1]);
Assert.Equal(2, t1[0, 2]);
Expand All @@ -859,8 +859,8 @@ public static void TensorSplitTests()
{
Tensor<int> t0 = Tensor.Create(Enumerable.Range(0, 8), [2, 2, 2]);
var t1 = Tensor.Split<int>(t0, 2, 0);
Assert.Equal([1, 2, 2], t1[0].Lengths.ToArray());
Assert.Equal([1, 2, 2], t1[1].Lengths.ToArray());
Assert.Equal([1, 2, 2], t1[0].Lengths);
Assert.Equal([1, 2, 2], t1[1].Lengths);
Assert.Equal(0, t1[0][0, 0, 0]);
Assert.Equal(1, t1[0][0, 0, 1]);
Assert.Equal(2, t1[0][0, 1, 0]);
Expand All @@ -871,8 +871,8 @@ public static void TensorSplitTests()
Assert.Equal(7, t1[1][0, 1, 1]);

t1 = Tensor.Split<int>(t0, 2, 1);
Assert.Equal([2, 1, 2], t1[0].Lengths.ToArray());
Assert.Equal([2, 1, 2], t1[1].Lengths.ToArray());
Assert.Equal([2, 1, 2], t1[0].Lengths);
Assert.Equal([2, 1, 2], t1[1].Lengths);
Assert.Equal(0, t1[0][0, 0, 0]);
Assert.Equal(1, t1[0][0, 0, 1]);
Assert.Equal(4, t1[0][1, 0, 0]);
Expand All @@ -883,8 +883,8 @@ public static void TensorSplitTests()
Assert.Equal(7, t1[1][1, 0, 1]);

t1 = Tensor.Split<int>(t0, 2, 2);
Assert.Equal([2, 2, 1], t1[0].Lengths.ToArray());
Assert.Equal([2, 2, 1], t1[1].Lengths.ToArray());
Assert.Equal([2, 2, 1], t1[0].Lengths);
Assert.Equal([2, 2, 1], t1[1].Lengths);
Assert.Equal(0, t1[0][0, 0, 0]);
Assert.Equal(2, t1[0][0, 1, 0]);
Assert.Equal(4, t1[0][1, 0, 0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ProjectReference Include="$(CoreLibProject)" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime\src\System.Runtime.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections\src\System.Collections.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Memory\src\System.Memory.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Threading\src\System.Threading.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void VisualBasicReverseString()
// Arrange

string forwardActual = string.Concat(clusters.SelectMany(cluster => cluster).Select(rune => rune.ToString()));
string reverseExpected = string.Concat(clusters.Reverse().SelectMany(cluster => cluster).Select(rune => rune.ToString()));
string reverseExpected = string.Concat(Enumerable.Reverse(clusters).SelectMany(cluster => cluster).Select(rune => rune.ToString()));

// Act

Expand Down

0 comments on commit 3b2bf41

Please sign in to comment.