-
Notifications
You must be signed in to change notification settings - Fork 7
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 #79 from nowsprinting/feature/screenshot_unique_ag…
…entname Change UGUIMonkeyAgent default screenshot filename strategy to TwoTieredCounterStrategy
- Loading branch information
Showing
14 changed files
with
167 additions
and
15 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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,58 @@ | ||
// Copyright (c) 2023-2024 DeNA Co., Ltd. | ||
// This software is released under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.CompilerServices; | ||
using DeNA.Anjin.Attributes; | ||
using TestHelper.Monkey.ScreenshotFilenameStrategies; | ||
|
||
namespace DeNA.Anjin.Strategies | ||
{ | ||
/// <summary> | ||
/// Screenshot filename strategy that adds a unique counter to the prefix. | ||
/// </summary> | ||
public class TwoTieredCounterStrategy : AbstractPrefixAndUniqueIDStrategy | ||
{ | ||
private static readonly Dictionary<string, int> s_prefixCounters = new Dictionary<string, int>(); | ||
private readonly int _uniqueNumberOfPrefix; | ||
private int _count; | ||
|
||
[InitializeOnLaunchAutopilot] | ||
internal static void ResetPrefixCounters() | ||
{ | ||
s_prefixCounters.Clear(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
[SuppressMessage("ReSharper", "CanSimplifyDictionaryLookupWithTryAdd")] | ||
public TwoTieredCounterStrategy(string filenamePrefix = null, [CallerMemberName] string callerMemberName = null) | ||
: base(filenamePrefix, callerMemberName) | ||
{ | ||
var key = base.GetFilenamePrefix(); | ||
if (s_prefixCounters.ContainsKey(key)) | ||
{ | ||
s_prefixCounters[key]++; | ||
} | ||
else | ||
{ | ||
s_prefixCounters[key] = 1; | ||
} | ||
|
||
_uniqueNumberOfPrefix = s_prefixCounters[key]; | ||
_count = 0; | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override string GetFilenamePrefix() | ||
{ | ||
return $"{base.GetFilenamePrefix()}{_uniqueNumberOfPrefix:D2}"; | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override string GetUniqueID() | ||
{ | ||
return $"{++_count:D4}"; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,58 @@ | ||
// Copyright (c) 2023-2024 DeNA Co., Ltd. | ||
// This software is released under the MIT License. | ||
|
||
using NUnit.Framework; | ||
|
||
namespace DeNA.Anjin.Strategies | ||
{ | ||
public class TwoTieredCounterStrategyTest | ||
{ | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
TwoTieredCounterStrategy.ResetPrefixCounters(); | ||
} | ||
|
||
[Test] | ||
public void GetFilename_WithPrefix_ReturnsUniqueFilename() | ||
{ | ||
var sut = new TwoTieredCounterStrategy("MyPrefix"); | ||
|
||
Assert.That(sut.GetFilename(), Is.EqualTo("MyPrefix01_0001.png")); | ||
Assert.That(sut.GetFilename(), Is.EqualTo("MyPrefix01_0002.png")); | ||
} | ||
|
||
[Test] | ||
public void GetFilename_WithoutPrefix_ReturnsFilenameUsingTestName() | ||
{ | ||
var sut = new TwoTieredCounterStrategy(); | ||
|
||
Assert.That(sut.GetFilename(), Is.EqualTo($"{TestContext.CurrentContext.Test.Name}01_0001.png")); | ||
Assert.That(sut.GetFilename(), Is.EqualTo($"{TestContext.CurrentContext.Test.Name}01_0002.png")); | ||
} | ||
|
||
[Test] | ||
public void GetFilename_WithSamePrefix_ReturnsFilenameUsingUniqueNumberByPrefix() | ||
{ | ||
var sut = new TwoTieredCounterStrategy("MyPrefix"); | ||
var sut2 = new TwoTieredCounterStrategy("MyPrefix"); | ||
|
||
Assert.That(sut.GetFilename(), Is.EqualTo("MyPrefix01_0001.png")); | ||
Assert.That(sut.GetFilename(), Is.EqualTo("MyPrefix01_0002.png")); | ||
Assert.That(sut2.GetFilename(), Is.EqualTo("MyPrefix02_0001.png")); | ||
Assert.That(sut2.GetFilename(), Is.EqualTo("MyPrefix02_0002.png")); | ||
} | ||
|
||
[Test] | ||
public void GetFilename_WithAnotherPrefix_ReturnsUniqueFilenameByPrefix() | ||
{ | ||
var sut = new TwoTieredCounterStrategy("MyPrefix"); | ||
var sut2 = new TwoTieredCounterStrategy("AnotherPrefix"); | ||
|
||
Assert.That(sut.GetFilename(), Is.EqualTo("MyPrefix01_0001.png")); | ||
Assert.That(sut.GetFilename(), Is.EqualTo("MyPrefix01_0002.png")); | ||
Assert.That(sut2.GetFilename(), Is.EqualTo("AnotherPrefix01_0001.png")); | ||
Assert.That(sut2.GetFilename(), Is.EqualTo("AnotherPrefix01_0002.png")); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Tests/Runtime/Strategies/TwoTieredCounterStrategyTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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