Files
sbox-public/engine/Sandbox.Test.Unit/Network/NetDictionary.cs
Lorenz Junglas 91f8fcf183 Speed up / parallelize tests (#3587)
- Added Sandbox.Test.Unit project (contains independent tests that can run in parallel) 
- Modify some slow/stress tests (e.g. instead of doing a million iterations settle for 10k).

Tests run almost twice as fast now.
2025-12-10 14:23:00 +01:00

68 lines
1.3 KiB
C#

using System.Collections.Generic;
namespace Networking;
[TestClass]
public class NetDictionary
{
[TestMethod]
public void AddRemoveAndCount()
{
var dictionary = new NetDictionary<string, int>();
Assert.IsTrue( dictionary.Count == 0 );
dictionary.Add( "foo", 0 );
Assert.IsTrue( dictionary.Count == 1 );
Assert.AreEqual( dictionary["foo"], 0 );
Assert.IsTrue( dictionary.ContainsKey( "foo" ) );
dictionary.Remove( "foo" );
Assert.IsTrue( dictionary.Count == 0 );
}
[TestMethod]
public void Iterate()
{
var dictionary = new NetDictionary<string, int>();
dictionary.Add( "a", 1 );
dictionary.Add( "b", 2 );
dictionary.Add( "c", 3 );
var current = 0;
foreach ( var (k, v) in dictionary )
{
var testKey = string.Empty;
if ( current == 0 )
testKey = "a";
else if ( current == 1 )
testKey = "b";
else if ( current == 2 )
testKey = "c";
Assert.AreEqual( k, testKey );
Assert.AreEqual( v, current + 1 );
current++;
}
Assert.AreEqual( 3, current );
Assert.AreEqual( 1, dictionary["a"] );
Assert.AreEqual( 2, dictionary["b"] );
Assert.AreEqual( 3, dictionary["c"] );
}
[TestMethod]
public void ValidAccess()
{
var dictionary = new NetDictionary<string, int>();
Assert.ThrowsException<KeyNotFoundException>( () =>
{
var _ = dictionary["a"];
} );
}
}