mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-19 11:49:44 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
70 lines
1.4 KiB
C#
70 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text.Json;
|
|
|
|
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"];
|
|
} );
|
|
}
|
|
}
|