<commit_before>using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pdelvo.Minecraft.Network;
using Pdelvo.Minecraft.Protocol;
using Pdelvo.Minecraft.Protocol.Helper;
using System.Linq;
using Pdelvo.Minecraft.Protocol.Packets;
using System.Threading.Tasks;

namespace Pdelvo.Minecraft.Tests
{
    [TestClass]
    public class PacketTests
    {
        [TestMethod]
        public async Task ClientTest()
        {
            for (int i = ProtocolInformation.MinSupportedClientVersion;
                 i <= ProtocolInformation.MaxSupportedClientVersion;
                 i++)
            {
                var stream = new MemoryStream();
                var client = new ClientRemoteInterface(
                    new BigEndianStream(stream), i);
                foreach (Type item in client.EndPoint.GetPackets())
                {
                    stream = new MemoryStream();
                    client = new ClientRemoteInterface(
                        new BigEndianStream(stream), i);
                    if (PacketEndPoint.IsPacketSupported(item, i) == true)
                    {
                        try
                        {
                            var packet = Activator.CreateInstance(item) as Packet;
                            if (packet is HandshakeRequest) (packet as HandshakeRequest).ProtocolVersion = (byte)i;
                            await client.SendPacketAsync(packet);
                            stream.Seek(0, SeekOrigin.Begin);
                            client.EndPoint.Stream.Context = PacketContext.Server;
                            await client.ReadPacketAsync();
                            Assert.AreEqual(stream.Position, stream.Length, item.Name);
                        }
                        catch (Exception ex)
                        {
                            Assert.Fail(item.ToString(), ex);
                        }
                    }
                }
            }
        }
        [TestMethod]
        public async Task ServerTest()
        {
            for (int i = ProtocolInformation.MinSupportedServerVersion;
                 i <= ProtocolInformation.MaxSupportedServerVersion;
                 i++)
            {
                var stream = new MemoryStream();
                var client = new ServerRemoteInterface(
                    new BigEndianStream(stream), i);
                foreach (Type item in client.EndPoint.GetPackets())
                {
                    stream = new MemoryStream();
                    client = new ServerRemoteInterface(
                        new BigEndianStream(stream), i);
                    if (PacketEndPoint.IsPacketSupported(item, i) == true)
                    {
                        try
                        {
                            var packet = Activator.CreateInstance(item) as Packet;
                            if (packet is HandshakeRequest) (packet as HandshakeRequest).ProtocolVersion = (byte)i;
                            await client.SendPacketAsync(packet);
                            stream.Seek(0, SeekOrigin.Begin);
                            client.EndPoint.Stream.Context = PacketContext.Client;
                            await client.ReadPacketAsync();
                            Assert.AreEqual(stream.Position, stream.Length, item.Name);
                        }
                        catch (Exception ex)
                        {
                            Assert.Fail(item.ToString(), ex);
                        }
                    }
                }
            }
        }
    }<commit_msg>Add player list ping test<commit_after>using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pdelvo.Minecraft.Network;
using Pdelvo.Minecraft.Protocol;
using Pdelvo.Minecraft.Protocol.Helper;
using System.Linq;
using Pdelvo.Minecraft.Protocol.Packets;
using System.Threading.Tasks;

namespace Pdelvo.Minecraft.Tests
{
    [TestClass]
    public class PacketTests
    {
        [TestMethod]
        public async Task ClientTest()
        {
            for (int i = ProtocolInformation.MinSupportedClientVersion;
                 i <= ProtocolInformation.MaxSupportedClientVersion;
                 i++)
            {
                var stream = new MemoryStream();
                var client = new ClientRemoteInterface(
                    new BigEndianStream(stream), i);
                foreach (Type item in client.EndPoint.GetPackets())
                {
                    stream = new MemoryStream();
                    client = new ClientRemoteInterface(
                        new BigEndianStream(stream), i);
                    if (PacketEndPoint.IsPacketSupported(item, i) == true)
                    {
                        try
                        {
                            var packet = Activator.CreateInstance(item) as Packet;
                            if (packet is HandshakeRequest) (packet as HandshakeRequest).ProtocolVersion = (byte)i;
                            await client.SendPacketAsync(packet);
                            stream.Seek(0, SeekOrigin.Begin);
                            client.EndPoint.Stream.Context = PacketContext.Server;
                            await client.ReadPacketAsync();
                            Assert.AreEqual(stream.Position, stream.Length, item.Name);
                        }
                        catch (Exception ex)
                        {
                            Assert.Fail(item.ToString(), ex);
                        }
                    }
                }
            }
        }
        [TestMethod]
        public async Task ServerTest()
        {
            for (int i = ProtocolInformation.MinSupportedServerVersion;
                 i <= ProtocolInformation.MaxSupportedServerVersion;
                 i++)
            {
                var stream = new MemoryStream();
                var client = new ServerRemoteInterface(
                    new BigEndianStream(stream), i);
                foreach (Type item in client.EndPoint.GetPackets())
                {
                    stream = new MemoryStream();
                    client = new ServerRemoteInterface(
                        new BigEndianStream(stream), i);
                    if (PacketEndPoint.IsPacketSupported(item, i) == true)
                    {
                        try
                        {
                            var packet = Activator.CreateInstance(item) as Packet;
                            if (packet is HandshakeRequest) (packet as HandshakeRequest).ProtocolVersion = (byte)i;
                            await client.SendPacketAsync(packet);
                            stream.Seek(0, SeekOrigin.Begin);
                            client.EndPoint.Stream.Context = PacketContext.Client;
                            await client.ReadPacketAsync();
                            Assert.AreEqual(stream.Position, stream.Length, item.Name);
                        }
                        catch (Exception ex)
                        {
                            Assert.Fail(item.ToString(), ex);
                        }
                    }
                }
            }
        }

        [TestMethod]
        public async Task TestPlayerPing()
        {
            var playerPing = new PlayerListPing();
            var stream = new MemoryStream();
            var oldServer = new ServerRemoteInterface(
                new BigEndianStream(stream), 46);

            oldServer.SendPacketAsync(playerPing);
            stream.Seek(0, SeekOrigin.Begin);
            var server = new ClientRemoteInterface(
                new BigEndianStream(stream), 0);

            var packet = server.ReadPacket();

            Assert.IsInstanceOfType(packet, typeof(PlayerListPing));

            var p = packet as PlayerListPing;

            Assert.AreEqual(p.MagicByte, 0);

            stream = new MemoryStream();
            var newServer = new ServerRemoteInterface(
                new BigEndianStream(stream), 47);

            newServer.SendPacketAsync(playerPing);
            stream.Seek(0, SeekOrigin.Begin);
            server = new ClientRemoteInterface(
                new BigEndianStream(stream), 0);

            packet = server.ReadPacket();

            Assert.IsInstanceOfType(packet, typeof(PlayerListPing));

            p = packet as PlayerListPing;

            Assert.AreEqual(p.MagicByte, 1);
            
        }
    }
{'fraction_non_alphanumeric': 0.07561260210035006, 'fraction_numerical': 0.001633605600933489, 'mean_word_length': 1.246069182389937, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2748173', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1862, 'n_words': 411}