<commit_before>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System.Collections.Generic;
using System.Linq;
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Select;
using osu.Game.Tests.Beatmaps;

namespace osu.Game.Tests.Visual
{
    public class TestCaseBeatmapInfoWedge : OsuTestCase
    {
        private RulesetStore rulesets;
        private TestBeatmapInfoWedge infoWedge;
        private readonly List<Beatmap> beatmaps = new List<Beatmap>();
        private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();

        [BackgroundDependencyLoader]
        private void load(OsuGameBase game, RulesetStore rulesets)
        {
            this.rulesets = rulesets;

            beatmap.BindTo(game.Beatmap);
        }

        protected override void LoadComplete()
        {
            base.LoadComplete();

            Add(infoWedge = new TestBeatmapInfoWedge
            {
                Size = new Vector2(0.5f, 245),
                RelativeSizeAxes = Axes.X,
                Margin = new MarginPadding
                {
                    Top = 20,
                }
            });

            AddStep("hide", () =>
            {
                infoWedge.State = Visibility.Hidden;
                Content.FadeOut(100);
            });

            AddStep("show", () =>
            {
                Content.FadeInFromZero(250);
                infoWedge.State = Visibility.Visible;
                infoWedge.UpdateBeatmap(beatmap);
            });

            foreach (var rulesetInfo in rulesets.AvailableRulesets)
            {
                var ruleset = rulesetInfo.CreateInstance();
                beatmaps.Add(createTestBeatmap(rulesetInfo));

                var name = rulesetInfo.ShortName;
                selectBeatmap(name);

                // TODO: check InfoLabels of other rulesets
                switch (ruleset)
                {
                    case OsuRuleset osu:
                        testOsuBeatmap(osu);
                        break;
                }
            }

            testNullBeatmap();
        }

        private void testOsuBeatmap(OsuRuleset ruleset)
        {
            AddAssert("check version", () => infoWedge.Info.VersionLabel.Text == $"{ruleset.ShortName}Version");
            AddAssert("check title", () => infoWedge.Info.TitleLabel.Text == $"{ruleset.ShortName}Source — {ruleset.ShortName}Title");
            AddAssert("check artist", () => infoWedge.Info.ArtistLabel.Text == $"{ruleset.ShortName}Artist");
            AddAssert("check author", () => infoWedge.Info.MapperContainer.Children.OfType<OsuSpriteText>().Any(s => s.Text == $"{ruleset.ShortName}Author"));
            // TODO: check InfoLabels
        }

        private void testNullBeatmap()
        {
            selectNullBeatmap();
            AddAssert("check empty version", () => string.IsNullOrEmpty(infoWedge.Info.VersionLabel.Text));
            AddAssert("check default title", () => infoWedge.Info.TitleLabel.Text == beatmap.Default.BeatmapInfo.Metadata.Title);
            AddAssert("check default artist", () => infoWedge.Info.ArtistLabel.Text == beatmap.Default.BeatmapInfo.Metadata.Artist);
            AddAssert("check empty author", () => !infoWedge.Info.MapperContainer.Children.Any());
            AddAssert("check empty infos", () => !infoWedge.Info.InfoLabelContainer.Children.Any());
        }

        private void selectBeatmap(string name)
        {
            AddStep($"select {name} beatmap", () =>
            {
                beatmap.Value = new TestWorkingBeatmap(beatmaps.First(b => b.BeatmapInfo.Ruleset.ShortName == name));
                infoWedge.UpdateBeatmap(beatmap);
            });
        }

        private void selectNullBeatmap()
        {
            AddStep("select null beatmap", () =>
            {
                beatmap.Value = beatmap.Default;
                infoWedge.UpdateBeatmap(beatmap);
            });
        }

        private Beatmap createTestBeatmap(RulesetInfo ruleset)
        {
            return new Beatmap
            {
                BeatmapInfo = new BeatmapInfo
                {
                    Metadata = new BeatmapMetadata
                    {
                        AuthorString = $"{ruleset.ShortName}Author",
                        Artist = $"{ruleset.ShortName}Artist",
                        Source = $"{ruleset.ShortName}Source",
                        Title = $"{ruleset.ShortName}Title"
                    },
                    Ruleset = ruleset,
                    StarDifficulty = 6,
                    Version = $"{ruleset.ShortName}Version"
                },
                HitObjects = new List<HitObject>() // TODO: Fill it with something depending on ruleset?
            };
        }

        private class TestBeatmapInfoWedge : BeatmapInfoWedge
        {
            public new BufferedWedgeInfo Info => base.Info;
        }
    }
}
<commit_msg>finished up visual tests<commit_after>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System.Collections.Generic;
using System.Linq;
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Select;
using osu.Game.Tests.Beatmaps;

namespace osu.Game.Tests.Visual
{
    public class TestCaseBeatmapInfoWedge : OsuTestCase
    {
        private RulesetStore rulesets;
        private TestBeatmapInfoWedge infoWedge;
        private readonly List<Beatmap> beatmaps = new List<Beatmap>();
        private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();

