1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 03:42:57 +08:00

Add reverse pattern visual tests

This commit is contained in:
Arthur Araujo 2024-03-27 08:22:51 -03:00
parent 01a72d5afa
commit 60c93d2c6d
2 changed files with 660 additions and 0 deletions

View File

@ -0,0 +1,313 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Objects;
using osu.Game.Tests.Beatmaps;
using osuTK;
using osuTK.Input;
namespace osu.Game.Rulesets.Catch.Tests.Editor
{
[TestFixture]
public partial class TestSceneCatchReverseSelection : TestSceneEditor
{
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestBeatmap(ruleset, false);
[Test]
public void TestReverseSelectionTwoFruits()
{
float fruit1OldX = default;
float fruit2OldX = default;
addObjects([
new Fruit
{
StartTime = 200,
X = fruit1OldX = 0,
},
new Fruit
{
StartTime = 400,
X = fruit2OldX = 20,
}
]);
selectEverything();
reverseSelection();
AddAssert("fruit1 is at fruit2's X",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(0).EffectiveX,
() => Is.EqualTo(fruit2OldX)
);
AddAssert("fruit2 is at fruit1's X",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(1).EffectiveX,
() => Is.EqualTo(fruit1OldX)
);
AddAssert("fruit2 is not a new combo",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(1).NewCombo,
() => Is.EqualTo(false)
);
}
[Test]
public void TestReverseSelectionThreeFruits()
{
float fruit1OldX = default;
float fruit2OldX = default;
float fruit3OldX = default;
addObjects([
new Fruit
{
StartTime = 200,
X = fruit1OldX = 0,
},
new Fruit
{
StartTime = 400,
X = fruit2OldX = 20,
},
new Fruit
{
StartTime = 600,
X = fruit3OldX = 40,
}
]);
selectEverything();
reverseSelection();
AddAssert("fruit1 is at fruit3's X",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(0).EffectiveX,
() => Is.EqualTo(fruit3OldX)
);
AddAssert("fruit2's X is unchanged",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(1).EffectiveX,
() => Is.EqualTo(fruit2OldX)
);
AddAssert("fruit3's is at fruit1's X",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(2).EffectiveX,
() => Is.EqualTo(fruit1OldX)
);
AddAssert("fruit3 is not a new combo",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(2).NewCombo,
() => Is.EqualTo(false)
);
}
[Test]
public void TestReverseSelectionFruitAndJuiceStream()
{
addObjects([
new Fruit
{
StartTime = 200,
X = 0,
},
new JuiceStream
{
StartTime = 400,
X = 20,
Path = new SliderPath
{
ControlPoints =
{
new PathControlPoint(),
new PathControlPoint(new Vector2(50))
}
}
}
]);
selectEverything();
reverseSelection();
AddAssert("First element is juice stream",
() => EditorBeatmap.HitObjects.First().GetType(),
() => Is.EqualTo(typeof(JuiceStream))
);
AddAssert("Last element is fruit",
() => EditorBeatmap.HitObjects.Last().GetType(),
() => Is.EqualTo(typeof(Fruit))
);
AddAssert("Fruit is not new combo",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(0).NewCombo,
() => Is.EqualTo(false)
);
}
[Test]
public void TestReverseSelectionTwoFruitsAndJuiceStream()
{
addObjects([
new Fruit
{
StartTime = 200,
X = 0,
},
new Fruit
{
StartTime = 400,
X = 20,
},
new JuiceStream
{
StartTime = 600,
X = 40,
Path = new SliderPath
{
ControlPoints =
{
new PathControlPoint(),
new PathControlPoint(new Vector2(50))
}
}
}
]);
selectEverything();
reverseSelection();
AddAssert("First element is juice stream",
() => EditorBeatmap.HitObjects.First().GetType(),
() => Is.EqualTo(typeof(JuiceStream))
);
AddAssert("Middle element is Fruit",
() => EditorBeatmap.HitObjects.ElementAt(1).GetType(),
() => Is.EqualTo(typeof(Fruit))
);
AddAssert("Last element is Fruit",
() => EditorBeatmap.HitObjects.Last().GetType(),
() => Is.EqualTo(typeof(Fruit))
);
AddAssert("Last fruit is not new combo",
() => EditorBeatmap.HitObjects.OfType<Fruit>().Last().NewCombo,
() => Is.EqualTo(false)
);
}
[Test]
public void TestReverseSelectionTwoCombos()
{
float fruit1OldX = default;
float fruit2OldX = default;
float fruit3OldX = default;
float fruit4OldX = default;
float fruit5OldX = default;
float fruit6OldX = default;
addObjects([
new Fruit
{
StartTime = 200,
X = fruit1OldX = 0,
},
new Fruit
{
StartTime = 400,
X = fruit2OldX = 20,
},
new Fruit
{
StartTime = 600,
X = fruit3OldX = 40,
},
new Fruit
{
StartTime = 800,
NewCombo = true,
X = fruit4OldX = 60,
},
new Fruit
{
StartTime = 1000,
X = fruit5OldX = 80,
},
new Fruit
{
StartTime = 1200,
X = fruit6OldX = 100,
}
]);
selectEverything();
reverseSelection();
AddAssert("fruit1 is at fruit6 position",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(0).EffectiveX,
() => Is.EqualTo(fruit6OldX)
);
AddAssert("fruit2 is at fruit5 position",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(1).EffectiveX,
() => Is.EqualTo(fruit5OldX)
);
AddAssert("fruit3 is at fruit4 position",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(2).EffectiveX,
() => Is.EqualTo(fruit4OldX)
);
AddAssert("fruit4 is at fruit3 position",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(3).EffectiveX,
() => Is.EqualTo(fruit3OldX)
);
AddAssert("fruit5 is at fruit2 position",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(4).EffectiveX,
() => Is.EqualTo(fruit2OldX)
);
AddAssert("fruit6 is at fruit1 position",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(5).EffectiveX,
() => Is.EqualTo(fruit1OldX)
);
AddAssert("fruit1 is new combo",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(0).NewCombo,
() => Is.EqualTo(true)
);
AddAssert("fruit4 is new combo",
() => EditorBeatmap.HitObjects.OfType<Fruit>().ElementAt(3).NewCombo,
() => Is.EqualTo(true)
);
}
private void addObjects(CatchHitObject[] hitObjects) => AddStep("Add objects", () => EditorBeatmap.AddRange(hitObjects));
private void selectEverything()
{
AddStep("Select everything", () =>
{
EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects);
});
}
private void reverseSelection()
{
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
}
}
}

