<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osu.Game.Users;
using osuTK;

namespace osu.Game.Tests.Visual.Multiplayer
{
    public class TestSceneDrawableRoom : OsuTestScene
    {
        public TestSceneDrawableRoom()
        {
            Child = new FillFlowContainer
            {
                Anchor = Anchor.Centre,
                Origin = Anchor.Centre,
                RelativeSizeAxes = Axes.Both,
                Size = new Vector2(0.9f),
                Spacing = new Vector2(10),
                Children = new Drawable[]
                {
                    createDrawableRoom(new Room
                    {
                        Name = { Value = "Room 1" },
                        Status = { Value = new RoomStatusOpen() },
                        EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
                    }),
                    createDrawableRoom(new Room
                    {
                        Name = { Value = "Room 2" },
                        Status = { Value = new RoomStatusPlaying() },
                        EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
                    }),
                    createDrawableRoom(new Room
                    {
                        Name = { Value = "Room 3" },
                        Status = { Value = new RoomStatusEnded() },
                        EndDate = { Value = DateTimeOffset.Now },
                    }),
                    createDrawableRoom(new Room
                    {
                        Name = { Value = "Room 4 (realtime)" },
                        Status = { Value = new RoomStatusOpen() },
                        Category = { Value = RoomCategory.Realtime },
                    }),
                    createDrawableRoom(new Room
                    {
                        Name = { Value = "Room 4 (spotlight)" },
                        Status = { Value = new RoomStatusOpen() },
                        Category = { Value = RoomCategory.Spotlight },
                    }),
                }
            };
        }

        private DrawableRoom createDrawableRoom(Room room)
        {
            room.Host.Value ??= new User { Username = "peppy", Id = 2 };

            if (room.RecentParticipants.Count == 0)
            {
                room.RecentParticipants.AddRange(Enumerable.Range(0, 20).Select(i => new User
                {
                    Id = i,
                    Username = $"User {i}"
                }));
            }

            var drawableRoom = new DrawableRoom(room) { MatchingFilter = true };
            drawableRoom.Action = () => drawableRoom.State = drawableRoom.State == SelectionState.Selected ? SelectionState.NotSelected : SelectionState.Selected;

            return drawableRoom;
        }

        [Test]
        public void TestEnableAndDisablePassword()
        {
            DrawableRoom drawableRoom = null;
            Room room = null;

            AddStep("create room", () => Child = drawableRoom = new DrawableRoom(room = new Room
            {
                Name = { Value = "Room with password" },
                Status = { Value = new RoomStatusOpen() },
                Category = { Value = RoomCategory.Realtime },
            }) { MatchingFilter = true });

            AddAssert("password icon hidden", () => Precision.AlmostEquals(0, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));

            AddStep("set password", () => room.Password.Value = "password");
            AddAssert("password icon visible", () => Precision.AlmostEquals(1, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));

            AddStep("unset password", () => room.Password.Value = string.Empty);
            AddAssert("password icon hidden", () => Precision.AlmostEquals(0, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));
        }
    }
}
<commit_msg>Fix DrawableRoom test scene<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osu.Game.Users;
using osuTK;

namespace osu.Game.Tests.Visual.Multiplayer
{
    public class TestSceneDrawableRoom : OsuTestScene
    {
        [Cached]
        private readonly Bindable<Room> selectedRoom = new Bindable<Room>();

        [Test]
        public void TestMultipleStatuses()
        {
            AddStep("create rooms", () =>
            {
                Child = new FillFlowContainer
                {
                    Anchor = Anchor.Centre,
                    Origin = Anchor.Centre,
                    RelativeSizeAxes = Axes.Both,
                    Size = new Vector2(0.9f),
                    Spacing = new Vector2(10),
                    Children = new Drawable[]
                    {
                        createDrawableRoom(new Room
                        {
                            Name = { Value = "Room 1" },
                            Status = { Value = new RoomStatusOpen() },
                            EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
                        }),
                        createDrawableRoom(new Room
                        {
                            Name = { Value = "Room 2" },
                            Status = { Value = new RoomStatusPlaying() },
                            EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
                        }),
                        createDrawableRoom(new Room
                        {
                            Name = { Value = "Room 3" },
                            Status = { Value = new RoomStatusEnded() },
                            EndDate = { Value = DateTimeOffset.Now },
                        }),
                        createDrawableRoom(new Room
                        {
                            Name = { Value = "Room 4 (realtime)" },
                            Status = { Value = new RoomStatusOpen() },
                            Category = { Value = RoomCategory.Realtime },
                        }),
                        createDrawableRoom(new Room
                        {
                            Name = { Value = "Room 4 (spotlight)" },
                            Status = { Value = new RoomStatusOpen() },
                            Category = { Value = RoomCategory.Spotlight },
                        }),
                    }
                };
            });
        }

        [Test]
        public void TestEnableAndDisablePassword()
        {
            DrawableRoom drawableRoom = null;
            Room room = null;

            AddStep("create room", () => Child = drawableRoom = createDrawableRoom(room = new Room
            {
                Name = { Value = "Room with password" },
                Status = { Value = new RoomStatusOpen() },
                Category = { Value = RoomCategory.Realtime },
            }));

            AddAssert("password icon hidden", () => Precision.AlmostEquals(0, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));

            AddStep("set password", () => room.Password.Value = "password");
            AddAssert("password icon visible", () => Precision.AlmostEquals(1, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));

            AddStep("unset password", () => room.Password.Value = string.Empty);
            AddAssert("password icon hidden", () => Precision.AlmostEquals(0, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));
        }

        private DrawableRoom createDrawableRoom(Room room)
        {
            room.Host.Value ??= new User { Username = "peppy", Id = 2 };

            if (room.RecentParticipants.Count == 0)
            {
                room.RecentParticipants.AddRange(Enumerable.Range(0, 20).Select(i => new User
                {
                    Id = i,
                    Username = $"User {i}"
                }));
            }

            var drawableRoom = new DrawableRoom(room) { MatchingFilter = true };
            drawableRoom.Action = () => drawableRoom.State = drawableRoom.State == SelectionState.Selected ? SelectionState.NotSelected : SelectionState.Selected;

            return drawableRoom;
        }
    }
}

{'fraction_non_alphanumeric': 0.10216046031918359, 'fraction_numerical': 0.0045597654977744, 'mean_word_length': 1.4716930507110277, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 32, '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': '3832022', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2187, 'n_words': 485}