Skip to content

Commit

Permalink
Add tests for timestamped overload
Browse files Browse the repository at this point in the history
  • Loading branch information
aevitas committed Feb 25, 2024
1 parent 88d0e07 commit 2b9b126
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/FlakeId.Tests/IdTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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()
{
Expand All @@ -31,7 +43,7 @@ public void Id_CreateManyFast()
[TestMethod]
public async Task Id_CreateManyDelayed()
{
List<Id> ids = new();
List<Id> ids = [];

for (int i = 0; i < 100; i++)
{
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 2b9b126

Please sign in to comment.