-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: write unit test for audio group preloading
- Loading branch information
Showing
7 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
Assets/AudioSystem/Test/Editor/Audio/AudioClipsGroupTests.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,92 @@ | ||
using Long18.AudioSystem.Data; | ||
using Long18.AudioSystem.Data.Utils; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
using UnityEngine.AddressableAssets; | ||
|
||
namespace Long18.AudioSystem.Test.Editor.Audio | ||
{ | ||
public class AudioClipsGroupTests | ||
{ | ||
private const int NUMBER_OF_TRY = 10; | ||
private const int FEW_OF_CLIPS = 2; | ||
private const int MANY_OF_CLIPS = 5; | ||
private const int NUMBER_OF_PASS = 2; | ||
|
||
private AssetReferenceT<AudioClip>[] _clips; | ||
private AudioClipsGroup _group; | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
foreach (var clip in _clips) | ||
{ | ||
if (clip == null || !clip.RuntimeKeyIsValid()) continue; | ||
clip.ReleaseAsset(); | ||
} | ||
} | ||
|
||
[TestCase(ESequenceMode.Sequential)] | ||
[TestCase(ESequenceMode.Repeat)] | ||
[TestCase(ESequenceMode.Random)] | ||
public void AudioClipsGroup_GetNextClip_ExpectNotIndexOutOfRange(ESequenceMode mode) | ||
{ | ||
_clips = CreateEmptyAudioClips(FEW_OF_CLIPS); | ||
_group = new(_clips, mode); | ||
ChangeClipsContinuously(); | ||
} | ||
|
||
[Test] | ||
public void AudioClipsGroup_GetPreviousClip_ExpectNotIndexOutOfRange() | ||
{ | ||
_clips = CreateEmptyAudioClips(FEW_OF_CLIPS); | ||
_group = new(_clips, ESequenceMode.Sequential); | ||
|
||
for (int i = 0; i < NUMBER_OF_PASS; i++) ChangeClipsBackward(); | ||
} | ||
|
||
[Test] | ||
public void AudioClipsGroup_GetNextClipSequentially_ExpectCorrectSequence() | ||
{ | ||
_clips = CreateEmptyAudioClips(MANY_OF_CLIPS); | ||
_group = new(_clips, ESequenceMode.Sequential); | ||
|
||
for (int i = 0; i < NUMBER_OF_PASS; i++) TravelOnePassThroughClips(); | ||
} | ||
|
||
private void ChangeClipsContinuously() | ||
{ | ||
for (int i = 0; i < NUMBER_OF_TRY; i++) _group.SwitchToNextClip(); | ||
} | ||
|
||
private void ChangeClipsBackward() | ||
{ | ||
for (int i = _clips.Length - 1; i >= 0; i--) | ||
{ | ||
var expectedClip = _clips[i]; | ||
_group.SwitchToPreviousClip(); | ||
Assert.AreEqual(expectedClip, _group.CurrentClip); | ||
} | ||
} | ||
|
||
private void TravelOnePassThroughClips() | ||
{ | ||
foreach (var clip in _clips) | ||
{ | ||
Assert.That(_group.CurrentClip == clip); | ||
_group.SwitchToNextClip(); | ||
} | ||
} | ||
|
||
private AssetReferenceT<AudioClip>[] CreateEmptyAudioClips(int quantity) | ||
{ | ||
var newClips = new AssetReferenceT<AudioClip>[quantity]; | ||
for (int i = 0; i < quantity; i++) | ||
{ | ||
newClips[i] = new AssetReferenceT<AudioClip>("AudioClip" + i); | ||
} | ||
|
||
return newClips; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/AudioSystem/Test/Editor/Audio/AudioClipsGroupTests.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "Editor.Tests", | ||
"rootNamespace": "Long18", | ||
"references": [ | ||
"GUID:0acc523941302664db1f4e527237feb3", | ||
"GUID:27619889b8ba8c24980f49ee34dbb44a", | ||
"GUID:84651a3751eca9349aac36a66bba901b", | ||
"GUID:9e24947de15b9834991c9d8411ea37cf", | ||
"GUID:dc1011b7296221a419df66d38b91ab77" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": true, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
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,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Caudiosystem_005Cscripts_005Ceditor/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |