Skip to content

Commit

Permalink
Add Binding and BindingMode enums
Browse files Browse the repository at this point in the history
Also added and refactored unit tests.
  • Loading branch information
ChainsManipulator committed Dec 8, 2024
1 parent ed85b19 commit 3561ad5
Show file tree
Hide file tree
Showing 21 changed files with 568 additions and 187 deletions.
38 changes: 38 additions & 0 deletions Libiada.Core.Tests/Attributes/BindingAttriubuteTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Libiada.Core.Tests.Attributes;

using Libiada.Core.Attributes;
using Libiada.Core.Extensions;
using Libiada.Core.Core;

/// <summary>
/// The binding attribute tests.
/// </summary>
[TestFixture(TestOf = typeof(BindingAttribute))]
public class BindingAttributeTests
{
/// <summary>
/// Invalid binding value test.
/// </summary>
[Test]
public void InvalidBindingValueTest()
{
Assert.Throws<ArgumentException>(() => new BindingAttribute((Binding)3));
}

/// <summary>
/// Binding attribute value test.
/// </summary>
/// <param name="value">
/// The value.
/// </param>
[Test]
public void BindingAttributeValueTest([Values] Binding value)
{
BindingAttribute attribute = new(value);
Assert.Multiple(() =>
{
Assert.That(attribute.Value, Is.EqualTo(value));
Assert.That(attribute.Value.GetDisplayValue(), Is.EqualTo(value.GetDisplayValue()));
});
}
}
38 changes: 38 additions & 0 deletions Libiada.Core.Tests/Attributes/BindingModeAttributeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Libiada.Core.Tests.Attributes;

using Libiada.Core.Attributes;
using Libiada.Core.Extensions;
using Libiada.Core.Core;

/// <summary>
/// The binding mode attribute tests.
/// </summary>
[TestFixture(TestOf = typeof(BindingModeAttribute))]
public class BindingModeAttributeTests
{
/// <summary>
/// Invalid binding mode value test.
/// </summary>
[Test]
public void InvalidBindingModeValueTest()
{
Assert.Throws<ArgumentException>(() => new BindingModeAttribute((BindingMode)5));
}

/// <summary>
/// Binding mode attribute value test.
/// </summary>
/// <param name="value">
/// The value.
/// </param>
[Test]
public void BindingModeAttributeValueTest([Values] BindingMode value)
{
BindingModeAttribute attribute = new(value);
Assert.Multiple(() =>
{
Assert.That(attribute.Value, Is.EqualTo(value));
Assert.That(attribute.Value.GetDisplayValue(), Is.EqualTo(value.GetDisplayValue()));
});
}
}
38 changes: 38 additions & 0 deletions Libiada.Core.Tests/Attributes/LinkAttributeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Libiada.Core.Tests.Attributes;

using Libiada.Core.Attributes;
using Libiada.Core.Extensions;
using Libiada.Core.Core;

/// <summary>
/// The link attribute tests.
/// </summary>
[TestFixture(TestOf = typeof(LinkAttribute))]
public class LinkAttributeTests
{
/// <summary>
/// Invalid link value test.
/// </summary>
[Test]
public void InvalidLinkValueTest()
{
Assert.Throws<ArgumentException>(() => new LinkAttribute((Link)8));
}

/// <summary>
/// Link attribute value test.
/// </summary>
/// <param name="value">
/// The value.
/// </param>
[Test]
public void LinkAttributeValueTest([Values] Link value)
{
LinkAttribute attribute = new(value);
Assert.Multiple(() =>
{
Assert.That(attribute.Value, Is.EqualTo(value));
Assert.That(attribute.Value.GetDisplayValue(), Is.EqualTo(value.GetDisplayValue()));
});
}
}
79 changes: 79 additions & 0 deletions Libiada.Core.Tests/Core/BindingModeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
namespace Libiada.Core.Tests.Core;

using Libiada.Core.Core;
using Libiada.Core.Extensions;

/// <summary>
/// BindingMode enum tests.
/// </summary>
[TestFixture(TestOf = typeof(BindingMode))]
public class BindingModeTests
{
/// <summary>
/// Binding modes count.
/// </summary>
private const int BindingModesCount = 5;

/// <summary>
/// Array of all binding modes.
/// </summary>
private readonly BindingMode[] bindingModes = EnumExtensions.ToArray<BindingMode>();

/// <summary>
/// Tests count of binding modes.
/// </summary>
[Test]
public void BindingModeCountTest() => Assert.That(bindingModes, Has.Length.EqualTo(BindingModesCount));

/// <summary>
/// Tests values of binding modes.
/// </summary>
[Test]
public void BindingModeValuesTest()
{
for (int i = 0; i < BindingModesCount; i++)
{
Assert.That(bindingModes, Contains.Item((BindingMode)i));
}
}

/// <summary>
/// Tests names of binding modes.
/// </summary>
/// <param name="bindingMode">
/// The binding mode.
/// </param>
/// <param name="name">
/// The name.
/// </param>
[TestCase((BindingMode)0, "NotApplicable")]
[TestCase((BindingMode)1, "Normal")]
[TestCase((BindingMode)2, "Cyclic")]
[TestCase((BindingMode)3, "Lossy")]
[TestCase((BindingMode)4, "Redundant")]
public void BindingModeNamesTest(BindingMode bindingMode, string name) => Assert.That(bindingMode.GetName(), Is.EqualTo(name));

/// <summary>
/// Tests that all binding modes have display value.
/// </summary>
/// <param name="bindingMode">
/// The binding mode.
/// </param>
[Test]
public void BindingModeHasDisplayValueTest([Values] BindingMode bindingMode) => Assert.That(bindingMode.GetDisplayValue(), Is.Not.Empty);

/// <summary>
/// Tests that all binding modes have description.
/// </summary>
/// <param name="bindingMode">
/// The binding mode.
/// </param>
[Test]
public void BindingModeHasDescriptionTest([Values] BindingMode bindingMode) => Assert.That(bindingMode.GetDescription(), Is.Not.Empty);

/// <summary>
/// Tests that all binding modes values are unique.
/// </summary>
[Test]
public void BindingModeValuesUniqueTest() => Assert.That(bindingModes.Cast<byte>(), Is.Unique);
}
77 changes: 77 additions & 0 deletions Libiada.Core.Tests/Core/BindingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
namespace Libiada.Core.Tests.Core;

using Libiada.Core.Core;
using Libiada.Core.Extensions;

/// <summary>
/// Binding enum tests.
/// </summary>
[TestFixture(TestOf = typeof(Binding))]
public class BindingTests
{
/// <summary>
/// Bindings count.
/// </summary>
private const int BindingsCount = 3;

/// <summary>
/// Array of all bindings.
/// </summary>
private readonly Binding[] bindings = EnumExtensions.ToArray<Binding>();

/// <summary>
/// Tests count of bindings.
/// </summary>
[Test]
public void BindingCountTest() => Assert.That(bindings, Has.Length.EqualTo(BindingsCount));

/// <summary>
/// Tests values of bindings.
/// </summary>
[Test]
public void BindingValuesTest()
{
for (int i = 0; i < BindingsCount; i++)
{
Assert.That(bindings, Contains.Item((Binding)i));
}
}

/// <summary>
/// Tests names of bindings.
/// </summary>
/// <param name="binding">
/// The binding.
/// </param>
/// <param name="name">
/// The name.
/// </param>
[TestCase((Binding)0, "NotApplicable")]
[TestCase((Binding)1, "Beginning")]
[TestCase((Binding)2, "End")]
public void BindingNamesTest(Binding binding, string name) => Assert.That(binding.GetName(), Is.EqualTo(name));

/// <summary>
/// Tests that all bindings have display value.
/// </summary>
/// <param name="binding">
/// The binding.
/// </param>
[Test]
public void BindingHasDisplayValueTest([Values] Binding binding) => Assert.That(binding.GetDisplayValue(), Is.Not.Empty);

/// <summary>
/// Tests that all bindings have description.
/// </summary>
/// <param name="binding">
/// The binding.
/// </param>
[Test]
public void BindingHasDescriptionTest([Values] Binding binding) => Assert.That(binding.GetDescription(), Is.Not.Empty);

/// <summary>
/// Tests that all bindings values are unique.
/// </summary>
[Test]
public void BindingValuesUniqueTest() => Assert.That(bindings.Cast<byte>(), Is.Unique);
}
36 changes: 11 additions & 25 deletions Libiada.Core.Tests/Core/LinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ public class LinkTests
/// </summary>
private const int LinksCount = 8;

/// <summary>
/// Array of all links.
/// </summary>
private readonly Link[] links = EnumExtensions.ToArray<Link>();

/// <summary>
/// Tests count of links.
/// </summary>
[Test]
public void LinkCountTest()
{
int actualCount = EnumExtensions.ToArray<Link>().Length;
Assert.That(EnumExtensions.ToArray<Link>(), Has.Length.EqualTo(LinksCount));
}
public void LinkCountTest() => Assert.That(links, Has.Length.EqualTo(LinksCount));

/// <summary>
/// Tests values of links.
/// </summary>
[Test]
public void LinkValuesTest()
{
Link[] links = EnumExtensions.ToArray<Link>();
for (int i = 0; i < LinksCount; i++)
{
Assert.That(links, Does.Contain((Link)i));
Assert.That(links, Contains.Item((Link)i));
}
}

Expand All @@ -54,10 +54,7 @@ public void LinkValuesTest()
[TestCase((Link)5, "Cycle")]
[TestCase((Link)6, "CycleStart")]
[TestCase((Link)7, "CycleEnd")]
public void LinkNamesTest(Link link, string name)
{
Assert.That(link.GetName(), Is.EqualTo(name));
}
public void LinkNamesTest(Link link, string name) => Assert.That(link.GetName(), Is.EqualTo(name));

/// <summary>
/// Tests that all links have display value.
Expand All @@ -66,10 +63,7 @@ public void LinkNamesTest(Link link, string name)
/// The link.
/// </param>
[Test]
public void LinkHasDisplayValueTest([Values]Link link)
{
Assert.That(link.GetDisplayValue(), Is.Not.Empty);
}
public void LinkHasDisplayValueTest([Values] Link link) => Assert.That(link.GetDisplayValue(), Is.Not.Empty);

/// <summary>
/// Tests that all links have description.
Expand All @@ -78,19 +72,11 @@ public void LinkHasDisplayValueTest([Values]Link link)
/// The link.
/// </param>
[Test]
public void LinkHasDescriptionTest([Values]Link link)
{
Assert.That(link.GetDescription(), Is.Not.Empty);
}
public void LinkHasDescriptionTest([Values] Link link) => Assert.That(link.GetDescription(), Is.Not.Empty);

/// <summary>
/// Tests that all links values are unique.
/// </summary>
[Test]
public void LinkValuesUniqueTest()
{
Link[] links = EnumExtensions.ToArray<Link>();
IEnumerable<byte> linkValues = links.Cast<byte>();
Assert.That(linkValues, Is.Unique);
}
public void LinkValuesUniqueTest() => Assert.That(links.Cast<byte>(), Is.Unique);
}
Loading

0 comments on commit 3561ad5

Please sign in to comment.