Skip to content

Commit

Permalink
feat: write unit test for audio group preloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Long18 committed Feb 21, 2024
1 parent e5ecc27 commit 86c27d5
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Assets/AudioSystem/Test/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/AudioSystem/Test/Editor/Audio.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions Assets/AudioSystem/Test/Editor/Audio/AudioClipsGroupTests.cs
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;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Assets/AudioSystem/Test/Editor/Editor.Tests.asmdef
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
}
7 changes: 7 additions & 0 deletions Assets/AudioSystem/Test/Editor/Editor.Tests.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Long18.AudioSystem.Editor.csproj.DotSettings
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>

0 comments on commit 86c27d5

Please sign in to comment.