Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-dmxc committed May 26, 2024
1 parent 28edd69 commit b67394c
Show file tree
Hide file tree
Showing 24 changed files with 1,521 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: "nuget"
directory: "/WellKnownDataTypes/"
schedule:
interval: "daily"
open-pull-requests-limit: 5
- package-ecosystem: "nuget"
directory: "/WellKnownDataTypes-Tests/"
schedule:
interval: "daily"
open-pull-requests-limit: 5
43 changes: 43 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build & Test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
dotnet-version: [ '6.0', '7.0', '8.0' ]
fail-fast: false
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4.1.1
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --framework net${{ matrix.dotnet-version }} --collect:"XPlat Code Coverage" --no-restore --verbosity normal --logger trx --results-directory "TestResults-${{ matrix.os }} ${{ matrix.dotnet-version }}"
- name: Upload a Build Artifact
if: ${{ failure() || success() }}
uses: actions/upload-artifact@v4.3.1
with:
name: ${{ matrix.os }} ${{ matrix.dotnet-version }}
path: |
WellKnownDataTypes-Tests/bin/*/net${{ matrix.dotnet-version }}/log.txt
TestResults-${{ matrix.os }} ${{ matrix.dotnet-version }}
WellKnownDataTypes/bin/Release/net${{ matrix.dotnet-version }}/WellKnownDataTypes.dll
retention-days: 2
continue-on-error: true

31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish Packages to nuget

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4.1.4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
7.0.x
8.0.x
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Upload a Build Artifact
uses: actions/upload-artifact@v4.3.3
with:
path: WellKnownDataTypes/bin/Release/**/WellKnownDataTypes.dll
- name: Create Nuget Package
run: dotnet pack --configuration Release
- name: Upload to Nuget.org
run: dotnet nuget push WellKnownDataTypes/bin/Release/*WellKnownDataTypes.*.nupkg --api-key ${{secrets.NUGET_KEY}} -s https://api.nuget.org/v3/index.json
63 changes: 63 additions & 0 deletions WellKnownDataTypes-Tests/Light/ArtNet/Address_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using org.dmxc.wkdt.Light.ArtNet;

namespace org.dmxc.wkdt.Tests.Light.ArtNet
{
public class Address_Tests
{
[Test]
public void TestAddress()
{
Address a = new Address(1);
Assert.Multiple(() =>
{
Assert.That(a.Universe.Value, Is.EqualTo(1));
Assert.That(a.Combined, Is.EqualTo(1));
});

a = new Address(15);
Assert.Multiple(() =>
{
Assert.That(a.Universe.Value, Is.EqualTo(15));
Assert.That(a.Combined, Is.EqualTo(15));
});

a = new Address(16);
Assert.Multiple(() =>
{
Assert.That(a.Universe.Value, Is.EqualTo(0));
Assert.That(a.Subnet.Value, Is.EqualTo(1));
Assert.That(a.Combined, Is.EqualTo(16));
});

a = new Address(0xff);
Assert.Multiple(() =>
{
Assert.That(a.Universe.Value, Is.EqualTo(15));
Assert.That(a.Subnet.Value, Is.EqualTo(15));
Assert.That(a.Combined, Is.EqualTo(0xff));
Assert.That(new Address(16) == new Address(1, 0));
Assert.That(new Address(16) != new Address(0, 1));
Assert.That(new Address(16), Is.EqualTo(new Address(1, 0)));
Assert.That(new Address(16), Is.Not.EqualTo(new Address(0, 1)));
Assert.That(new Address(16), Is.EqualTo((object)new Address(1, 0)));
Assert.That(new Address(16).GetHashCode(), Is.Not.EqualTo(new Address(0, 1).GetHashCode()));
Assert.That(new Address(16).Equals((object)new Address(1, 0)), Is.True);
Assert.That(new Address(16).Equals((object)new Address(0, 1)), Is.False);
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);
});

HashSet<Address> addresses = new HashSet<Address>();
for (byte b = 0; b < byte.MaxValue; b++)
{
Address address = (Address)b;
addresses.Add(address);
Assert.That((byte)address, Is.EqualTo(b));
}
Assert.That(addresses, Has.Count.EqualTo(byte.MaxValue));

Assert.That(addresses.OrderByDescending(s => s.Universe).ThenBy(s => s).ToArray(), Has.Length.EqualTo(byte.MaxValue));
}
}
}
52 changes: 52 additions & 0 deletions WellKnownDataTypes-Tests/Light/ArtNet/Net_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using org.dmxc.wkdt.Light.ArtNet;

namespace org.dmxc.wkdt.Tests.Light.ArtNet
{
public class Net_Tests
{
[Test]
public void TestNet()
{
HashSet<Net> nets = new HashSet<Net>();
for (byte b = 0; b < byte.MaxValue; b++)
{
try
{
Net n = (Net)b;
Assert.Multiple(() =>
{
Assert.That(b, Is.LessThanOrEqualTo(0x7f));
Assert.That(n.Value, Is.EqualTo(b));
Assert.That(n.ToString(), Is.Not.Empty);
});
nets.Add(n);
Assert.That((byte)n, Is.EqualTo(b));
}
catch
{
Assert.That(b, Is.GreaterThan(0x7f));
}
}
Assert.Multiple(() =>
{
Assert.That(nets, Has.Count.EqualTo(0x7f + 1));
Assert.That(nets.OrderByDescending(s => s).OrderBy(s => s.GetHashCode()).OrderBy(s => s).ToList(), Has.Count.EqualTo(0x7f + 1));
});

Assert.Multiple(() =>
{
Assert.That(new Net(1) == (Net)1, Is.True);
Assert.That(new Net(1) != (Net)1, Is.False);
Assert.That(new Net(1) == (Net)2, Is.False);
Assert.That(new Net(1) != (Net)2, Is.True);
Assert.That(new Net(1).GetHashCode(), Is.EqualTo(((Net)1).GetHashCode()));
Assert.That(new Net(1).GetHashCode(), Is.Not.EqualTo(((Net)2).GetHashCode()));
Assert.That(new Net(1).Equals(null), Is.False);
Assert.That(new Net(1).Equals((object)1), Is.False);
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);
});
}
}
}
56 changes: 56 additions & 0 deletions WellKnownDataTypes-Tests/Light/ArtNet/PortAddress_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using org.dmxc.wkdt.Light.ArtNet;

namespace org.dmxc.wkdt.Tests.Light.ArtNet
{
public class PortAddress_Tests
{
[Test]
public void TestPortAddress()
{
HashSet<PortAddress> portAddresses = new HashSet<PortAddress>();
ushort count = 0;
for (ushort b = 0; b < ushort.MaxValue; b++)
{
try
{
PortAddress pa = (PortAddress)b;

Assert.Multiple(() =>
{
Assert.That(b, Is.LessThanOrEqualTo(0x7fff));
Assert.That(pa.Combined, Is.EqualTo(b));
Assert.That(pa.ToString(), Is.Not.Empty);
});
portAddresses.Add(pa);
Assert.That((ushort)pa, Is.EqualTo(b));
count++;
}
catch
{
Assert.That(b, Is.GreaterThan(0x7fff));
}
}
Assert.Multiple(() =>
{
Assert.That(portAddresses, Has.Count.EqualTo(count));
Assert.That(portAddresses.OrderByDescending(s => s).OrderBy(s => s.GetHashCode()).OrderBy(s => s).ToList(), Has.Count.EqualTo(count));
});

Assert.Multiple(() =>
{
Assert.That(new PortAddress((ushort)1) == new PortAddress(0, 0, 1), Is.True);
Assert.That(new PortAddress((ushort)1) != new PortAddress(0, (Universe)1), Is.False);
Assert.That(new PortAddress((ushort)1) != new PortAddress(0, new Address(0, 1)), Is.False);
Assert.That(new PortAddress(1) == new PortAddress(0, 0, 2), Is.False);
Assert.That(new PortAddress(1) != new PortAddress(0, (Universe)2), Is.True);
Assert.That(new PortAddress(1).GetHashCode(), Is.EqualTo(((PortAddress)1).GetHashCode()));
Assert.That(new PortAddress((ushort)1).GetHashCode(), Is.Not.EqualTo(((PortAddress)2).GetHashCode()));
Assert.That(new PortAddress(1).Equals(null), Is.False);
Assert.That(new PortAddress(1).Equals((object)1), Is.False);
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);
});
}
}
}
54 changes: 54 additions & 0 deletions WellKnownDataTypes-Tests/Light/ArtNet/Subnet_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using org.dmxc.wkdt.Light.ArtNet;

namespace org.dmxc.wkdt.Tests.Light.ArtNet
{
public class Subnet_Tests
{
[Test]
public void TestSubnet()
{
HashSet<Subnet> subNets = new HashSet<Subnet>();
for (byte b = 0; b < byte.MaxValue; b++)
{
try
{
Subnet s = (Subnet)b;

Assert.Multiple(() =>
{
Assert.That(b, Is.LessThanOrEqualTo(0xf));
Assert.That(s.Value, Is.EqualTo(b));
Assert.That(s.ToString(), Is.Not.Empty);
});
subNets.Add(s);
Assert.That((byte)s, Is.EqualTo(b));
}
catch
{
Assert.That(b, Is.GreaterThan(0xf));
}
}
Assert.Multiple(() =>
{
Assert.That(subNets, Has.Count.EqualTo(0xf + 1));
Assert.That(subNets.OrderByDescending(s => s).OrderBy(s => s.GetHashCode()).OrderBy(s => s).ToList(), Has.Count.EqualTo(0xf + 1));
});

Assert.Multiple(() =>
{
Assert.That(new Subnet(1) == (Subnet)1, Is.True);
Assert.That(new Subnet(1) != (Subnet)1, Is.False);
Assert.That(new Subnet(1) == (Subnet)2, Is.False);
Assert.That(new Subnet(1) != (Subnet)2, Is.True);
Assert.That(new Subnet(1).GetHashCode(), Is.EqualTo(((Subnet)1).GetHashCode()));
Assert.That(new Subnet(1).GetHashCode(), Is.Not.EqualTo(((Subnet)2).GetHashCode()));
Assert.That(new Subnet(1).Equals(null), Is.False);
Assert.That(new Subnet(1).Equals((object)1), Is.False);
Assert.That(new Subnet(1).Equals((object)(Subnet)1), Is.True);
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);
});
}
}
}
53 changes: 53 additions & 0 deletions WellKnownDataTypes-Tests/Light/ArtNet/Universe_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using org.dmxc.wkdt.Light.ArtNet;

namespace org.dmxc.wkdt.Tests.Light.ArtNet
{
public class Universe_Tests
{
[Test]
public void TestUniverse()
{
HashSet<Universe> universes = new HashSet<Universe>();
for (byte b = 0; b < byte.MaxValue; b++)
{
try
{
Universe u = (Universe)b;
Assert.Multiple(() =>
{
Assert.That(b, Is.LessThanOrEqualTo(0xf));
Assert.That(u.Value, Is.EqualTo(b));
Assert.That(u.ToString(), Is.Not.Empty);
});
universes.Add(u);
Assert.That((byte)u, Is.EqualTo(b));
}
catch
{
Assert.That(b, Is.GreaterThan(0xf));
}
}
Assert.Multiple(() =>
{
Assert.That(universes, Has.Count.EqualTo(0xf + 1));
Assert.That(universes.OrderByDescending(s => s).OrderBy(s => s.GetHashCode()).OrderBy(s => s).ToList(), Has.Count.EqualTo(0xf + 1));
});

Assert.Multiple(() =>
{
Assert.That(new Universe(1) == (Universe)1, Is.True);
Assert.That(new Universe(1) != (Universe)1, Is.False);
Assert.That(new Universe(1) == (Universe)2, Is.False);
Assert.That(new Universe(1) != (Universe)2, Is.True);
Assert.That(new Universe(1).GetHashCode(), Is.EqualTo(((Universe)1).GetHashCode()));
Assert.That(new Universe(1).GetHashCode(), Is.Not.EqualTo(((Universe)2).GetHashCode()));
Assert.That(new Universe(1).Equals(null), Is.False);
Assert.That(new Universe(1).Equals((object)1), Is.False);
Assert.That(new Universe(1).Equals((object)(Universe)1), Is.True);
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);
});
}
}
}
Loading

0 comments on commit b67394c

Please sign in to comment.