From 2b9b126431897ee0efdda4e5c5c3311d99d0c6c7 Mon Sep 17 00:00:00 2001 From: aevitas Date: Sun, 25 Feb 2024 19:50:10 +0100 Subject: [PATCH] Add tests for timestamped overload --- src/FlakeId.Tests/IdTests.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/FlakeId.Tests/IdTests.cs b/src/FlakeId.Tests/IdTests.cs index b8c00ba..bfd085b 100644 --- a/src/FlakeId.Tests/IdTests.cs +++ b/src/FlakeId.Tests/IdTests.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using FlakeId.Extensions; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace FlakeId.Tests; @@ -17,6 +19,16 @@ public void Id_Create() Assert.IsTrue(id > 1); } + [TestMethod] + public void Id_CreateFromTimeStamp() + { + // Example ID for this timestamp: 1211383614714445825 + long timeStamp = 1708886760167; + Id id = Id.Create(timeStamp); + + Assert.AreEqual(timeStamp, id.ToUnixTimeMilliseconds()); + } + [TestMethod] public void Id_CreateManyFast() { @@ -31,7 +43,7 @@ public void Id_CreateManyFast() [TestMethod] public async Task Id_CreateManyDelayed() { - List ids = new(); + List ids = []; for (int i = 0; i < 100; i++) { @@ -60,7 +72,7 @@ public void Id_Sortable() { // The sequence in which Ids are generated should be equal to a set of sorted Ids. Id[] ids = Enumerable.Range(0, 1000).Select(_ => Id.Create()).ToArray(); - Id[] sorted = ids.OrderBy(i => i).ToArray(); + Id[] sorted = [.. ids.OrderBy(i => i)]; Assert.IsTrue(ids.SequenceEqual(sorted)); }