fix unit tests
This commit is contained in:
parent
837d1bdf85
commit
8269c559d1
7 changed files with 150 additions and 115 deletions
|
@ -65,7 +65,8 @@
|
|||
<Compile Include="Assets\Editor\SpectrumGeneratorEditMode.cs" />
|
||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_ChangeObserver.cs" />
|
||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_RectangularSelection.cs" />
|
||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_SpectrumGenerator.cs" />
|
||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_SpectrumGeneratorEditMode.cs" />
|
||||
<Compile Include="Assets\Editor\UnitTest\UnitTest_SpectrumGeneratorPlayMode.cs" />
|
||||
<Compile Include="Assets\Scripts\VideoInput\Editor\UnitTest\ComponentFactoryTestCase.cs" />
|
||||
<Compile Include="Assets\Scripts\VideoInput\Editor\UnitTest\KinectSensorTestCase.cs" />
|
||||
<Compile Include="Assets\ThridParty\Editor\KinectCopyPluginDataHelper.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();
|
||||
|
||||
|
|
|
@ -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<IPdArray>();
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
|
@ -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<IPdArray>();
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<IPdArray>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 130ee59590104ff991a08209e3bcd345
|
||||
timeCreated: 1570033095
|
Loading…
Reference in a new issue