View File

@ -0,0 +1,347 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Tests.Beatmaps;
using osuTK;
using osuTK.Input;
namespace osu.Game.Rulesets.Osu.Tests.Editor
{
[TestFixture]
public partial class TestSceneOsuReverseSelection : TestSceneOsuEditor
{
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestBeatmap(ruleset, false);
[Test]
public void TestReverseSelectionTwoCircles()
{
Vector2 circle1OldPosition = default;
Vector2 circle2OldPosition = default;
AddStep("Add circles", () =>
{
var circle1 = new HitCircle
{
StartTime = 0,
Position = circle1OldPosition = new Vector2(208, 240)
};
var circle2 = new HitCircle
{
StartTime = 200,
Position = circle2OldPosition = new Vector2(256, 144)
};
EditorBeatmap.AddRange([circle1, circle2]);
});
AddStep("Select circles", () =>
{
EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects);
});
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
AddAssert("circle1 is at circle2 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(0).Position,
() => Is.EqualTo(circle2OldPosition)
);
AddAssert("circle2 is at circle1 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(1).Position,
() => Is.EqualTo(circle1OldPosition)
);
AddAssert("circle2 is not a new combo",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(1).NewCombo,
() => Is.EqualTo(false)
);
}
[Test]
public void TestReverseSelectionThreeCircles()
{
Vector2 circle1OldPosition = default;
Vector2 circle2OldPosition = default;
Vector2 circle3OldPosition = default;
AddStep("Add circles", () =>
{
var circle1 = new HitCircle
{
StartTime = 0,
Position = circle1OldPosition = new Vector2(208, 240)
};
var circle2 = new HitCircle
{
StartTime = 200,
Position = circle2OldPosition = new Vector2(256, 144)
};
var circle3 = new HitCircle
{
StartTime = 400,
Position = circle3OldPosition = new Vector2(304, 240)
};
EditorBeatmap.AddRange([circle1, circle2, circle3]);
});
AddStep("Select circles", () =>
{
EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects);
});
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
AddAssert("circle1 is at circle3 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(0).Position,
() => Is.EqualTo(circle3OldPosition)
);
AddAssert("circle3 is at circle1 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(2).Position,
() => Is.EqualTo(circle1OldPosition)
);
AddAssert("circle3 is not a new combo",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(2).NewCombo,
() => Is.EqualTo(false)
);
}
[Test]
public void TestReverseSelectionCircleAndSlider()
{
Vector2 circleOldPosition = default;
Vector2 sliderHeadOldPosition = default;
Vector2 sliderTailOldPosition = default;
AddStep("Add objects", () =>
{
var circle = new HitCircle
{
StartTime = 0,
Position = circleOldPosition = new Vector2(208, 240)
};
var slider = new Slider
{
StartTime = 200,
Position = sliderHeadOldPosition = new Vector2(257, 144),
Path = new SliderPath
{
ControlPoints =
{
new PathControlPoint(),
new PathControlPoint(new Vector2(100))
}
}
};
sliderTailOldPosition = slider.EndPosition;
EditorBeatmap.AddRange([circle, slider]);
});
AddStep("Select objects", () =>
{
var circle = (HitCircle)EditorBeatmap.HitObjects[0];
var slider = (Slider)EditorBeatmap.HitObjects[1];
EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects);
});
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
AddAssert("circle is at the same position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(0).Position,
() => Is.EqualTo(circleOldPosition)
);
AddAssert("Slider head is at slider tail", () =>
Vector2.Distance(EditorBeatmap.HitObjects.OfType<Slider>().ElementAt(0).Position, sliderTailOldPosition) < 1);
AddAssert("Slider tail is at slider head", () =>
Vector2.Distance(EditorBeatmap.HitObjects.OfType<Slider>().ElementAt(0).EndPosition, sliderHeadOldPosition) < 1);
}
[Test]
public void TestReverseSelectionTwoCirclesAndSlider()
{
Vector2 circle1OldPosition = default;
Vector2 circle2OldPosition = default;
Vector2 sliderHeadOldPosition = default;
Vector2 sliderTailOldPosition = default;
AddStep("Add objects", () =>
{
var circle1 = new HitCircle
{
StartTime = 0,
Position = circle1OldPosition = new Vector2(208, 240)
};
var circle2 = new HitCircle
{
StartTime = 200,
Position = circle2OldPosition = new Vector2(256, 144)
};
var slider = new Slider
{
StartTime = 200,
Position = sliderHeadOldPosition = new Vector2(304, 240),
Path = new SliderPath
{
ControlPoints =
{
new PathControlPoint(),
new PathControlPoint(new Vector2(100))
}
}
};
sliderTailOldPosition = slider.EndPosition;
EditorBeatmap.AddRange([circle1, circle2, slider]);
});
AddStep("Select objects", () =>
{
EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects);
});
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
AddAssert("circle1 is at circle2 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(0).Position,
() => Is.EqualTo(circle2OldPosition)
);
AddAssert("circle2 is at circle1 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(1).Position,
() => Is.EqualTo(circle1OldPosition)
);
AddAssert("Slider head is at slider tail", () =>
Vector2.Distance(EditorBeatmap.HitObjects.OfType<Slider>().ElementAt(0).Position, sliderTailOldPosition) < 1);
AddAssert("Slider tail is at slider head", () =>
Vector2.Distance(EditorBeatmap.HitObjects.OfType<Slider>().ElementAt(0).EndPosition, sliderHeadOldPosition) < 1);
}
[Test]
public void TestReverseSelectionTwoCombos()
{
Vector2 circle1OldPosition = default;
Vector2 circle2OldPosition = default;
Vector2 circle3OldPosition = default;
Vector2 circle4OldPosition = default;
Vector2 circle5OldPosition = default;
Vector2 circle6OldPosition = default;
AddStep("Add circles", () =>
{
var circle1 = new HitCircle
{
StartTime = 0,
Position = circle1OldPosition = new Vector2(216, 240)
};
var circle2 = new HitCircle
{
StartTime = 200,
Position = circle2OldPosition = new Vector2(120, 192)
};
var circle3 = new HitCircle
{
StartTime = 400,
Position = circle3OldPosition = new Vector2(216, 144)
};
var circle4 = new HitCircle
{
StartTime = 646,
NewCombo = true,
Position = circle4OldPosition = new Vector2(296, 240)
};
var circle5 = new HitCircle
{
StartTime = 846,
Position = circle5OldPosition = new Vector2(392, 162)
};
var circle6 = new HitCircle
{
StartTime = 1046,
Position = circle6OldPosition = new Vector2(296, 144)
};
EditorBeatmap.AddRange([circle1, circle2, circle3, circle4, circle5, circle6]);
});
AddStep("Select circles", () =>
{
EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects);
});
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
AddAssert("circle1 is at circle6 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(0).Position,
() => Is.EqualTo(circle6OldPosition)
);
AddAssert("circle2 is at circle5 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(1).Position,
() => Is.EqualTo(circle5OldPosition)
);
AddAssert("circle3 is at circle4 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(2).Position,
() => Is.EqualTo(circle4OldPosition)
);
AddAssert("circle4 is at circle3 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(3).Position,
() => Is.EqualTo(circle3OldPosition)
);
AddAssert("circle5 is at circle2 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(4).Position,
() => Is.EqualTo(circle2OldPosition)
);
AddAssert("circle6 is at circle1 position",
() => EditorBeatmap.HitObjects.OfType<HitCircle>().ElementAt(5).Position,
() => Is.EqualTo(circle1OldPosition)
);
}
}
}