2020-07-15 13:32:59 +00:00
|
|
|
namespace X10D.Tests.Core
|
2020-04-18 13:41:53 +00:00
|
|
|
{
|
|
|
|
using System;
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
/// <summary>
|
2020-07-15 13:32:59 +00:00
|
|
|
/// Tests for <see cref="DoubleExtensions" />.
|
2020-04-18 13:41:53 +00:00
|
|
|
/// </summary>
|
|
|
|
[TestClass]
|
|
|
|
public class DoubleTests
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-07-15 13:32:59 +00:00
|
|
|
/// Tests for <see cref="DoubleExtensions.Clamp" />.
|
2020-04-18 13:41:53 +00:00
|
|
|
/// </summary>
|
|
|
|
[TestMethod]
|
|
|
|
public void Clamp()
|
|
|
|
{
|
|
|
|
Assert.AreEqual(2.0, 3.0.Clamp(1.0, 2.0));
|
|
|
|
Assert.AreEqual(1.0, (-3.0).Clamp(1.0, 2.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-07-15 13:32:59 +00:00
|
|
|
/// Tests for <see cref="DoubleExtensions.DegreesToRadians" />.
|
2020-04-18 13:41:53 +00:00
|
|
|
/// </summary>
|
|
|
|
[TestMethod]
|
|
|
|
public void DegreesToRadians()
|
|
|
|
{
|
|
|
|
Assert.AreEqual(Math.PI, 180.0.DegreesToRadians());
|
|
|
|
Assert.AreEqual(Math.PI * 1.5, 270.0.DegreesToRadians());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-07-15 13:32:59 +00:00
|
|
|
/// Tests for <see cref="DoubleExtensions.GetBytes" />.
|
2020-04-18 13:41:53 +00:00
|
|
|
/// </summary>
|
|
|
|
[TestMethod]
|
|
|
|
public void GetBytes()
|
|
|
|
{
|
|
|
|
CollectionAssert.AreEqual(
|
|
|
|
new byte[] { 0x18, 0x2D, 0x44, 0x54, 0xFB, 0x21, 0x09, 0x40 },
|
|
|
|
Math.PI.GetBytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-07-15 13:32:59 +00:00
|
|
|
/// Tests for <see cref="DoubleExtensions.IsEven" />.
|
2020-04-18 13:41:53 +00:00
|
|
|
/// </summary>
|
|
|
|
[TestMethod]
|
|
|
|
public void IsEven()
|
|
|
|
{
|
|
|
|
Assert.IsTrue(2.0.IsEven());
|
|
|
|
Assert.IsFalse(1.0.IsEven());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-07-15 13:32:59 +00:00
|
|
|
/// Tests for <see cref="DoubleExtensions.IsOdd" />.
|
2020-04-18 13:41:53 +00:00
|
|
|
/// </summary>
|
|
|
|
[TestMethod]
|
|
|
|
public void IsOdd()
|
|
|
|
{
|
|
|
|
Assert.IsFalse(2.0.IsOdd());
|
|
|
|
Assert.IsTrue(1.0.IsOdd());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-07-15 13:32:59 +00:00
|
|
|
/// Tests for <see cref="DoubleExtensions.RadiansToDegrees" />.
|
2020-04-18 13:41:53 +00:00
|
|
|
/// </summary>
|
|
|
|
[TestMethod]
|
|
|
|
public void RadiansToDegrees()
|
|
|
|
{
|
|
|
|
Assert.AreEqual(180.0, Math.PI.RadiansToDegrees());
|
|
|
|
Assert.AreEqual(360.0, (2.0 * Math.PI).RadiansToDegrees());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2020-07-15 13:32:59 +00:00
|
|
|
/// Tests for <see cref="DoubleExtensions.Round" />.
|
2020-04-18 13:41:53 +00:00
|
|
|
/// </summary>
|
|
|
|
[TestMethod]
|
|
|
|
public void Round()
|
|
|
|
{
|
|
|
|
Assert.AreEqual(5.0, 3.5.Round(5));
|
|
|
|
Assert.AreEqual(5.0, 7.0.Round(5));
|
|
|
|
Assert.AreEqual(10.0, 7.5.Round(5));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|