Skip to content

Commit

Permalink
Refactor some ToString Methodes
Browse files Browse the repository at this point in the history
Bump v0.0.4
  • Loading branch information
patrick-dmxc committed Jun 20, 2024
1 parent 984d34d commit c8609e7
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 4 deletions.
8 changes: 8 additions & 0 deletions WellKnownDataTypes-Tests/Light/ArtNet/Address_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public void TestAddress()
Assert.That(new Address(16).Equals(null), Is.False);
Assert.That(new Address(16), Is.Not.EqualTo(null));
Assert.That(new Address(16).ToString(), Is.Not.Empty);
Assert.That(new Address(1).ToString, Is.EqualTo("1"));
Assert.That(new Address(2).ToString, Is.EqualTo("2"));
Assert.That(new Address(1).ToStringDetailed(), Is.EqualTo("Address: 1(0x01) | Subnet: 0(0x0), Universe: 1(0x1)"));
Assert.That(new Address(2).ToStringDetailed(), Is.EqualTo("Address: 2(0x02) | Subnet: 0(0x0), Universe: 2(0x2)"));
Assert.That(new Address(15).ToStringDetailed(), Is.EqualTo("Address: 15(0x0f) | Subnet: 0(0x0), Universe: 15(0xf)"));
Assert.That(new Address(16).ToStringDetailed(), Is.EqualTo("Address: 16(0x10) | Subnet: 1(0x1), Universe: 0(0x0)"));
Assert.That(new Address(255).ToStringDetailed(), Is.EqualTo("Address: 255(0xff) | Subnet: 15(0xf), Universe: 15(0xf)"));
Assert.That(new Address(0xdd).ToStringDetailed(), Is.EqualTo("Address: 221(0xdd) | Subnet: 13(0xd), Universe: 13(0xd)"));
});

HashSet<Address> addresses = new HashSet<Address>();
Expand Down
6 changes: 6 additions & 0 deletions WellKnownDataTypes-Tests/Light/ArtNet/Net_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public void TestNet()
Assert.That(new Net(1).Equals((object)(Net)1), Is.True);
Assert.That(new Net(1).Equals((Net)1), Is.True);
Assert.That(new Net(1).Equals((Net)2), Is.False);
Assert.That(new Net(1).ToString, Is.EqualTo("1"));
Assert.That(new Net(2).ToString, Is.EqualTo("2"));
Assert.That(new Net(1).ToStringDetailed(), Is.EqualTo("Net: 1(0x01)"));
Assert.That(new Net(2).ToStringDetailed(), Is.EqualTo("Net: 2(0x02)"));
Assert.That(new Net(15).ToStringDetailed(), Is.EqualTo("Net: 15(0x0f)"));
Assert.That(new Net(16).ToStringDetailed(), Is.EqualTo("Net: 16(0x10)"));
});
}

Expand Down
9 changes: 9 additions & 0 deletions WellKnownDataTypes-Tests/Light/ArtNet/PortAddress_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public void TestPortAddress()
Assert.That(new PortAddress(1).Equals((object)(PortAddress)1), Is.True);
Assert.That(new PortAddress(1).Equals((PortAddress)1), Is.True);
Assert.That(new PortAddress(1).Equals((PortAddress)2), Is.False);
Assert.That(new PortAddress(1).ToString, Is.EqualTo("1"));
Assert.That(new PortAddress(2).ToString, Is.EqualTo("2"));
Assert.That(new PortAddress(1).ToStringDetailed(), Is.EqualTo("PortAddress: 1(0x0001) | Net: 0(0x00), Subnet: 0(0x0), Universe: 1(0x1)"));
Assert.That(new PortAddress(2).ToStringDetailed(), Is.EqualTo("PortAddress: 2(0x0002) | Net: 0(0x00), Subnet: 0(0x0), Universe: 2(0x2)"));
Assert.That(new PortAddress(15).ToStringDetailed(), Is.EqualTo("PortAddress: 15(0x000f) | Net: 0(0x00), Subnet: 0(0x0), Universe: 15(0xf)"));
Assert.That(new PortAddress(16).ToStringDetailed(), Is.EqualTo("PortAddress: 16(0x0010) | Net: 0(0x00), Subnet: 1(0x1), Universe: 0(0x0)"));
Assert.That(new PortAddress(255).ToStringDetailed(), Is.EqualTo("PortAddress: 255(0x00ff) | Net: 0(0x00), Subnet: 15(0xf), Universe: 15(0xf)"));
Assert.That(new PortAddress(0xdd).ToStringDetailed(), Is.EqualTo("PortAddress: 221(0x00dd) | Net: 0(0x00), Subnet: 13(0xd), Universe: 13(0xd)"));
Assert.That(new PortAddress(0x7ddd).ToStringDetailed(), Is.EqualTo("PortAddress: 32221(0x7ddd) | Net: 125(0x7d), Subnet: 13(0xd), Universe: 13(0xd)"));
});
}

