some basic tests

This commit is contained in:
LubieKakao1212 2023-01-02 11:55:02 +01:00
parent af47348919
commit d731193948
14 changed files with 249 additions and 0 deletions

8
Achievments/Tests.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bab659ddb2d136440a51c5c9b76fefcb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,90 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using NEG.Utils.Achivments;
public class ConfigTests
{
public const string AchivmentDefOnlyLabel = "TestAchivments";
public const string AchivmentSetLabel = "TestAchivments";
public const string AchivmentProgressLabel = "TestAchivments";
public const string NoProgressAchivment = "NO_PROGRESS";
public const string WithProgressAchivment = "WITH_PROGRESS";
[Test]
public void AchivmentDefOnly()
{
AchivmentManager manager = AchivmentManager.Builder.FromLabeledConfig(AchivmentDefOnlyLabel).Build();
//Shoud not throw
manager.SetAchivment(NoProgressAchivment);
//Shoud not throw
manager.SetAchivment(WithProgressAchivment);
}
[Test]
public void AchivmentSet()
{
var callbackTester = new TestCallbackRereiver();
AchivmentManager manager = AchivmentManager.Builder.FromLabeledConfig(AchivmentDefOnlyLabel)
.WithCallbackReciever(callbackTester)
.Build();
//Shoud not throw
manager.SetAchivment(NoProgressAchivment);
//Shoud not throw
manager.SetAchivment(WithProgressAchivment);
}
[Test]
public void AchivmentProgress()
{
AchivmentManager manager = AchivmentManager.Builder.FromLabeledConfig(AchivmentProgressLabel).Build();
}
private class TestCallbackRereiver : IAchivmentCallbackReciever
{
public int LastProgressUpdated { get; private set; } = -1;
public string LastIdUpdated { get; private set; } = null;
public string LastIdSet { get; private set; } = null;
public void SetAchivment(AchivmentData achivment)
{
LastIdSet = achivment.Achivment.Id;
}
public void SetAchivmentProgress(AchivmentData achivment, int progress)
{
LastIdUpdated = achivment.Achivment.Id;
LastProgressUpdated = progress;
}
public void Reset()
{
LastIdSet = null;
LastIdUpdated = null;
LastProgressUpdated = -1;
}
public void TestSetCallbackst(AchivmentManager manager, string id)
{
manager.SetAchivment(id);
Assert.AreEqual(id, LastIdSet);
Assert.AreEqual(null, LastIdUpdated);
Assert.AreEqual(-1, LastProgressUpdated);
}
public void TestProgressCallback(AchivmentManager manager, string id, int progress, int expectedProgress, bool shouldSet)
{
manager.AddProgress(id, progress);
//Assert.AreEqual(, LastIdSet);
Assert.AreEqual(null, LastIdUpdated);
Assert.AreEqual(-1, LastProgressUpdated);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c47a38eaf8bffa849b130320427701cc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,27 @@
{
"name": "NEG.Utils.Achivments.Tests",
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"NEG.Utils.Achivments",
"Unity.Addressables",
"Unity.ResourceManager",
""
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 18b8be0ae04b6ad45ba52b2ddeb8198d
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3f7445ed9dd5a4548b89d56c196cbec7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ef37a873be859d042bda22dee624e429, type: 3}
m_Name: AchivmentCollection
m_EditorClassIdentifier:
<Achivments>k__BackingField:
- {fileID: 11400000, guid: 553d34779f9a31d4891686d6d34e8033, type: 2}
- {fileID: 11400000, guid: adbb4fd3d7472eb49933ac9958d499ff, type: 2}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4d95138fe57571c4299aa325a378e4ea
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 88120b6e616164f489387a6a32a25dee, type: 3}
m_Name: BaseConfig
m_EditorClassIdentifier:
<AchivmentCollectionAssetLabel>k__BackingField: TestAchivments

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 15513fd07fae44548bac5d923171a2a3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f9bd42dd58472044b8ecc0d69caa7da8, type: 3}
m_Name: NoProgress
m_EditorClassIdentifier:
<Id>k__BackingField: NO_PROGRESS
<ProgressRequired>k__BackingField: 1
additionalDataInitializer:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 553d34779f9a31d4891686d6d34e8033
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f9bd42dd58472044b8ecc0d69caa7da8, type: 3}
m_Name: WithProgress
m_EditorClassIdentifier:
<Id>k__BackingField: WITH_PROGRESS
<ProgressRequired>k__BackingField: 100
additionalDataInitializer:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: adbb4fd3d7472eb49933ac9958d499ff
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant: