-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
href: linear.md | ||
- name: Union (|) | ||
href: union.md | ||
- name: Intersect (&) | ||
href: intersect.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters