-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1885 from andy840119/re-design-hit-object-validator
Re-design working hit-object validator.
- Loading branch information
Showing
16 changed files
with
399 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
osu.Game.Rulesets.Karaoke.Tests/Objects/Workings/HitObjectWorkingPropertyValidatorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using NUnit.Framework; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Rulesets.Karaoke.Objects.Workings; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Objects.Workings; | ||
|
||
public abstract class HitObjectWorkingPropertyValidatorTest<THitObject, TFlag> | ||
where TFlag : struct, Enum | ||
where THitObject : KaraokeHitObject, new() | ||
{ | ||
protected abstract HitObjectWorkingPropertyValidator<THitObject, TFlag> GetValidatorFromHitObject(THitObject hitObject); | ||
|
||
[Test] | ||
public void RunAllInvalidateTest([Values] TFlag flag) | ||
{ | ||
// run this test case just make sure that all working property are checked. | ||
var validator = GetValidatorFromHitObject(new THitObject()); | ||
Assert.DoesNotThrow(() => validator.Invalidate(flag)); | ||
} | ||
|
||
[Test] | ||
public void RunAllValidateTest([Values] TFlag flag) | ||
{ | ||
// run this test case just make sure that all working property are checked. | ||
var validator = GetValidatorFromHitObject(new THitObject()); | ||
Assert.DoesNotThrow(() => validator.Validate(flag)); | ||
} | ||
|
||
protected void AssetIsValid(THitObject hitObject, TFlag flag, bool isValid) | ||
{ | ||
var validator = GetValidatorFromHitObject(hitObject); | ||
Assert.AreEqual(isValid, validator.IsValid(flag)); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
osu.Game.Rulesets.Karaoke.Tests/Objects/Workings/LyricWorkingPropertyValidatorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using NUnit.Framework; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Rulesets.Karaoke.Objects.Workings; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Objects.Workings; | ||
|
||
public class LyricWorkingPropertyValidatorTest : HitObjectWorkingPropertyValidatorTest<Lyric, LyricWorkingProperty> | ||
{ | ||
protected override HitObjectWorkingPropertyValidator<Lyric, LyricWorkingProperty> GetValidatorFromHitObject(Lyric hitObject) | ||
=> hitObject.WorkingPropertyValidator; | ||
|
||
[Test] | ||
public void TestPage() | ||
{ | ||
var lyric = new Lyric(); | ||
|
||
// should be invalid on the first load. | ||
AssetIsValid(lyric, LyricWorkingProperty.Page, false); | ||
|
||
// page state is valid because assign the property. | ||
Assert.DoesNotThrow(() => lyric.PageIndex = 1); | ||
AssetIsValid(lyric, LyricWorkingProperty.Page, true); | ||
} | ||
|
||
[Test] | ||
public void TestReferenceLyric() | ||
{ | ||
var lyric = new Lyric(); | ||
|
||
// should be invalid on the first load. | ||
AssetIsValid(lyric, LyricWorkingProperty.ReferenceLyric, false); | ||
|
||
// should be valid if change the reference lyric id. | ||
Assert.DoesNotThrow(() => | ||
{ | ||
lyric.ReferenceLyricId = null; | ||
lyric.ReferenceLyric = null; | ||
}); | ||
AssetIsValid(lyric, LyricWorkingProperty.ReferenceLyric, true); | ||
|
||
// should be valid if change the reference lyric id. | ||
Assert.DoesNotThrow(() => | ||
{ | ||
lyric.ReferenceLyricId = 1; | ||
lyric.ReferenceLyric = new Lyric { ID = 1 }; | ||
}); | ||
AssetIsValid(lyric, LyricWorkingProperty.ReferenceLyric, true); | ||
|
||
// should be invalid if change the reference lyric id. | ||
Assert.DoesNotThrow(() => lyric.ReferenceLyricId = 2); | ||
AssetIsValid(lyric, LyricWorkingProperty.ReferenceLyric, false); | ||
|
||
// should be valid again if assign the reference lyric to the matched lyric. | ||
Assert.DoesNotThrow(() => lyric.ReferenceLyric = new Lyric { ID = 2 }); | ||
AssetIsValid(lyric, LyricWorkingProperty.ReferenceLyric, true); | ||
|
||
// should throw the exception if assign the working reference lyric to the unmatched reference lyric id. | ||
Assert.Throws<InvalidWorkingPropertyAssignException>(() => lyric.ReferenceLyric = new Lyric { ID = 3 }); | ||
Assert.Throws<InvalidWorkingPropertyAssignException>(() => lyric.ReferenceLyric = null); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
osu.Game.Rulesets.Karaoke.Tests/Objects/Workings/NoteWorkingPropertyValidatorTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using NUnit.Framework; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
using osu.Game.Rulesets.Karaoke.Objects.Workings; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Objects.Workings; | ||
|
||
public class NoteWorkingPropertyValidatorTest : HitObjectWorkingPropertyValidatorTest<Note, NoteWorkingProperty> | ||
{ | ||
protected override HitObjectWorkingPropertyValidator<Note, NoteWorkingProperty> GetValidatorFromHitObject(Note hitObject) | ||
=> hitObject.WorkingPropertyValidator; | ||
|
||
[Test] | ||
public void TestPage() | ||
{ | ||
var note = new Note(); | ||
|
||
// should be invalid on the first load. | ||
AssetIsValid(note, NoteWorkingProperty.Page, false); | ||
|
||
// page state is valid because assign the property. | ||
Assert.DoesNotThrow(() => note.PageIndex = 1); | ||
AssetIsValid(note, NoteWorkingProperty.Page, true); | ||
} | ||
|
||
[Test] | ||
public void TestReferenceLyric() | ||
{ | ||
var note = new Note(); | ||
|
||
// should be invalid on the first load. | ||
AssetIsValid(note, NoteWorkingProperty.ReferenceLyric, false); | ||
|
||
// should be valid if change the reference lyric id. | ||
Assert.DoesNotThrow(() => | ||
{ | ||
note.ReferenceLyricId = null; | ||
note.ReferenceLyric = null; | ||
}); | ||
AssetIsValid(note, NoteWorkingProperty.ReferenceLyric, true); | ||
|
||
// should be valid if change the reference lyric id. | ||
Assert.DoesNotThrow(() => | ||
{ | ||
note.ReferenceLyricId = 1; | ||
note.ReferenceLyric = new Lyric { ID = 1 }; | ||
}); | ||
AssetIsValid(note, NoteWorkingProperty.ReferenceLyric, true); | ||
|
||
// should be invalid if change the reference lyric id. | ||
Assert.DoesNotThrow(() => note.ReferenceLyricId = 2); | ||
AssetIsValid(note, NoteWorkingProperty.ReferenceLyric, false); | ||
|
||
// should be valid again if assign the reference lyric to the matched lyric. | ||
Assert.DoesNotThrow(() => note.ReferenceLyric = new Lyric { ID = 2 }); | ||
AssetIsValid(note, NoteWorkingProperty.ReferenceLyric, true); | ||
|
||
// should throw the exception if assign the working reference lyric to the unmatched reference lyric id. | ||
Assert.Throws<InvalidWorkingPropertyAssignException>(() => note.ReferenceLyric = new Lyric { ID = 3 }); | ||
Assert.Throws<InvalidWorkingPropertyAssignException>(() => note.ReferenceLyric = null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.