<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.

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Catch.UI;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Configuration;
using osu.Game.Rulesets.Catch.Judgements;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Objects.Drawables;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Rulesets.Catch.Tests
{
    [TestFixture]
    public class TestSceneCatcher : OsuTestScene
    {
        [Resolved]
        private OsuConfigManager config { get; set; }

        private DroppedObjectContainer droppedObjectContainer;

        private TestCatcher catcher;

        [SetUp]
        public void SetUp() => Schedule(() =>
        {
            var difficulty = new BeatmapDifficulty
            {
                CircleSize = 0,
            };

            droppedObjectContainer = new DroppedObjectContainer();

            Child = new Container
            {
                Anchor = Anchor.Centre,
                Children = new Drawable[]
                {
                    droppedObjectContainer,
                    catcher = new TestCatcher(droppedObjectContainer, difficulty),
                }
            };
        });

        [Test]
        public void TestCatcherHyperStateReverted()
        {
            DrawableCatchHitObject drawableObject1 = null;
            DrawableCatchHitObject drawableObject2 = null;
            JudgementResult result1 = null;
            JudgementResult result2 = null;
            AddStep("catch hyper fruit", () =>
            {
                attemptCatch(new Fruit { HyperDashTarget = new Fruit { X = 100 } }, out drawableObject1, out result1);
            });
            AddStep("catch normal fruit", () =>
            {
                attemptCatch(new Fruit(), out drawableObject2, out result2);
            });
            AddStep("revert second result", () =>
            {
                catcher.OnRevertResult(drawableObject2, result2);
            });
            checkHyperDash(true);
            AddStep("revert first result", () =>
            {
                catcher.OnRevertResult(drawableObject1, result1);
            });
            checkHyperDash(false);
        }

        [Test]
        public void TestCatcherAnimationStateReverted()
        {
            DrawableCatchHitObject drawableObject = null;
            JudgementResult result = null;
            AddStep("catch kiai fruit", () =>
            {
                attemptCatch(new TestKiaiFruit(), out drawableObject, out result);
            });
            checkState(CatcherAnimationState.Kiai);
            AddStep("revert result", () =>
            {
                catcher.OnRevertResult(drawableObject, result);
            });
            checkState(CatcherAnimationState.Idle);
        }

        [Test]
        public void TestCatcherCatchWidth()
        {
            float halfWidth = Catcher.CalculateCatchWidth(new BeatmapDifficulty { CircleSize = 0 }) / 2;
            const float center_x = CatchPlayfield.CENTER_X;
            AddStep("move catcher to center", () => catcher.X = center_x);
            AddStep("catch fruit", () =>
            {
                attemptCatch(new Fruit { X = center_x + -halfWidth + 1 });
                attemptCatch(new Fruit { X = center_x + halfWidth - 1 });
            });
            checkPlate(2);
            AddStep("miss fruit", () =>
            {
                attemptCatch(new Fruit { X = center_x + -halfWidth - 1 });
                attemptCatch(new Fruit { X = center_x + halfWidth + 1 });
            });
            checkPlate(2);
        }

        [Test]
        public void TestFruitClampedToCatchableRegion()
        {
            AddStep("catch fruit left", () => attemptCatch(new Fruit { X = -CatchPlayfield.WIDTH }));
            checkPlate(1);
            AddStep("move catcher to right", () => catcher.X = CatchPlayfield.WIDTH);
            AddStep("catch fruit right", () => attemptCatch(new Fruit { X = CatchPlayfield.WIDTH * 2 }));
            checkPlate(2);
        }

        [Test]
        public void TestFruitChangesCatcherState()
        {<commit_msg>Adjust variables slightly for readability<commit_after>﻿// Copyright (c) p<NAME> <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Catch.UI;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Configuration;
using osu.Game.Rulesets.Catch.Judgements;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.Objects.Drawables;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Rulesets.Catch.Tests
{
    [TestFixture]
    public class TestSceneCatcher : OsuTestScene
    {
        [Resolved]
        private OsuConfigManager config { get; set; }

        private DroppedObjectContainer droppedObjectContainer;

        private TestCatcher catcher;

        [SetUp]
        public void SetUp() => Schedule(() =>
        {
            var difficulty = new BeatmapDifficulty
            {
                CircleSize = 0,
            };

            droppedObjectContainer = new DroppedObjectContainer();

            Child = new Container
            {
                Anchor = Anchor.Centre,
                Children = new Drawable[]
                {
                    droppedObjectContainer,
                    catcher = new TestCatcher(droppedObjectContainer, difficulty),
                }
            };
        });

        [Test]
        public void TestCatcherHyperStateReverted()
        {
            DrawableCatchHitObject drawableObject1 = null;
            DrawableCatchHitObject drawableObject2 = null;
            JudgementResult result1 = null;
            JudgementResult result2 = null;
            AddStep("catch hyper fruit", () =>
            {
                attemptCatch(new Fruit { HyperDashTarget = new Fruit { X = 100 } }, out drawableObject1, out result1);
            });
            AddStep("catch normal fruit", () =>
            {
                attemptCatch(new Fruit(), out drawableObject2, out result2);
            });
            AddStep("revert second result", () =>
            {
                catcher.OnRevertResult(drawableObject2, result2);
            });
            checkHyperDash(true);
            AddStep("revert first result", () =>
            {
                catcher.OnRevertResult(drawableObject1, result1);
            });
            checkHyperDash(false);
        }

        [Test]
        public void TestCatcherAnimationStateReverted()
        {
            DrawableCatchHitObject drawableObject = null;
            JudgementResult result = null;
            AddStep("catch kiai fruit", () =>
            {
                attemptCatch(new TestKiaiFruit(), out drawableObject, out result);
            });
            checkState(CatcherAnimationState.Kiai);
            AddStep("revert result", () =>
            {
                catcher.OnRevertResult(drawableObject, result);
            });
            checkState(CatcherAnimationState.Idle);
        }

        [Test]
        public void TestCatcherCatchWidth()
        {
            float halfWidth = Catcher.CalculateCatchWidth(new BeatmapDifficulty { CircleSize = 0 }) / 2;

            AddStep("move catcher to center", () => catcher.X = CatchPlayfield.CENTER_X);

            float leftPlateBounds = CatchPlayfield.CENTER_X - halfWidth;
            float rightPlateBounds = CatchPlayfield.CENTER_X + halfWidth;

            AddStep("catch fruit", () =>
            {
                attemptCatch(new Fruit { X = leftPlateBounds + 1 });
                attemptCatch(new Fruit { X = rightPlateBounds - 1 });
            });
            checkPlate(2);

            AddStep("miss fruit", () =>
            {
                attemptCatch(new Fruit { X = leftPlateBounds - 1 });
                attemptCatch(new Fruit { X = rightPlateBounds + 1 });
            });
            checkPlate(2);
        }

        [Test]
        public void TestFruitClampedToCatchableRegion()
        {
            AddStep("catch fruit left", () => attemptCatch(new Fruit { X = -CatchPlayfield.WIDTH }));
            checkPlate(1);
            AddStep("move catcher to right", () => catcher.X = CatchPlayfield.WIDTH);
            AddStep("catch fruit right", () => attemptCatch(new Fruit { X = CatchPlayfield.WIDTH * 2 }));
            checkPlate(2);
        }

        [Test]
        public void TestFruitChangesCatcherState()
        {
{'fraction_non_alphanumeric': 0.09786324786324786, 'fraction_numerical': 0.0057692307692307696, 'mean_word_length': 1.9026356589147286, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 36, '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': '2488398', 'n_tokens_mistral': 2663, 'n_tokens_neox': 2514, 'n_words': 546}