<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 osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;

namespace osu.Game.Tests.Visual
{
    public class TestCasePause : TestCasePlayer
    {
        public TestCasePause()
            : base(new OsuRuleset())
        {
        }

        protected override bool AllowFail => true;

        protected override Player CreatePlayer(Ruleset ruleset) => new PausePlayer();

        protected override void AddCheckSteps(Func<Player> player)
        {
            PausePlayer pausable() => (PausePlayer)player();

            base.AddCheckSteps(player);

            AddStep("pause", () => pausable().Pause());
            AddAssert("clock stopped", () => !pausable().GameplayClockContainer.GameplayClock.IsRunning);
            AddAssert("pause overlay shown", () => pausable().PauseOverlayVisible);

            AddStep("resume", () => pausable().Resume());
            AddAssert("pause overlay hidden", () => !pausable().PauseOverlayVisible);

            AddStep("pause too soon", () => pausable().Pause());
            AddAssert("clock not stopped", () => pausable().GameplayClockContainer.GameplayClock.IsRunning);
            AddAssert("pause overlay hidden", () => !pausable().PauseOverlayVisible);

            AddUntilStep(() => pausable().HasFailed, "wait for fail");

            AddAssert("fail overlay shown", () => pausable().FailOverlayVisible);

            AddStep("try to pause", () => pausable().Pause());

            AddAssert("pause overlay hidden", () => !pausable().PauseOverlayVisible);
            AddAssert("fail overlay still shown", () => pausable().FailOverlayVisible);

            AddStep("restart", () => pausable().Restart());

            AddUntilStep(() =>
            {
                pausable().Pause();
                return pausable().PauseOverlayVisible;
            }, "keep trying to pause");

            AddStep("exit", () => pausable().Exit());
            AddUntilStep(() => !pausable().IsCurrentScreen(), "player exited");
        }

        private class PausePlayer : Player
        {
            public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;

            public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;

            public bool FailOverlayVisible => FailOverlay.State == Visibility.Visible;

            public bool PauseOverlayVisible => PauseOverlay.State == Visibility.Visible;
        }
    }
}<commit_msg>Make tests better<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 NUnit.Framework;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;

namespace osu.Game.Tests.Visual
{
    public class TestCasePause : PlayerTestCase
    {
        protected new PausePlayer Player => (PausePlayer)base.Player;

        public TestCasePause()
            : base(new OsuRuleset())
        {
        }

        [Test]
        public void TestPauseResume()
        {
            AddStep("pause", () => Player.Pause());
            AddAssert("clock stopped", () => !Player.GameplayClockContainer.GameplayClock.IsRunning);
            AddAssert("pause overlay shown", () => Player.PauseOverlayVisible);

            AddStep("resume", () => Player.Resume());
            AddAssert("pause overlay hidden", () => !Player.PauseOverlayVisible);
        }

        [Test]
        public void TestPauseTooSoon()
        {
            AddStep("pause", () => Player.Pause());
            AddAssert("clock stopped", () => !Player.GameplayClockContainer.GameplayClock.IsRunning);
            AddStep("resume", () => Player.Resume());
            AddAssert("clock started", () => Player.GameplayClockContainer.GameplayClock.IsRunning);
            AddStep("pause too soon", () => Player.Pause());
            AddAssert("clock not stopped", () => Player.GameplayClockContainer.GameplayClock.IsRunning);
            AddAssert("pause overlay hidden", () => !Player.PauseOverlayVisible);
        }

        [Test]
        public void TestPauseAfterFail()
        {
            AddUntilStep(() => Player.HasFailed, "wait for fail");

            AddAssert("fail overlay shown", () => Player.FailOverlayVisible);

            AddStep("try to pause", () => Player.Pause());

            AddAssert("pause overlay hidden", () => !Player.PauseOverlayVisible);
            AddAssert("fail overlay still shown", () => Player.FailOverlayVisible);
        }

        [Test]
        public void TestExitFromPause()
        {
            AddUntilStep(() =>
            {
                Player.Pause();
                return Player.PauseOverlayVisible;
            }, "keep trying to pause");

            AddStep("exit", () => Player.Exit());
            AddUntilStep(() => !Player.IsCurrentScreen(), "player exited");
        }

        protected override bool AllowFail => true;

        protected override Player CreatePlayer(Ruleset ruleset) => new PausePlayer();

        protected class PausePlayer : Player
        {
            public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;

            public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;

            public bool FailOverlayVisible => FailOverlay.State == Visibility.Visible;

            public bool PauseOverlayVisible => PauseOverlay.State == Visibility.Visible;
        }
    }
}
{'fraction_non_alphanumeric': 0.12744761250429407, 'fraction_numerical': 0.0, 'mean_word_length': 2.574585635359116, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 59, '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': '5435567', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1512, 'n_words': 338}