Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
# Added
- Added unit tests.

# Changes
- UniRx Integration runtime code moved to "Runtime" folder.
- ReactiveModifiableProperty<T>/ReactiveModifierList<T>.ObserveChanged now observe ReactiveModifierList<T>.ObserveMove.
  • Loading branch information
mackysoft committed Nov 27, 2020
1 parent db1e961 commit d18a855
Show file tree
Hide file tree
Showing 35 changed files with 347 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public static class ReactiveModifierListExtensions {
}
return Observable.Merge(
source.ObserveCountChanged().AsUnitObservable(),
source.ObserveReplace().AsUnitObservable()
source.ObserveReplace().AsUnitObservable(),
source.ObserveMove().AsUnitObservable()
).Select(_ => source);
}

Expand Down

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "MackySoft.Modiferty.UniRx.Editor.Tests",
"references": [
"GUID:e695879245fa2de4a81d0b0f517b15c3",
"GUID:fede8c6c4e4bddd44b1db8410752c53f",
"GUID:27619889b8ba8c24980f49ee34dbb44a",
"GUID:0acc523941302664db1f4e527237feb3",
"GUID:560b04d1a97f54a4e82edc0cbbb69285"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"MODIFERTY_UNIRX",
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections;
using UnityEngine;
using UnityEngine.TestTools;
using UniRx;
using NUnit.Framework;

namespace MackySoft.Modiferty.Tests {

public class ReactiveModifiableIntTests {

[UnityTest]
public IEnumerator ObserveChanged_BaseValue () {
ReactiveModifiableInt property = new ReactiveModifiableInt(0);
var subscription = property.ObserveChanged().First().ToYieldInstruction();

property.BaseValue = 1;

yield return subscription;

Assert.AreEqual(property.BaseValue,1);
}

}
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System.Collections;
using UnityEngine;
using UnityEngine.TestTools;
using UniRx;
using NUnit.Framework;

namespace MackySoft.Modiferty.Tests {
public class ReactiveModifierListTests {

[UnityTest]
public IEnumerator ObserveChanged_Add () {
var modifiers = new ReactiveModifierList<int>();

var subscription = modifiers.ObserveChanged().First().ToYieldInstruction();

modifiers.Add(new AdditiveModifierInt(1));

yield return subscription;

Assert.AreEqual(modifiers.Count,1);
}

[UnityTest]
public IEnumerator ObserveChanged_Remove () {
var modifiers = new ReactiveModifierList<int>();
var modifier = new AdditiveModifierInt(1);
modifiers.Add(modifier);

var subscription = modifiers.ObserveChanged().First().ToYieldInstruction();

modifiers.Remove(modifier);

yield return subscription;

Assert.AreEqual(modifiers.Count,0);
}

[UnityTest]
public IEnumerator ObserveChanged_Insert () {
var modifiers = new ReactiveModifierList<int>();
modifiers.Add(new AdditiveModifierInt(1));

var subscription = modifiers.ObserveChanged().First().ToYieldInstruction();

modifiers.Insert(0,new SubtractiveModifierInt(1));

yield return subscription;

Assert.AreEqual(modifiers.Count,2);
}

[UnityTest]
public IEnumerator ObserveChanged_Move () {
var modifiers = new ReactiveModifierList<int>();
modifiers.Add(new AdditiveModifierInt(1));

var targetModifier = new SubtractiveModifierInt(1);
modifiers.Add(targetModifier);

var subscription = modifiers.ObserveChanged().First().ToYieldInstruction();

modifiers.Move(1,0);

yield return subscription;

Assert.AreEqual(modifiers.IndexOf(targetModifier),0);
}

[UnityTest]
public IEnumerator ObserveChanged_Replace () {
var modifiers = new ReactiveModifierList<int>();
modifiers.Add(new AdditiveModifierInt(1));

var subscription = modifiers.ObserveChanged().First().ToYieldInstruction();

var targetModifier = new SubtractiveModifierInt(1);
modifiers[0] = targetModifier;

yield return subscription;

Assert.AreSame(modifiers[0],targetModifier);
}

[UnityTest]
public IEnumerator ObserveChanged_Clear () {
var modifiers = new ReactiveModifierList<int>();
modifiers.Add(new AdditiveModifierInt(1));

var subscription = modifiers.ObserveChanged().First().ToYieldInstruction();

modifiers.Clear();

yield return subscription;

Assert.AreEqual(modifiers.Count,0);
}

}
}

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

8 changes: 8 additions & 0 deletions Assets/MackySoft/MackySoft.Modiferty/Tests.meta

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

8 changes: 8 additions & 0 deletions Assets/MackySoft/MackySoft.Modiferty/Tests/Editor.meta

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "MackySoft.Modiferty.Editor.Tests",
"references": [
"GUID:e695879245fa2de4a81d0b0f517b15c3",
"GUID:40928bc94bf6c9d4ab69789b56aaff51",
"GUID:27619889b8ba8c24980f49ee34dbb44a",
"GUID:0acc523941302664db1f4e527237feb3"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using UnityEngine;
using NUnit.Framework;

namespace MackySoft.Modiferty.Tests {

public class ModifiableIntTests {

[Test]
public void Solo ([Random(-99999,99999,10)] int baseValue) {
var property = new ModifiableInt(baseValue);
Assert.AreEqual(baseValue,property.Evaluate());
}

[Test]
public void Additive (
[Random(-99999,99999,10)] int baseValue,
[Random(-99999,99999,10)] int add
) {
var property = new ModifiableInt(baseValue);
property.AddModifier(new AdditiveModifierInt(add));
Assert.AreEqual(baseValue + add,property.Evaluate());
}

[Test]
public void Subtractive (
[Random(-99999,99999,10)] int baseValue,
[Random(-99999,99999,10)] int subtract
) {
var property = new ModifiableInt(baseValue);
property.AddModifier(new SubtractiveModifierInt(subtract));
Assert.AreEqual(baseValue - subtract,property.Evaluate());
}

[Test]
public void Multiply (
[Random(-99999,99999,10)] int baseValue,
[Random(-10f,10f,10)] float multiplier,
[Values] RoundingMethod method
) {
var property = new ModifiableInt(baseValue);
property.AddModifier(new MultiplyModifierInt(multiplier,method));
Assert.AreEqual(RoundUtility.RoundToInt(baseValue * multiplier,method),property.Evaluate());
}

[Test]
public void Division (
[Random(-99999,99999,10)] int baseValue,
[Random(-10f,10f,10)] float division,
[Values] RoundingMethod method
) {
var property = new ModifiableInt(baseValue);
property.AddModifier(new DivisionModifierInt(division,method));
Assert.AreEqual(RoundUtility.RoundToInt(baseValue / division,method),property.Evaluate());
}

[Test]
public void AddModifierAsDisposable () {
var property = new ModifiableInt(0);

IDisposable disposable = property.AddModifierAsDisposable(new AdditiveModifierInt(1));
int beforeDisposedValue = property.Evaluate();

disposable.Dispose();

int afterDisposedValue = property.Evaluate();
Assert.AreNotEqual(beforeDisposedValue,afterDisposedValue);
}

}
}

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

5 changes: 2 additions & 3 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"dependencies": {
"com.unity.ide.rider": "1.2.1",
"com.unity.ide.visualstudio": "2.0.3",
"com.unity.ide.vscode": "1.2.3",
"com.unity.test-framework": "1.1.18",
"com.unity.ide.visualstudio": "2.0.5",
"com.unity.test-framework": "1.1.19",
"com.unity.ugui": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.physics": "1.0.0",
Expand Down

0 comments on commit d18a855

Please sign in to comment.