Use array initializer

This commit is contained in:
Paul Pacheco 2019-07-24 20:09:10 -05:00
parent 60dcd2acdc
commit eb4c00f8e4

View File

@ -249,7 +249,7 @@ void EnsureThrows(Action<NetworkReader> read, byte[] data = null)
[Test] [Test]
public void TestVector2() public void TestVector2()
{ {
Vector2[] inputs = new Vector2[]{ Vector2[] inputs = {
Vector2.right, Vector2.right,
Vector2.up, Vector2.up,
Vector2.zero, Vector2.zero,
@ -270,7 +270,7 @@ public void TestVector2()
[Test] [Test]
public void TestVector3() public void TestVector3()
{ {
Vector3[] inputs = new Vector3[]{ Vector3[] inputs = {
Vector3.right, Vector3.right,
Vector3.up, Vector3.up,
Vector3.zero, Vector3.zero,
@ -292,7 +292,7 @@ public void TestVector3()
[Test] [Test]
public void TestVector4() public void TestVector4()
{ {
Vector4[] inputs = new Vector4[]{ Vector4[] inputs = {
Vector3.right, Vector3.right,
Vector3.up, Vector3.up,
Vector4.zero, Vector4.zero,
@ -313,7 +313,7 @@ public void TestVector4()
[Test] [Test]
public void TestVector2Int() public void TestVector2Int()
{ {
Vector2Int[] inputs = new Vector2Int[]{ Vector2Int[] inputs = {
Vector2Int.down, Vector2Int.down,
Vector2Int.up, Vector2Int.up,
Vector2Int.left, Vector2Int.left,
@ -335,7 +335,7 @@ public void TestVector2Int()
[Test] [Test]
public void TestVector3Int() public void TestVector3Int()
{ {
Vector3Int[] inputs = new Vector3Int[]{ Vector3Int[] inputs = {
Vector3Int.down, Vector3Int.down,
Vector3Int.up, Vector3Int.up,
Vector3Int.left, Vector3Int.left,
@ -358,7 +358,7 @@ public void TestVector3Int()
[Test] [Test]
public void TestColor() public void TestColor()
{ {
Color[] inputs = new Color[]{ Color[] inputs = {
Color.black, Color.black,
Color.blue, Color.blue,
Color.cyan, Color.cyan,
@ -380,7 +380,7 @@ public void TestColor()
[Test] [Test]
public void TestColor32() public void TestColor32()
{ {
Color32[] inputs = new Color32[]{ Color32[] inputs = {
Color.black, Color.black,
Color.blue, Color.blue,
Color.cyan, Color.cyan,
@ -403,7 +403,7 @@ public void TestColor32()
[Test] [Test]
public void TestQuaternion() public void TestQuaternion()
{ {
Quaternion[] inputs = new Quaternion[]{ Quaternion[] inputs = {
Quaternion.identity, Quaternion.identity,
default, default,
Quaternion.LookRotation(new Vector3(0.3f,0.4f,0.5f)), Quaternion.LookRotation(new Vector3(0.3f,0.4f,0.5f)),
@ -422,7 +422,7 @@ public void TestQuaternion()
[Test] [Test]
public void TestRect() public void TestRect()
{ {
Rect[] inputs = new Rect[]{ Rect[] inputs = {
Rect.zero, Rect.zero,
new Rect(1004.1f,2.001f,4636,400f), new Rect(1004.1f,2.001f,4636,400f),
new Rect(-100.622f,-200f,300f,975.6f), new Rect(-100.622f,-200f,300f,975.6f),
@ -442,7 +442,7 @@ public void TestRect()
[Test] [Test]
public void TestPlane() public void TestPlane()
{ {
Plane[] inputs = new Plane[]{ Plane[] inputs = {
new Plane(new Vector3(-0.24f,0.34f,0.2f), 120.2f), new Plane(new Vector3(-0.24f,0.34f,0.2f), 120.2f),
new Plane(new Vector3(0.133f,0.34f,0.122f), -10.135f), new Plane(new Vector3(0.133f,0.34f,0.122f), -10.135f),
new Plane(new Vector3(0.133f,-0.0f,float.MaxValue), -13.3f), new Plane(new Vector3(0.133f,-0.0f,float.MaxValue), -13.3f),
@ -465,7 +465,7 @@ public void TestPlane()
[Test] [Test]
public void TestRay() public void TestRay()
{ {
Ray[] inputs = new Ray[]{ Ray[] inputs = {
new Ray(Vector3.up,Vector3.down), new Ray(Vector3.up,Vector3.down),
new Ray(new Vector3(0.1f,0.2f,0.3f), new Vector3(0.4f,0.5f,0.6f)), new Ray(new Vector3(0.1f,0.2f,0.3f), new Vector3(0.4f,0.5f,0.6f)),
new Ray(new Vector3(-0.3f,0.5f,0.999f), new Vector3(1f,100.1f,20f)), new Ray(new Vector3(-0.3f,0.5f,0.999f), new Vector3(1f,100.1f,20f)),
@ -484,7 +484,7 @@ public void TestRay()
[Test] [Test]
public void TestMatrix4x4() public void TestMatrix4x4()
{ {
Matrix4x4[] inputs = new Matrix4x4[]{ Matrix4x4[] inputs = {
Matrix4x4.identity, Matrix4x4.identity,
Matrix4x4.zero, Matrix4x4.zero,
Matrix4x4.Scale(Vector3.one * 0.12345f), Matrix4x4.Scale(Vector3.one * 0.12345f),
@ -506,8 +506,7 @@ public void TestReadingInvalidString()
{ {
// These are all bytes which never show up in valid UTF8 encodings. // These are all bytes which never show up in valid UTF8 encodings.
// NetworkReader should gracefully handle maliciously crafted input. // NetworkReader should gracefully handle maliciously crafted input.
byte[] invalidUTF8bytes = new byte[] byte[] invalidUTF8bytes = {
{
0xC0, 0xC1, 0xF5, 0xF6, 0xC0, 0xC1, 0xF5, 0xF6,
0xF7, 0xF8, 0xF9, 0xFA, 0xF7, 0xF8, 0xF9, 0xFA,
0xFB, 0xFC, 0xFD, 0xFE, 0xFB, 0xFC, 0xFD, 0xFE,
@ -583,7 +582,7 @@ public void TestChar()
[Test] [Test]
public void TestUnicodeString() public void TestUnicodeString()
{ {
string[] weirdUnicode = new string[]{ string[] weirdUnicode = {
"𝔲𝔫𝔦𝔠𝔬𝔡𝔢 𝔱𝔢𝔰𝔱", "𝔲𝔫𝔦𝔠𝔬𝔡𝔢 𝔱𝔢𝔰𝔱",
"𝖚𝖓𝖎𝖈𝖔𝖉𝖊 𝖙𝖊𝖘𝖙", "𝖚𝖓𝖎𝖈𝖔𝖉𝖊 𝖙𝖊𝖘𝖙",
"𝐮𝐧𝐢𝐜𝐨𝐝𝐞 𝐭𝐞𝐬𝐭", "𝐮𝐧𝐢𝐜𝐨𝐝𝐞 𝐭𝐞𝐬𝐭",
@ -832,7 +831,7 @@ public void TestGuid()
[Test] [Test]
public void TestFloats() public void TestFloats()
{ {
float[] weirdFloats = new float[]{ float[] weirdFloats = {
0f, 0f,
-0f, -0f,
float.Epsilon, float.Epsilon,
@ -863,7 +862,7 @@ public void TestFloats()
[Test] [Test]
public void TestDoubles() public void TestDoubles()
{ {
double[] weirdDoubles = new double[]{ double[] weirdDoubles = {
0d, 0d,
-0d, -0d,
double.Epsilon, double.Epsilon,
@ -894,7 +893,7 @@ public void TestDoubles()
[Test] [Test]
public void TestDecimals() public void TestDecimals()
{ {
decimal[] weirdDecimals = new decimal[]{ decimal[] weirdDecimals = {
decimal.Zero, decimal.Zero,
-decimal.Zero, -decimal.Zero,
decimal.MaxValue, decimal.MaxValue,
@ -915,11 +914,11 @@ public void TestDecimals()
[Test] [Test]
public void TestFloatBinaryCompatibility() public void TestFloatBinaryCompatibility()
{ {
float[] weirdFloats = new float[]{ float[] weirdFloats = {
((float) Math.PI) / 3.0f, ((float) Math.PI) / 3.0f,
((float) Math.E) / 3.0f ((float) Math.E) / 3.0f
}; };
byte[] expected = new byte[]{ byte[] expected = {
146, 10,134, 63, 146, 10,134, 63,
197,245,103, 63, 197,245,103, 63,
}; };
@ -934,11 +933,11 @@ public void TestFloatBinaryCompatibility()
[Test] [Test]
public void TestDoubleBinaryCompatibility() public void TestDoubleBinaryCompatibility()
{ {
double[] weirdDoubles = new double[]{ double[] weirdDoubles = {
Math.PI / 3.0d, Math.PI / 3.0d,
Math.E / 3.0d Math.E / 3.0d
}; };
byte[] expected = new byte[]{ byte[] expected = {
101,115, 45, 56, 82,193,240, 63, 101,115, 45, 56, 82,193,240, 63,
140,116,112,185,184,254,236, 63, 140,116,112,185,184,254,236, 63,
}; };
@ -953,11 +952,11 @@ public void TestDoubleBinaryCompatibility()
[Test] [Test]
public void TestDecimalBinaryCompatibility() public void TestDecimalBinaryCompatibility()
{ {
decimal[] weirdDecimals = new decimal[]{ decimal[] weirdDecimals = {
((decimal) Math.PI) / 3.0m, ((decimal) Math.PI) / 3.0m,
((decimal) Math.E) / 3.0m ((decimal) Math.E) / 3.0m
}; };
byte[] expected = new byte[]{ byte[] expected = {
0x00, 0x00, 0x1C, 0x00, 0x12, 0x37, 0xD6, 0x21, 0xAB, 0xEA, 0x00, 0x00, 0x1C, 0x00, 0x12, 0x37, 0xD6, 0x21, 0xAB, 0xEA,
0x84, 0x0A, 0x5B, 0x5E, 0xB1, 0x03, 0x00, 0x00, 0x0E, 0x00, 0x84, 0x0A, 0x5B, 0x5E, 0xB1, 0x03, 0x00, 0x00, 0x0E, 0x00,
0x00, 0x00, 0x00, 0x00, 0xF0, 0x6D, 0xC2, 0xA4, 0x68, 0x52, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x6D, 0xC2, 0xA4, 0x68, 0x52,
@ -975,8 +974,8 @@ public void TestDecimalBinaryCompatibility()
[Test] [Test]
public void TestByteEndianness() public void TestByteEndianness()
{ {
byte[] values = new byte[]{0x12,0x43,0x00,0xff,0xab,0x02,0x20}; byte[] values = {0x12,0x43,0x00,0xff,0xab,0x02,0x20};
byte[] expected = new byte[]{0x12,0x43,0x00,0xff,0xab,0x02,0x20}; byte[] expected = {0x12,0x43,0x00,0xff,0xab,0x02,0x20};
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
foreach (byte value in values) foreach (byte value in values)
{ {
@ -988,8 +987,8 @@ public void TestByteEndianness()
[Test] [Test]
public void TestUShortEndianness() public void TestUShortEndianness()
{ {
ushort[] values = new ushort[]{0x0000,0x1234,0xabcd,0xF00F,0x0FF0,0xbeef}; ushort[] values = {0x0000,0x1234,0xabcd,0xF00F,0x0FF0,0xbeef};
byte[] expected = new byte[]{0x00,0x00,0x34,0x12,0xcd,0xab,0x0F,0xF0,0xF0,0x0F,0xef,0xbe}; byte[] expected = {0x00,0x00,0x34,0x12,0xcd,0xab,0x0F,0xF0,0xF0,0x0F,0xef,0xbe};
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
foreach (ushort value in values) foreach (ushort value in values)
{ {
@ -1001,8 +1000,8 @@ public void TestUShortEndianness()
[Test] [Test]
public void TestUIntEndianness() public void TestUIntEndianness()
{ {
uint[] values = new uint[]{0x12345678,0xabcdef09,0xdeadbeef}; uint[] values = {0x12345678,0xabcdef09,0xdeadbeef};
byte[] expected = new byte[]{0x78,0x56,0x34,0x12,0x09,0xef,0xcd,0xab,0xef,0xbe,0xad,0xde}; byte[] expected = {0x78,0x56,0x34,0x12,0x09,0xef,0xcd,0xab,0xef,0xbe,0xad,0xde};
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
foreach (uint value in values) foreach (uint value in values)
{ {
@ -1014,8 +1013,8 @@ public void TestUIntEndianness()
[Test] [Test]
public void TestULongEndianness() public void TestULongEndianness()
{ {
ulong[] values = new ulong[]{0x0123456789abcdef,0xdeaded_beef_c0ffee}; ulong[] values = {0x0123456789abcdef,0xdeaded_beef_c0ffee};
byte[] expected = new byte[]{0xef,0xcd,0xab,0x89,0x67,0x45,0x23,0x01,0xee,0xff,0xc0,0xef,0xbe,0xed,0xad,0xde}; byte[] expected = {0xef,0xcd,0xab,0x89,0x67,0x45,0x23,0x01,0xee,0xff,0xc0,0xef,0xbe,0xed,0xad,0xde};
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
foreach (ulong value in values) foreach (ulong value in values)
{ {
@ -1027,8 +1026,8 @@ public void TestULongEndianness()
[Test] [Test]
public void TestSbyteEndianness() public void TestSbyteEndianness()
{ {
byte[] values = new byte[]{0x12,0x43,0x00,0xff,0xab,0x02,0x20}; byte[] values = {0x12,0x43,0x00,0xff,0xab,0x02,0x20};
byte[] expected = new byte[]{0x12,0x43,0x00,0xff,0xab,0x02,0x20}; byte[] expected = {0x12,0x43,0x00,0xff,0xab,0x02,0x20};
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
foreach (byte value in values) foreach (byte value in values)
{ {
@ -1040,8 +1039,8 @@ public void TestSbyteEndianness()
[Test] [Test]
public void TestShortEndianness() public void TestShortEndianness()
{ {
ushort[] values = new ushort[]{0x0000,0x1234,0xabcd,0xF00F,0x0FF0,0xbeef}; ushort[] values = {0x0000,0x1234,0xabcd,0xF00F,0x0FF0,0xbeef};
byte[] expected = new byte[]{0x00,0x00,0x34,0x12,0xcd,0xab,0x0F,0xF0,0xF0,0x0F,0xef,0xbe}; byte[] expected = {0x00,0x00,0x34,0x12,0xcd,0xab,0x0F,0xF0,0xF0,0x0F,0xef,0xbe};
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
foreach (ushort value in values) foreach (ushort value in values)
{ {
@ -1053,8 +1052,8 @@ public void TestShortEndianness()
[Test] [Test]
public void TestIntEndianness() public void TestIntEndianness()
{ {
uint[] values = new uint[]{0x12345678,0xabcdef09,0xdeadbeef}; uint[] values = {0x12345678,0xabcdef09,0xdeadbeef};
byte[] expected = new byte[]{0x78,0x56,0x34,0x12,0x09,0xef,0xcd,0xab,0xef,0xbe,0xad,0xde}; byte[] expected = {0x78,0x56,0x34,0x12,0x09,0xef,0xcd,0xab,0xef,0xbe,0xad,0xde};
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
foreach (uint value in values) foreach (uint value in values)
{ {
@ -1066,8 +1065,8 @@ public void TestIntEndianness()
[Test] [Test]
public void TestLongEndianness() public void TestLongEndianness()
{ {
ulong[] values = new ulong[]{0x0123456789abcdef,0xdeaded_beef_c0ffee}; ulong[] values = {0x0123456789abcdef,0xdeaded_beef_c0ffee};
byte[] expected = new byte[]{0xef,0xcd,0xab,0x89,0x67,0x45,0x23,0x01,0xee,0xff,0xc0,0xef,0xbe,0xed,0xad,0xde}; byte[] expected = {0xef,0xcd,0xab,0x89,0x67,0x45,0x23,0x01,0xee,0xff,0xc0,0xef,0xbe,0xed,0xad,0xde};
NetworkWriter writer = new NetworkWriter(); NetworkWriter writer = new NetworkWriter();
foreach (ulong value in values) foreach (ulong value in values)
{ {