Skip to content

Commit

Permalink
feat: intersect docs and tests [ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
bmazzarol committed Oct 11, 2023
1 parent 29b1eac commit 45323e0
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Eon.Docs/articles/components/intersect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Intersect (&)

@Eon.Schedule.Intersect* returns the intersect of two @Eon.Schedule.
As long as both of the two @Eon.Schedule are still running it will return the
maximum @Eon.Duration.

Using the @Eon.Schedule.Intersect* method,

[!code-csharp[Example1](../../../Eon.Tests/Examples/IntersectTests.cs#Example1)]

Using the @Eon.Schedule.op_BitwiseAnd*,

[!code-csharp[Example2](../../../Eon.Tests/Examples/IntersectTests.cs#Example2)]

The returned @Eon.Schedule will run as long as the shortest of the two
@Eon.Schedule

[!code-csharp[Example3](../../../Eon.Tests/Examples/IntersectTests.cs#Example3)]

@Eon.Schedule.op_BitwiseAnd* can be used with @Eon.ScheduleTransformer,

[!code-csharp[Example4](../../../Eon.Tests/Examples/IntersectTests.cs#Example4)]
2 changes: 2 additions & 0 deletions Eon.Docs/articles/components/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
href: linear.md
- name: Union (|)
href: union.md
- name: Intersect (&)
href: intersect.md
8 changes: 6 additions & 2 deletions Eon.Docs/articles/components/union.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@Eon.Schedule.Union* returns the union of two @Eon.Schedule.
As long as any of the two @Eon.Schedule are still running it will return the
minimum @Eon.Duration of either.
minimum @Eon.Duration.

Using the @Eon.Schedule.Union* method,

Expand All @@ -13,6 +13,10 @@ Using the @Eon.Schedule.op_BitwiseOr*,
[!code-csharp[Example2](../../../Eon.Tests/Examples/UnionTests.cs#Example2)]

The returned @Eon.Schedule will run as long as the longest of the two
@Eon.Schedule
@Eon.Schedule,

[!code-csharp[Example3](../../../Eon.Tests/Examples/UnionTests.cs#Example3)]

@Eon.Schedule.op_BitwiseOr* can be used with @Eon.ScheduleTransformer,

[!code-csharp[Example4](../../../Eon.Tests/Examples/UnionTests.cs#Example4)]
85 changes: 85 additions & 0 deletions Eon.Tests/Examples/IntersectTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
namespace Eon.Tests.Examples;

public static class IntersectTests
{
[Fact(DisplayName = "Intersect returns the max duration of either schedule")]
public static void Case1()
{
#region Example1
Schedule intersect = Schedule
.Linear(TimeSpan.FromSeconds(1))
.Intersect(Schedule.Spaced(TimeSpan.FromSeconds(3)));

using var enumerator = intersect.GetEnumerator();
enumerator.MoveNext().Should().BeTrue();
enumerator.Current.Should().Be(TimeSpan.FromSeconds(3));
enumerator.MoveNext().Should().BeTrue();
enumerator.Current.Should().Be(TimeSpan.FromSeconds(3));
enumerator.MoveNext().Should().BeTrue();
enumerator.Current.Should().Be(TimeSpan.FromSeconds(3));
enumerator.MoveNext().Should().BeTrue();
enumerator.Current.Should().Be(TimeSpan.FromSeconds(4));

#endregion
}

[Fact(DisplayName = "Intersect operator returns the max duration of either schedule")]
public static void Case2()
{
#region Example2
Schedule intersect =
Schedule.Spaced(TimeSpan.FromSeconds(4))
& Schedule.Linear(TimeSpan.FromSeconds(1), factor: 2);

using var enumerator = intersect.GetEnumerator();
enumerator.MoveNext().Should().BeTrue();
enumerator.Current.Should().Be(TimeSpan.FromSeconds(4));
enumerator.MoveNext().Should().BeTrue();
enumerator.Current.Should().Be(TimeSpan.FromSeconds(4));
enumerator.MoveNext().Should().BeTrue();
enumerator.Current.Should().Be(TimeSpan.FromSeconds(5));
enumerator.MoveNext().Should().BeTrue();
enumerator.Current.Should().Be(TimeSpan.FromSeconds(7));

#endregion
}

[Fact(DisplayName = "Intersect operator returns the shortest of the 2 schedules")]
public static void Case3()
{
#region Example3
Schedule leftSideLonger =
Schedule.Spaced(TimeSpan.FromSeconds(4)).Take(4)
& Schedule.Linear(TimeSpan.FromSeconds(1), factor: 2).Take(2);

leftSideLonger.Should().HaveCount(2);

Schedule rightSideLonger =
Schedule.Spaced(TimeSpan.FromSeconds(4)).Take(3)
& Schedule.Linear(TimeSpan.FromSeconds(1), factor: 2).Take(4);

rightSideLonger.Should().HaveCount(3);

#endregion
}

[Fact(DisplayName = "Intersect operator can be used with transformers")]
public static void Case4()
{
#region Example4
Schedule union1 =
Schedule.Spaced(TimeSpan.FromSeconds(4)).Take(4) & Schedule.NoDelayOnFirst;

union1.Should().HaveCount(4).And.ContainInOrder(Duration.Zero, TimeSpan.FromSeconds(4));

Schedule union2 =
Schedule.NoDelayOnFirst & Schedule.Linear(TimeSpan.FromSeconds(1)).Take(4);

union2
.Should()
.HaveCount(4)
.And.ContainInOrder(Duration.Zero, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(3));

#endregion
}
}
20 changes: 20 additions & 0 deletions Eon.Tests/Examples/UnionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,24 @@ public static void Case3()

#endregion
}

[Fact(DisplayName = "Union operator can be used with transformers")]
public static void Case4()
{
#region Example4
Schedule union1 =
Schedule.Spaced(TimeSpan.FromSeconds(4)).Take(4) | Schedule.NoDelayOnFirst;

union1.Should().HaveCount(4).And.ContainInOrder(Duration.Zero, TimeSpan.FromSeconds(4));

Schedule union2 =
Schedule.NoDelayOnFirst | Schedule.Linear(TimeSpan.FromSeconds(1)).Take(4);

union2
.Should()
.HaveCount(4)
.And.ContainInOrder(Duration.Zero, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(3));

#endregion
}
}

0 comments on commit 45323e0

Please sign in to comment.