Add Bindable nunit tests

This commit is contained in:
smoogipoo
2018-01-25 19:55:04 +09:00
parent d305fb935d
commit 672c7cedf0
8 changed files with 399 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using NUnit.Framework;
using osu.Framework.Configuration;
namespace osu.Framework.Tests.Bindables
{
[TestFixture]
public class BindableBoolTest
{
[TestCase(true)]
[TestCase(false)]
public void TestSet(bool value)
{
var bindable = new BindableBool { Value = value };
Assert.AreEqual(value, bindable.Value);
}
[TestCase("True", true)]
[TestCase("true", true)]
[TestCase("False", false)]
[TestCase("false", false)]
[TestCase("1", true)]
[TestCase("0", false)]
public void TestParsingString(string value, bool expected)
{
var bindable = new BindableBool();
bindable.Parse(value);
Assert.AreEqual(expected, bindable.Value);
}
[TestCase(true)]
[TestCase(false)]
public void TestParsingBoolean(bool value)
{
var bindable = new BindableBool();
bindable.Parse(value);
Assert.AreEqual(value, bindable.Value);
}
}
}

View File

@@ -0,0 +1,66 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using NUnit.Framework;
using osu.Framework.Configuration;
namespace osu.Framework.Tests.Bindables
{
[TestFixture]
public class BindableDoubleTest
{
[TestCase(0)]
[TestCase(-0)]
[TestCase(1)]
[TestCase(-105.123)]
[TestCase(105.123)]
[TestCase(double.MinValue)]
[TestCase(double.MaxValue)]
public void TestSet(double value)
{
var bindable = new BindableDouble { Value = value };
Assert.AreEqual(value, bindable.Value);
}
[TestCase("0", 0f)]
[TestCase("1", 1f)]
[TestCase("-0", 0f)]
[TestCase("-105.123", -105.123)]
[TestCase("105.123", 105.123)]
public void TestParsingString(string value, double expected)
{
var bindable = new BindableDouble();
bindable.Parse(value);
Assert.AreEqual(expected, bindable.Value);
}
[TestCase("0", -10, 10, 0)]
[TestCase("1", -10, 10, 1)]
[TestCase("-0", -10, 10, 0)]
[TestCase("-105.123", -10, 10, -10)]
[TestCase("105.123", -10, 10, 10)]
public void TestParsingStringWithRange(string value, double minValue, double maxValue, double expected)
{
var bindable = new BindableDouble { MinValue = minValue, MaxValue = maxValue };
bindable.Parse(value);
Assert.AreEqual(expected, bindable.Value);
}
[TestCase(0)]
[TestCase(-0)]
[TestCase(1)]
[TestCase(-105.123)]
[TestCase(105.123)]
[TestCase(double.MinValue)]
[TestCase(double.MaxValue)]
public void TestParsingDouble(double value)
{
var bindable = new BindableDouble();
bindable.Parse(value);
Assert.AreEqual(value, bindable.Value);
}
}
}

View File

@@ -0,0 +1,52 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using NUnit.Framework;
using osu.Framework.Configuration;
namespace osu.Framework.Tests.Bindables
{
[TestFixture]
public class BindableEnumTest
{
[TestCase(TestEnum.Value1)]
[TestCase(TestEnum.Value2)]
[TestCase(TestEnum.Value1 - 1)]
[TestCase(TestEnum.Value2 + 1)]
public void TestSet(TestEnum value)
{
var bindable = new Bindable<TestEnum> { Value = value };
Assert.AreEqual(value, bindable.Value);
}
[TestCase("Value1", TestEnum.Value1)]
[TestCase("Value2", TestEnum.Value2)]
[TestCase("-1", TestEnum.Value1 - 1)]
[TestCase("2", TestEnum.Value2 + 1)]
public void TestParsingString(string value, TestEnum expected)
{
var bindable = new Bindable<TestEnum>();
bindable.Parse(value);
Assert.AreEqual(expected, bindable.Value);
}
[TestCase(TestEnum.Value1)]
[TestCase(TestEnum.Value2)]
[TestCase(TestEnum.Value1 - 1)]
[TestCase(TestEnum.Value2 + 1)]
public void TestParsingEnum(TestEnum value)
{
var bindable = new Bindable<TestEnum>();
bindable.Parse(value);
Assert.AreEqual(value, bindable.Value);
}
public enum TestEnum
{
Value1 = 0,
Value2 = 1
}
}
}

View File

@@ -0,0 +1,66 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using NUnit.Framework;
using osu.Framework.Configuration;
namespace osu.Framework.Tests.Bindables
{
[TestFixture]
public class BindableFloatTest
{
[TestCase(0)]
[TestCase(-0)]
[TestCase(1)]
[TestCase(-105.123f)]
[TestCase(105.123f)]
[TestCase(float.MinValue)]
[TestCase(float.MaxValue)]
public void TestSet(float value)
{
var bindable = new BindableFloat { Value = value };
Assert.AreEqual(value, bindable.Value);
}
[TestCase("0", 0f)]
[TestCase("1", 1f)]
[TestCase("-0", 0f)]
[TestCase("-105.123", -105.123f)]
[TestCase("105.123", 105.123f)]
public void TestParsingString(string value, float expected)
{
var bindable = new BindableFloat();
bindable.Parse(value);
Assert.AreEqual(expected, bindable.Value);
}
[TestCase("0", -10, 10, 0)]
[TestCase("1", -10, 10, 1)]
[TestCase("-0", -10, 10, 0)]
[TestCase("-105.123", -10, 10, -10)]
[TestCase("105.123", -10, 10, 10)]
public void TestParsingStringWithRange(string value, float minValue, float maxValue, float expected)
{
var bindable = new BindableFloat { MinValue = minValue, MaxValue = maxValue };
bindable.Parse(value);
Assert.AreEqual(expected, bindable.Value);
}
[TestCase(0)]
[TestCase(-0)]
[TestCase(1)]
[TestCase(-105.123f)]
[TestCase(105.123f)]
[TestCase(float.MinValue)]
[TestCase(float.MaxValue)]
public void TestParsingFloat(float value)
{
var bindable = new BindableFloat();
bindable.Parse(value);
Assert.AreEqual(value, bindable.Value);
}
}
}

