-
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 #1809 from andy840119/implement-base-class-for-gen…
…erator Implement base class for generator and detector.
- Loading branch information
Showing
41 changed files
with
551 additions
and
531 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
24 changes: 0 additions & 24 deletions
24
osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/BaseGeneratorTest.cs
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/BasePropertyDetectorTest.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,69 @@ | ||
// 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.Edit.Generator; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator; | ||
|
||
public abstract class BasePropertyDetectorTest<TDetector, TItem, TProperty, TConfig> | ||
: BasePropertyDetectorTest<TDetector, TItem, TProperty> | ||
where TDetector : PropertyDetector<TItem, TProperty> | ||
where TConfig : IHasConfig<TConfig>, new() | ||
{ | ||
protected static TConfig GeneratorConfig(Action<TConfig>? action = null) | ||
{ | ||
var config = new TConfig(); | ||
action?.Invoke(config); | ||
return config; | ||
} | ||
|
||
protected static TConfig GeneratorDefaultConfig(Action<TConfig>? action = null) | ||
{ | ||
var config = new TConfig().CreateDefaultConfig(); | ||
action?.Invoke(config); | ||
return config; | ||
} | ||
|
||
protected static TDetector GenerateDetector(TConfig config) | ||
{ | ||
if (Activator.CreateInstance(typeof(TDetector), config) is not TDetector detector) | ||
throw new ArgumentNullException(nameof(detector)); | ||
|
||
return detector; | ||
} | ||
|
||
protected static void CheckCanDetect(TItem item, bool canDetect, TConfig config) | ||
{ | ||
var detector = GenerateDetector(config); | ||
|
||
CheckCanDetect(item, canDetect, detector); | ||
} | ||
|
||
protected void CheckDetectResult(TItem item, TProperty expected, TConfig config) | ||
{ | ||
var detector = GenerateDetector(config); | ||
|
||
CheckDetectResult(item, expected, detector); | ||
} | ||
} | ||
|
||
public abstract class BasePropertyDetectorTest<TDetector, TItem, TProperty> | ||
where TDetector : PropertyDetector<TItem, TProperty> | ||
{ | ||
protected static void CheckCanDetect(TItem item, bool canDetect, TDetector detector) | ||
{ | ||
bool actual = detector.CanDetect(item); | ||
Assert.AreEqual(canDetect, actual); | ||
} | ||
|
||
protected void CheckDetectResult(TItem item, TProperty expected, TDetector detector) | ||
{ | ||
// create time tag and actually time tag. | ||
var actual = detector.Detect(item); | ||
AssertEqual(expected, actual); | ||
} | ||
|
||
protected abstract void AssertEqual(TProperty expected, TProperty actual); | ||
} |
69 changes: 69 additions & 0 deletions
69
osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/BasePropertyGeneratorTest.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,69 @@ | ||
// 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.Edit.Generator; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator; | ||
|
||
public abstract class BasePropertyGeneratorTest<TGenerator, TItem, TProperty, TConfig> | ||
: BasePropertyGeneratorTest<TGenerator, TItem, TProperty> | ||
where TGenerator : PropertyGenerator<TItem, TProperty> | ||
where TConfig : IHasConfig<TConfig>, new() | ||
{ | ||
protected static TConfig GeneratorConfig(Action<TConfig>? action = null) | ||
{ | ||
var config = new TConfig(); | ||
action?.Invoke(config); | ||
return config; | ||
} | ||
|
||
protected static TConfig GeneratorDefaultConfig(Action<TConfig>? action = null) | ||
{ | ||
var config = new TConfig().CreateDefaultConfig(); | ||
action?.Invoke(config); | ||
return config; | ||
} | ||
|
||
protected static TGenerator GenerateGenerator(TConfig config) | ||
{ | ||
if (Activator.CreateInstance(typeof(TGenerator), config) is not TGenerator generator) | ||
throw new ArgumentNullException(nameof(generator)); | ||
|
||
return generator; | ||
} | ||
|
||
protected static void CheckCanGenerate(TItem item, bool canGenerate, TConfig config) | ||
{ | ||
var generator = GenerateGenerator(config); | ||
|
||
CheckCanGenerate(item, canGenerate, generator); | ||
} | ||
|
||
protected void CheckGenerateResult(TItem item, TProperty expected, TConfig config) | ||
{ | ||
var generator = GenerateGenerator(config); | ||
|
||
CheckGenerateResult(item, expected, generator); | ||
} | ||
} | ||
|
||
public abstract class BasePropertyGeneratorTest<TGenerator, TItem, TProperty> | ||
where TGenerator : PropertyGenerator<TItem, TProperty> | ||
{ | ||
protected static void CheckCanGenerate(TItem item, bool canGenerate, TGenerator generator) | ||
{ | ||
bool actual = generator.CanGenerate(item); | ||
Assert.AreEqual(canGenerate, actual); | ||
} | ||
|
||
protected void CheckGenerateResult(TItem item, TProperty expected, TGenerator generator) | ||
{ | ||
// create time tag and actually time tag. | ||
var actual = generator.Generate(item); | ||
AssertEqual(expected, actual); | ||
} | ||
|
||
protected abstract void AssertEqual(TProperty expected, TProperty actual); | ||
} |
43 changes: 3 additions & 40 deletions
43
osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Beatmaps/BaseBeatmapDetectorTest.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 |
---|---|---|
@@ -1,53 +1,16 @@ | ||
// 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.Beatmaps; | ||
using osu.Game.Rulesets.Karaoke.Edit.Generator; | ||
using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Beatmaps | ||
{ | ||
public abstract class BaseBeatmapDetectorTest<TDetector, TObject, TConfig> | ||
: BaseGeneratorTest<TConfig> | ||
where TDetector : class, IBeatmapPropertyDetector<TObject> where TConfig : IHasConfig<TConfig>, new() | ||
: BasePropertyDetectorTest<TDetector, KaraokeBeatmap, TObject, TConfig> | ||
where TDetector : BeatmapPropertyDetector<TObject, TConfig> | ||
where TConfig : IHasConfig<TConfig>, new() | ||
{ | ||
protected static TDetector GenerateDetector(TConfig config) | ||
{ | ||
if (Activator.CreateInstance(typeof(TDetector), config) is not TDetector detector) | ||
throw new ArgumentNullException(nameof(detector)); | ||
|
||
return detector; | ||
} | ||
|
||
protected static void CheckCanDetect(KaraokeBeatmap beatmap, bool canDetect, TConfig config) | ||
{ | ||
var detector = GenerateDetector(config); | ||
|
||
CheckCanDetect(beatmap, canDetect, detector); | ||
} | ||
|
||
protected static void CheckCanDetect(KaraokeBeatmap beatmap, bool canDetect, TDetector detector) | ||
{ | ||
bool actual = detector.CanDetect(beatmap); | ||
Assert.AreEqual(canDetect, actual); | ||
} | ||
|
||
protected void CheckDetectResult(KaraokeBeatmap beatmap, TObject expected, TConfig config) | ||
{ | ||
var detector = GenerateDetector(config); | ||
|
||
CheckDetectResult(beatmap, expected, detector); | ||
} | ||
|
||
protected void CheckDetectResult(KaraokeBeatmap beatmap, TObject expected, TDetector detector) | ||
{ | ||
// create time tag and actually time tag. | ||
var actual = detector.Detect(beatmap); | ||
AssertEqual(expected, actual); | ||
} | ||
|
||
protected abstract void AssertEqual(TObject expected, TObject actual); | ||
} | ||
} |
43 changes: 3 additions & 40 deletions
43
osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Beatmaps/BaseBeatmapGeneratorTest.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 |
---|---|---|
@@ -1,53 +1,16 @@ | ||
// 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.Beatmaps; | ||
using osu.Game.Rulesets.Karaoke.Edit.Generator; | ||
using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Beatmaps | ||
{ | ||
public abstract class BaseBeatmapGeneratorTest<TGenerator, TObject, TConfig> | ||
: BaseGeneratorTest<TConfig> | ||
where TGenerator : class, IBeatmapPropertyGenerator<TObject> where TConfig : IHasConfig<TConfig>, new() | ||
: BasePropertyGeneratorTest<TGenerator, KaraokeBeatmap, TObject, TConfig> | ||
where TGenerator : BeatmapPropertyGenerator<TObject, TConfig> | ||
where TConfig : IHasConfig<TConfig>, new() | ||
{ | ||
protected static TGenerator GenerateGenerator(TConfig config) | ||
{ | ||
if (Activator.CreateInstance(typeof(TGenerator), config) is not TGenerator generator) | ||
throw new ArgumentNullException(nameof(generator)); | ||
|
||
return generator; | ||
} | ||
|
||
protected static void CheckCanGenerate(KaraokeBeatmap beatmap, bool canGenerate, TConfig config) | ||
{ | ||
var generator = GenerateGenerator(config); | ||
|
||
CheckCanGenerate(beatmap, canGenerate, generator); | ||
} | ||
|
||
protected static void CheckCanGenerate(KaraokeBeatmap beatmap, bool canGenerate, TGenerator generator) | ||
{ | ||
bool actual = generator.CanGenerate(beatmap); | ||
Assert.AreEqual(canGenerate, actual); | ||
} | ||
|
||
protected void CheckGenerateResult(KaraokeBeatmap beatmap, TObject expected, TConfig config) | ||
{ | ||
var generator = GenerateGenerator(config); | ||
|
||
CheckGenerateResult(beatmap, expected, generator); | ||
} | ||
|
||
protected void CheckGenerateResult(KaraokeBeatmap beatmap, TObject expected, TGenerator generator) | ||
{ | ||
// create time tag and actually time tag. | ||
var actual = generator.Generate(beatmap); | ||
AssertEqual(expected, actual); | ||
} | ||
|
||
protected abstract void AssertEqual(TObject expected, TObject actual); | ||
} | ||
} |
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.