        [BackgroundDependencyLoader]
        private void load(OsuGameBase game, RulesetStore rulesets)
        {
            this.rulesets = rulesets;

            beatmap.BindTo(game.Beatmap);
        }

        protected override void LoadComplete()
        {
            base.LoadComplete();

            Add(infoWedge = new TestBeatmapInfoWedge
            {
                Size = new Vector2(0.5f, 245),
                RelativeSizeAxes = Axes.X,
                Margin = new MarginPadding
                {
                    Top = 20,
                }
            });

            AddStep("hide", () =>
            {
                infoWedge.State = Visibility.Hidden;
                Content.FadeOut(100);
            });

            AddStep("show", () =>
            {
                Content.FadeInFromZero(250);
                infoWedge.State = Visibility.Visible;
                infoWedge.UpdateBeatmap(beatmap);
            });

            foreach (var rulesetInfo in rulesets.AvailableRulesets)
            {
                var ruleset = rulesetInfo.CreateInstance();
                beatmaps.Add(createTestBeatmap(rulesetInfo));

                var name = rulesetInfo.ShortName;
                selectBeatmap(name);

                // TODO: adjust cases once more info is shown for other gamemodes
                switch (ruleset)
                {
                    case OsuRuleset osu:
                        testOsuBeatmap(osu);
                        testInfoLabels(5);
                        break;
                    default:
                        testInfoLabels(2);
                        break;
                }
            }

            testNullBeatmap();
        }

        private void testOsuBeatmap(OsuRuleset ruleset)
        {
            AddAssert("check version", () => infoWedge.Info.VersionLabel.Text == $"{ruleset.ShortName}Version");
            AddAssert("check title", () => infoWedge.Info.TitleLabel.Text == $"{ruleset.ShortName}Source — {ruleset.ShortName}Title");
            AddAssert("check artist", () => infoWedge.Info.ArtistLabel.Text == $"{ruleset.ShortName}Artist");
            AddAssert("check author", () => infoWedge.Info.MapperContainer.Children.OfType<OsuSpriteText>().Any(s => s.Text == $"{ruleset.ShortName}Author"));
        }

        private void testInfoLabels(int expectedCount)
        {
            AddAssert("check infolabels exists", () => infoWedge.Info.InfoLabelContainer.Children.Any());
            AddAssert("check infolabels count", () => infoWedge.Info.InfoLabelContainer.Children.Count == expectedCount);
        }

        private void testNullBeatmap()
        {
            selectNullBeatmap();
            AddAssert("check empty version", () => string.IsNullOrEmpty(infoWedge.Info.VersionLabel.Text));
            AddAssert("check default title", () => infoWedge.Info.TitleLabel.Text == beatmap.Default.BeatmapInfo.Metadata.Title);
            AddAssert("check default artist", () => infoWedge.Info.ArtistLabel.Text == beatmap.Default.BeatmapInfo.Metadata.Artist);
            AddAssert("check empty author", () => !infoWedge.Info.MapperContainer.Children.Any());
            AddAssert("check no infolabels", () => !infoWedge.Info.InfoLabelContainer.Children.Any());
        }

        private void selectBeatmap(string name)
        {
            AddStep($"select {name} beatmap", () =>
            {
                beatmap.Value = new TestWorkingBeatmap(beatmaps.First(b => b.BeatmapInfo.Ruleset.ShortName == name));
                infoWedge.UpdateBeatmap(beatmap);
            });
        }

        private void selectNullBeatmap()
        {
            AddStep("select null beatmap", () =>
            {
                beatmap.Value = beatmap.Default;
                infoWedge.UpdateBeatmap(beatmap);
            });
        }

        private Beatmap createTestBeatmap(RulesetInfo ruleset)
        {
            List<HitObject> objects = new List<HitObject>();
            for (double i = 0; i < 50000; i += 1000)
                objects.Add(new HitObject { StartTime = i });

            return new Beatmap
            {
                BeatmapInfo = new BeatmapInfo
                {
                    Metadata = new BeatmapMetadata
                    {
                        AuthorString = $"{ruleset.ShortName}Author",
                        Artist = $"{ruleset.ShortName}Artist",
                        Source = $"{ruleset.ShortName}Source",
                        Title = $"{ruleset.ShortName}Title"
                    },
                    Ruleset = ruleset,
                    StarDifficulty = 6,
                    Version = $"{ruleset.ShortName}Version"
                },
                HitObjects = objects
            };
        }

        private class TestBeatmapInfoWedge : BeatmapInfoWedge
        {
            public new BufferedWedgeInfo Info => base.Info;
        }
    }
}

{'fraction_non_alphanumeric': 0.10199633859297358, 'fraction_numerical': 0.005056228750762793, 'mean_word_length': 1.6299862448418156, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 54, 'https://': 2, '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': '6809244', 'n_tokens_mistral': 3213, 'n_tokens_neox': 2941, 'n_words': 533}