diff --git a/UnityProject/Assembly-CSharp-Editor.csproj b/UnityProject/Assembly-CSharp-Editor.csproj index 9cf6e07..eec7d5f 100644 --- a/UnityProject/Assembly-CSharp-Editor.csproj +++ b/UnityProject/Assembly-CSharp-Editor.csproj @@ -65,7 +65,8 @@ - + + diff --git a/UnityProject/Assets/Editor/PdSpectrumBindEditor.cs b/UnityProject/Assets/Editor/PdSpectrumBindEditor.cs index 0aac61a..84142bb 100644 --- a/UnityProject/Assets/Editor/PdSpectrumBindEditor.cs +++ b/UnityProject/Assets/Editor/PdSpectrumBindEditor.cs @@ -45,7 +45,6 @@ namespace cylvester GUILayout.Label("Spectrum Extractor", EditorStyles.boldLabel); paintSpace_ = GUILayoutUtility.GetRect(behaviour.TextureWidth, behaviour.TextureWidth, behaviour.TextureHeight, behaviour.TextureHeight); - UpdateSelection(); diff --git a/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGenerator.cs b/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGenerator.cs deleted file mode 100644 index e82cb96..0000000 --- a/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGenerator.cs +++ /dev/null @@ -1,113 +0,0 @@ -using NUnit.Framework; -using NSubstitute; -using UnityEngine; - -namespace cylvester -{ - [TestFixture] - public class UnitTest_SpectrumGenerator - { - private IPdArray pdArray_; - private Rect selectionRect_; - private Rect noSelectionRect_; - private float[] dummyData_; - private Color standardColor_; - private Color selectedColor_; - - [SetUp] - public void SetUp() - { - dummyData_ = new float[100]; - pdArray_ = Substitute.For(); - pdArray_.Data.Returns(dummyData_); - selectionRect_ = new Rect {x = 9, y = 9, width = 3, height = 3}; - noSelectionRect_ = new Rect {width = 0, height = 0}; - - standardColor_ = new Color(0f, 0f, 0f, 0.2f); - selectedColor_ = new Color(0f, 0f, 0f, 1f); - } -/* - [Test] - public void Construction() - { - var spectrumGenerator = new SpectrumGenerator(100, 101); - - Assert.AreEqual(100, spectrumGenerator.Spectrum.width); - Assert.AreEqual(101, spectrumGenerator.Spectrum.height); - } - - [Test] - public void Update_array_available_loud() - { - for (var i = 0; i < dummyData_.Length; ++i) - dummyData_[i] = 100f; // loud sound - - var spectrumGenerator = new SpectrumGenerator(100, 100); - var validPixel = spectrumGenerator.Update(pdArray_, selectionRect_); - - Assert.AreEqual(1, validPixel); - } - - [Test] - public void Update_array_available_soft() - { - for (var i = 0; i < dummyData_.Length; ++i) - dummyData_[i] = 0.001f; // soft sound - - var spectrumGenerator = new SpectrumGenerator(100, 100); - var validPixel = spectrumGenerator.Update(pdArray_, selectionRect_); - - Assert.AreEqual(0, validPixel); - } - - [Test] - public void Update_array_available_loud_no_selection() - { - for (var i = 0; i < dummyData_.Length; ++i) - dummyData_[i] = 100f; // loud sound - - var spectrumGenerator = new SpectrumGenerator(100, 100); - var validPixel = spectrumGenerator.Update(pdArray_, noSelectionRect_); - - Assert.AreEqual(0, validPixel); - } - - - [Test] - public void Update_array_unavailable() - { - var spectrumGenerator = new SpectrumGenerator(100, 100); - var validPixels = spectrumGenerator.Update(null, noSelectionRect_); - - Assert.AreEqual(0, validPixels); - var texture = spectrumGenerator.Spectrum; - var pixels = texture.GetPixels(); - - foreach (var pixel in pixels) - Assert.AreEqual(standardColor_, pixel); - } - - [Test] - public void Update_array_unavailable_with_selection() - { - var spectrumGenerator = new SpectrumGenerator(100, 100); - var validPixels = spectrumGenerator.Update(null, selectionRect_); - - Assert.AreEqual(0, validPixels); - var texture = spectrumGenerator.Spectrum; - - for (var x = 0; x < 100; x++) - { - for (var y = 0; y < 100; y++) - { - if (x == 10 && y == 90) // because vertically inverted - Assert.AreEqual(selectedColor_, texture.GetPixel(x, y)); - else - Assert.AreEqual(standardColor_, texture.GetPixel(x, y)); - } - } - } - */ - - } -} \ No newline at end of file diff --git a/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorEditMode.cs b/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorEditMode.cs new file mode 100644 index 0000000..dc09260 --- /dev/null +++ b/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorEditMode.cs @@ -0,0 +1,74 @@ +using NUnit.Framework; +using NSubstitute; +using UnityEngine; + +namespace cylvester +{ + [TestFixture] + public class UnitTest_SpectrumGeneratorEditMode + { + private IPdArray pdArray_; + private Rect selectionRect_; + private Rect noSelectionRect_; + private float[] dummyData_; + private Color standardColor_; + private Color selectedColor_; + + [SetUp] + public void SetUp() + { + dummyData_ = new float[100]; + pdArray_ = Substitute.For(); + pdArray_.Data.Returns(dummyData_); + selectionRect_ = new Rect {x = 9, y = 9, width = 3, height = 3}; + noSelectionRect_ = new Rect {width = 0, height = 0}; + + standardColor_ = new Color(0f, 0f, 0f, 0.2f); + selectedColor_ = new Color(0f, 0f, 0f, 1f); + } + + [Test] + public void Construction() + { + var spectrumGenerator = new SpectrumGeneratorEditMode(100, 101); + + Assert.AreEqual(100, spectrumGenerator.Spectrum.width); + Assert.AreEqual(101, spectrumGenerator.Spectrum.height); + } + + [Test] + public void Update_without_selection() + { + var spectrumGeneratorEditMode = new SpectrumGeneratorEditMode(100, 100); + var validPixels = spectrumGeneratorEditMode.Update(noSelectionRect_); + + Assert.AreEqual(0, validPixels); + var texture = spectrumGeneratorEditMode.Spectrum; + var pixels = texture.GetPixels(); + + foreach (var pixel in pixels) + Assert.AreEqual(standardColor_, pixel); + } + + [Test] + public void Update_with_selection() + { + var spectrumGeneratorEditMode = new SpectrumGeneratorEditMode(100, 100); + var validPixels = spectrumGeneratorEditMode.Update(selectionRect_); + + Assert.AreEqual(0, validPixels); + var texture = spectrumGeneratorEditMode.Spectrum; + + for (var x = 0; x < 100; x++) + { + for (var y = 0; y < 100; y++) + { + if (x == 10 && y == 90) // because vertically inverted + Assert.AreEqual(selectedColor_, texture.GetPixel(x, y)); + else + Assert.AreEqual(standardColor_, texture.GetPixel(x, y)); + } + } + } + } +} \ No newline at end of file diff --git a/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGenerator.cs.meta b/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorEditMode.cs.meta similarity index 100% rename from UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGenerator.cs.meta rename to UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorEditMode.cs.meta diff --git a/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorPlayMode.cs b/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorPlayMode.cs new file mode 100644 index 0000000..0da3dd8 --- /dev/null +++ b/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorPlayMode.cs @@ -0,0 +1,71 @@ +using NUnit.Framework; +using NSubstitute; +using UnityEngine; + +namespace cylvester +{ + [TestFixture] + public class UnitTest_SpectrumGeneratorPlayMode + { + private IPdArray pdArray_; + private Rect selectionRect_; + private Rect noSelectionRect_; + private float[] dummyData_; + + + [SetUp] + public void SetUp() + { + dummyData_ = new float[100]; + pdArray_ = Substitute.For(); + pdArray_.Data.Returns(dummyData_); + selectionRect_ = new Rect {x = 9, y = 9, width = 3, height = 3}; + noSelectionRect_ = new Rect {width = 0, height = 0}; + } + + [Test] + public void Construction() + { + var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 101, pdArray_); + + Assert.AreEqual(100, spectrumGenerator.Spectrum.width); + Assert.AreEqual(101, spectrumGenerator.Spectrum.height); + } + + [Test] + public void Update_array_available_loud() + { + for (var i = 0; i < dummyData_.Length; ++i) + dummyData_[i] = 100f; // loud sound + + var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 100, pdArray_); + var validPixel = spectrumGenerator.Update(selectionRect_); + + Assert.AreEqual(1, validPixel); + } + + [Test] + public void Update_array_available_soft() + { + for (var i = 0; i < dummyData_.Length; ++i) + dummyData_[i] = 0.001f; // soft sound + + var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 100, pdArray_); + var validPixel = spectrumGenerator.Update(selectionRect_); + + Assert.AreEqual(0, validPixel); + } + + [Test] + public void Update_array_available_loud_no_selection() + { + for (var i = 0; i < dummyData_.Length; ++i) + dummyData_[i] = 100f; // loud sound + + var spectrumGenerator = new SpectrumGeneratorPlayMode(100, 100, pdArray_); + var validPixel = spectrumGenerator.Update(noSelectionRect_); + + Assert.AreEqual(0, validPixel); + } + } +} \ No newline at end of file diff --git a/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorPlayMode.cs.meta b/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorPlayMode.cs.meta new file mode 100644 index 0000000..68f9ff3 --- /dev/null +++ b/UnityProject/Assets/Editor/UnitTest/UnitTest_SpectrumGeneratorPlayMode.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 130ee59590104ff991a08209e3bcd345 +timeCreated: 1570033095 \ No newline at end of file