-
Notifications
You must be signed in to change notification settings - Fork 390
Expand file tree
/
Copy pathTest_ArrayExtensions.cs
More file actions
84 lines (68 loc) · 2.12 KB
/
Test_ArrayExtensions.cs
File metadata and controls
84 lines (68 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CommunityToolkit.Common.UnitTests.Extensions;
[TestClass]
public class Test_ArrayExtensions
{
[TestMethod]
public void Test_ArrayExtensions_Jagged_GetColumn()
{
int[][] array =
{
new int[] { 5, 2, 4 },
new int[] { 6, 3 },
new int[] { 7 }
};
int[]? col = array.GetColumn(1).ToArray();
CollectionAssert.AreEquivalent(new int[] { 2, 3, 0 }, col);
}
[TestMethod]
public void Test_ArrayExtensions_Jagged_GetColumn_Exception()
{
int[][] array =
{
new int[] { 5, 2, 4 },
new int[] { 6, 3 },
new int[] { 7 }
};
_ = Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
{
_ = array.GetColumn(-1).ToArray();
});
_ = Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
{
_ = array.GetColumn(3).ToArray();
});
}
[TestMethod]
public void Test_ArrayExtensions_Rectangular_ToString()
{
int[,] array =
{
{ 5, 2, 4 },
{ 6, 3, -1 },
{ 7, 0, 9 }
};
string value = array.ToArrayString();
Debug.WriteLine(value);
Assert.AreEqual("[[5,\t2,\t4]," + Environment.NewLine + " [6,\t3,\t-1]," + Environment.NewLine + " [7,\t0,\t9]]", value);
}
[TestMethod]
public void Test_ArrayExtensions_Jagged_ToString()
{
int[][] array =
{
new int[] { 5, 2 },
new int[] { 6, 3, -1, 2 },
new int[] { 7, 0, 9 }
};
string value = array.ToArrayString();
Debug.WriteLine(value);
Assert.AreEqual("[[5,\t2]," + Environment.NewLine + " [6,\t3,\t-1,\t2]," + Environment.NewLine + " [7,\t0,\t9]]", value);
}
}