View File

@@ -0,0 +1,66 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using NUnit.Framework;
using osu.Framework.Configuration;
namespace osu.Framework.Tests.Bindables
{
[TestFixture]
public class BindableIntTest
{
[TestCase(0)]
[TestCase(-0)]
[TestCase(1)]
[TestCase(-105)]
[TestCase(105)]
[TestCase(int.MinValue)]
[TestCase(int.MaxValue)]
public void TestSet(int value)
{
var bindable = new BindableInt { Value = value };
Assert.AreEqual(value, bindable.Value);
}
[TestCase("0", 0)]
[TestCase("1", 1)]
[TestCase("-0", 0)]
[TestCase("-105", -105)]
[TestCase("105", 105)]
public void TestParsingString(string value, int expected)
{
var bindable = new BindableInt();
bindable.Parse(value);
Assert.AreEqual(expected, bindable.Value);
}
[TestCase("0", -10, 10, 0)]
[TestCase("1", -10, 10, 1)]
[TestCase("-0", -10, 10, 0)]
[TestCase("-105", -10, 10, -10)]
[TestCase("105", -10, 10, 10)]
public void TestParsingStringWithRange(string value, int minValue, int maxValue, int expected)
{
var bindable = new BindableInt { MinValue = minValue, MaxValue = maxValue };
bindable.Parse(value);
Assert.AreEqual(expected, bindable.Value);
}
[TestCase(0)]
[TestCase(-0)]
[TestCase(1)]
[TestCase(-105)]
[TestCase(105)]
[TestCase(int.MinValue)]
[TestCase(int.MaxValue)]
public void TestParsingInt(int value)
{
var bindable = new BindableInt();
bindable.Parse(value);
Assert.AreEqual(value, bindable.Value);
}
}
}

View File

@@ -0,0 +1,66 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using NUnit.Framework;
using osu.Framework.Configuration;
namespace osu.Framework.Tests.Bindables
{
[TestFixture]
public class BindableLongTest
{
[TestCase(0)]
[TestCase(-0)]
[TestCase(1)]
[TestCase(-105)]
[TestCase(105)]
[TestCase(long.MinValue)]
[TestCase(long.MaxValue - 1)] // This will overflow a double - this is probably an issue
public void TestSet(long value)
{
var bindable = new BindableLong { Value = value };
Assert.AreEqual(value, bindable.Value);
}
[TestCase("0", 0)]
[TestCase("1", 1)]
[TestCase("-0", 0)]
[TestCase("-105", -105)]
[TestCase("105", 105)]
public void TestParsingString(string value, long expected)
{
var bindable = new BindableLong();
bindable.Parse(value);
Assert.AreEqual(expected, bindable.Value);
}
[TestCase("0", -10, 10, 0)]
[TestCase("1", -10, 10, 1)]
[TestCase("-0", -10, 10, 0)]
[TestCase("-105", -10, 10, -10)]
[TestCase("105", -10, 10, 10)]
public void TestParsingStringWithRange(string value, long minValue, long maxValue, long expected)
{
var bindable = new BindableLong { MinValue = minValue, MaxValue = maxValue };
bindable.Parse(value);
Assert.AreEqual(expected, bindable.Value);
}
[TestCase(0)]
[TestCase(-0)]
[TestCase(1)]
[TestCase(-105)]
[TestCase(105)]
[TestCase(long.MinValue)]
[TestCase(long.MaxValue)]
public void TestParsingLong(long value)
{
var bindable = new BindableLong();
bindable.Parse(value);
Assert.AreEqual(value, bindable.Value);
}
}
}

View File

@@ -0,0 +1,32 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using NUnit.Framework;
using osu.Framework.Configuration;
namespace osu.Framework.Tests.Bindables
{
[TestFixture]
public class BindableStringTest
{
[TestCase("")]
[TestCase(null)]
[TestCase("this is a string")]
public void TestSet(string value)
{
var bindable = new Bindable<string> { Value = value };
Assert.AreEqual(value, bindable.Value);
}
[TestCase("")]
[TestCase("null")]
[TestCase("this is a string")]
public void TestParsingString(string value)
{
var bindable = new Bindable<string>();
bindable.Parse(value);
Assert.AreEqual(value, bindable.Value);
}
}
}

View File

@@ -54,6 +54,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AutomatedVisualTestGame.cs" />
<Compile Include="Bindables\BindableBoolTest.cs" />
<Compile Include="Bindables\BindableDoubleTest.cs" />
<Compile Include="Bindables\BindableEnumTest.cs" />
<Compile Include="Bindables\BindableFloatTest.cs" />
<Compile Include="Bindables\BindableIntTest.cs" />
<Compile Include="Bindables\BindableLongTest.cs" />
<Compile Include="Bindables\BindableStringTest.cs" />
<Compile Include="IO\TestSortedListSerialization.cs" />
<Compile Include="IO\TestWebRequest.cs" />
<Compile Include="Lists\TestArrayExtensions.cs" />