Expand Down
6 changes: 6 additions & 0 deletions WellKnownDataTypes-Tests/Light/ArtNet/Subnet_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public void TestSubnet()
Assert.That(new Subnet(1).Equals((Subnet)1), Is.True);
Assert.That(new Subnet(1).Equals((Subnet)2), Is.False);
Assert.That(new Subnet(0).Equals(Subnet.Default), Is.True);
Assert.That(new Subnet(1).ToString, Is.EqualTo("1"));
Assert.That(new Subnet(2).ToString, Is.EqualTo("2"));
Assert.That(new Subnet(1).ToStringDetailed(), Is.EqualTo("Subnet: 1(0x1)"));
Assert.That(new Subnet(2).ToStringDetailed(), Is.EqualTo("Subnet: 2(0x2)"));
Assert.That(new Subnet(15).ToStringDetailed(), Is.EqualTo("Subnet: 15(0xf)"));
Assert.Throws(typeof(ArgumentException), () => new Subnet(16).ToStringDetailed());
});
}
[Test]
Expand Down
6 changes: 6 additions & 0 deletions WellKnownDataTypes-Tests/Light/ArtNet/Universe_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public void TestUniverse()
Assert.That(new Universe(1).Equals((Universe)1), Is.True);
Assert.That(new Universe(1).Equals((Universe)2), Is.False);
Assert.That(new Universe(0).Equals(Universe.Default), Is.True);
Assert.That(new Universe(1).ToString, Is.EqualTo("1"));
Assert.That(new Universe(2).ToString, Is.EqualTo("2"));
Assert.That(new Universe(1).ToStringDetailed(), Is.EqualTo("Universe: 1(0x1)"));
Assert.That(new Universe(2).ToStringDetailed(), Is.EqualTo("Universe: 2(0x2)"));
Assert.That(new Universe(15).ToStringDetailed(), Is.EqualTo("Universe: 15(0xf)"));
Assert.Throws(typeof(ArgumentException), () => new Universe(16).ToStringDetailed());
});
}
[Test]
Expand Down
6 changes: 5 additions & 1 deletion WellKnownDataTypes/Light/ArtNet/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public override int GetHashCode()
}
public override string ToString()
{
return $"{Combined}(0x{Combined:x2}) / Subnet: {Subnet}(0x{Subnet:x1}), Universe: {Universe}(0x{Universe:x1})";
return Combined.ToString();
}
public string ToStringDetailed()
{
return $"Address: {Combined}(0x{Combined:x2}) | {Subnet.ToStringDetailed()}, {Universe.ToStringDetailed()}";
}

public static bool operator ==(in Address a, in Address b)
Expand Down
6 changes: 5 additions & 1 deletion WellKnownDataTypes/Light/ArtNet/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public override int GetHashCode()
}
public override string ToString()
{
return $"Net: {Value}(0x{Value:x})";
return Value.ToString();
}
public string ToStringDetailed()
{
return $"Net: {Value}(0x{Value:x2})";
}

public static bool operator ==(in Net a, in Net b)
Expand Down
6 changes: 5 additions & 1 deletion WellKnownDataTypes/Light/ArtNet/PortAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public override int GetHashCode()
}
public override string ToString()
{
return $"{Combined}(0x{Combined:x4}) / {Net}, {Subnet}, {Universe}";
return Combined.ToString();
}
public string ToStringDetailed()
{
return $"PortAddress: {Combined}(0x{Combined:x4}) | {Net.ToStringDetailed()}, {Subnet.ToStringDetailed()}, {Universe.ToStringDetailed()}";
}

public static bool operator ==(in PortAddress a, in PortAddress b)
Expand Down
4 changes: 4 additions & 0 deletions WellKnownDataTypes/Light/ArtNet/Subnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public override int GetHashCode()
return hashCode;
}
public override string ToString()
{
return Value.ToString();
}
public string ToStringDetailed()
{
return $"Subnet: {Value}(0x{Value:x1})";
}
Expand Down
4 changes: 4 additions & 0 deletions WellKnownDataTypes/Light/ArtNet/Universe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public override int GetHashCode()
return hashCode;
}
public override string ToString()
{
return Value.ToString();
}
public string ToStringDetailed()
{
return $"Universe: {Value}(0x{Value:x1})";
}
Expand Down
2 changes: 1 addition & 1 deletion WellKnownDataTypes/WellKnownDataTypes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>0.0.3</Version>
<Version>0.0.4</Version>
<RepositoryUrl>https://github.com/DMXControl/WellKnownDataTypes</RepositoryUrl>
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down

0 comments on commit c8609e7

Please sign in to comment.