Files
sbox-public/engine/Sandbox.Test/BytePack/Arrays.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

84 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.Json;
namespace bytePack;
public partial class RoundTrip
{
[TestMethod]
public void Array_Values()
{
DoRoundTrip( new int[] { 1, 2, 4, 5, 6, 7, 8 } );
DoRoundTrip( new float[] { 1, 2, 4, 5, 6, 7, 8 } );
DoRoundTrip( new double[] { 1, 2, 4, 5, 6, 7, 8 } );
DoRoundTrip( new byte[] { 1, 2, 4, 5, 6, 7, 8 } );
}
[TestMethod]
public void Array_Strings()
{
DoRoundTrip( new string[] { "one", "two", "three" } );
}
[TestMethod]
public void Array_Values_Empty()
{
DoRoundTrip( new int[0] );
DoRoundTrip( new float[0] );
DoRoundTrip( new double[0] );
DoRoundTrip( new byte[0] );
DoRoundTrip( new string[0] );
DoRoundTrip( Array.Empty<int>() );
DoRoundTrip( Array.Empty<float>() );
DoRoundTrip( Array.Empty<double>() );
DoRoundTrip( Array.Empty<byte>() );
DoRoundTrip( Array.Empty<string>() );
}
[TestMethod]
public void Array_Values_Huge()
{
var array = Array.CreateInstance( typeof( global::Vector3 ), 1_000_000 );
DoRoundTrip( array );
}
[TestMethod]
public void Array_Objects()
{
DoRoundTrip( new object[] { 1 } );
DoRoundTrip( new object[] { 1, 2000.0, "the", 4, 6.0f } );
DoRoundTrip( new object[] { 1, 2000.0, "the", 4, 6.0f, global::Vector3.One, null, null, 34, "poops" } );
var objectArray = new object[] { 1, 2000.0, "the", 4, 6.0f, global::Vector3.One, null, null, 34, "poops" };
var valueArray = new int[] { 1, 2, 3, 4 };
DoRoundTrip( new object[] { 1, 2, objectArray, "the", valueArray } );
}
[TestMethod]
public void Array_Objects_Empty()
{
DoRoundTrip( new object[0] );
DoRoundTrip( Array.Empty<object>() );
}
[TestMethod]
public void Array_Objects_Huge()
{
var list = new List<object>();
for ( int i = 0; i < 1_000_000; i++ )
list.Add( global::Vector3.Random );
DoRoundTrip( list.ToArray() );
}
}