From c8609e7508315bea75df62c350e64e497d25cd99 Mon Sep 17 00:00:00 2001 From: Patrick Grote Date: Thu, 20 Jun 2024 15:56:56 +0200 Subject: [PATCH] Refactor some ToString Methodes Bump v0.0.4 --- WellKnownDataTypes-Tests/Light/ArtNet/Address_Tests.cs | 8 ++++++++ WellKnownDataTypes-Tests/Light/ArtNet/Net_Tests.cs | 6 ++++++ .../Light/ArtNet/PortAddress_Tests.cs | 9 +++++++++ WellKnownDataTypes-Tests/Light/ArtNet/Subnet_Tests.cs | 6 ++++++ WellKnownDataTypes-Tests/Light/ArtNet/Universe_Tests.cs | 6 ++++++ WellKnownDataTypes/Light/ArtNet/Address.cs | 6 +++++- WellKnownDataTypes/Light/ArtNet/Net.cs | 6 +++++- WellKnownDataTypes/Light/ArtNet/PortAddress.cs | 6 +++++- WellKnownDataTypes/Light/ArtNet/Subnet.cs | 4 ++++ WellKnownDataTypes/Light/ArtNet/Universe.cs | 4 ++++ WellKnownDataTypes/WellKnownDataTypes.csproj | 2 +- 11 files changed, 59 insertions(+), 4 deletions(-) diff --git a/WellKnownDataTypes-Tests/Light/ArtNet/Address_Tests.cs b/WellKnownDataTypes-Tests/Light/ArtNet/Address_Tests.cs index a23934e..c2fd67e 100644 --- a/WellKnownDataTypes-Tests/Light/ArtNet/Address_Tests.cs +++ b/WellKnownDataTypes-Tests/Light/ArtNet/Address_Tests.cs @@ -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
addresses = new HashSet
(); diff --git a/WellKnownDataTypes-Tests/Light/ArtNet/Net_Tests.cs b/WellKnownDataTypes-Tests/Light/ArtNet/Net_Tests.cs index f000980..f7b20b7 100644 --- a/WellKnownDataTypes-Tests/Light/ArtNet/Net_Tests.cs +++ b/WellKnownDataTypes-Tests/Light/ArtNet/Net_Tests.cs @@ -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)")); }); } diff --git a/WellKnownDataTypes-Tests/Light/ArtNet/PortAddress_Tests.cs b/WellKnownDataTypes-Tests/Light/ArtNet/PortAddress_Tests.cs index 9c115b6..2d7f934 100644 --- a/WellKnownDataTypes-Tests/Light/ArtNet/PortAddress_Tests.cs +++ b/WellKnownDataTypes-Tests/Light/ArtNet/PortAddress_Tests.cs @@ -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)")); }); } diff --git a/WellKnownDataTypes-Tests/Light/ArtNet/Subnet_Tests.cs b/WellKnownDataTypes-Tests/Light/ArtNet/Subnet_Tests.cs index bbf64a2..7b9c01e 100644 --- a/WellKnownDataTypes-Tests/Light/ArtNet/Subnet_Tests.cs +++ b/WellKnownDataTypes-Tests/Light/ArtNet/Subnet_Tests.cs @@ -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] diff --git a/WellKnownDataTypes-Tests/Light/ArtNet/Universe_Tests.cs b/WellKnownDataTypes-Tests/Light/ArtNet/Universe_Tests.cs index b15b6cd..a1c1b05 100644 --- a/WellKnownDataTypes-Tests/Light/ArtNet/Universe_Tests.cs +++ b/WellKnownDataTypes-Tests/Light/ArtNet/Universe_Tests.cs @@ -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] diff --git a/WellKnownDataTypes/Light/ArtNet/Address.cs b/WellKnownDataTypes/Light/ArtNet/Address.cs index 5afb5ce..450ea5d 100644 --- a/WellKnownDataTypes/Light/ArtNet/Address.cs +++ b/WellKnownDataTypes/Light/ArtNet/Address.cs @@ -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) diff --git a/WellKnownDataTypes/Light/ArtNet/Net.cs b/WellKnownDataTypes/Light/ArtNet/Net.cs index acef2fd..6edcb01 100644 --- a/WellKnownDataTypes/Light/ArtNet/Net.cs +++ b/WellKnownDataTypes/Light/ArtNet/Net.cs @@ -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) diff --git a/WellKnownDataTypes/Light/ArtNet/PortAddress.cs b/WellKnownDataTypes/Light/ArtNet/PortAddress.cs index 7553ebd..b314d8d 100644 --- a/WellKnownDataTypes/Light/ArtNet/PortAddress.cs +++ b/WellKnownDataTypes/Light/ArtNet/PortAddress.cs @@ -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) diff --git a/WellKnownDataTypes/Light/ArtNet/Subnet.cs b/WellKnownDataTypes/Light/ArtNet/Subnet.cs index e971345..07b8add 100644 --- a/WellKnownDataTypes/Light/ArtNet/Subnet.cs +++ b/WellKnownDataTypes/Light/ArtNet/Subnet.cs @@ -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})"; } diff --git a/WellKnownDataTypes/Light/ArtNet/Universe.cs b/WellKnownDataTypes/Light/ArtNet/Universe.cs index 6422fd5..a773bdb 100644 --- a/WellKnownDataTypes/Light/ArtNet/Universe.cs +++ b/WellKnownDataTypes/Light/ArtNet/Universe.cs @@ -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})"; } diff --git a/WellKnownDataTypes/WellKnownDataTypes.csproj b/WellKnownDataTypes/WellKnownDataTypes.csproj index fe54cb7..f9ab8c2 100644 --- a/WellKnownDataTypes/WellKnownDataTypes.csproj +++ b/WellKnownDataTypes/WellKnownDataTypes.csproj @@ -2,7 +2,7 @@ netstandard2.0;net6.0;net7.0;net8.0 LICENSE - 0.0.3 + 0.0.4 https://github.com/DMXControl/WellKnownDataTypes $(RepositoryUrl) README.md