-
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
131 additions
and
10 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 |
---|---|---|
|
@@ -11,3 +11,5 @@ | |
href: from.md | ||
- name: Linear | ||
href: linear.md | ||
- name: Union (|) | ||
href: union.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Union (|) | ||
|
||
@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. | ||
|
||
Using the @Eon.Schedule.Union* method, | ||
|
||
[!code-csharp[Example1](../../../Eon.Tests/Examples/UnionTests.cs#Example1)] | ||
|
||
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 | ||
|
||
[!code-csharp[Example3](../../../Eon.Tests/Examples/UnionTests.cs#Example3)] |
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,65 @@ | ||
namespace Eon.Tests.Examples; | ||
|
||
public static class UnionTests | ||
{ | ||
[Fact(DisplayName = "Union returns the min duration of either schedule")] | ||
public static void Case1() | ||
{ | ||
#region Example1 | ||
Schedule union = Schedule | ||
.Linear(TimeSpan.FromSeconds(1)) | ||
.Union(Schedule.Spaced(TimeSpan.FromSeconds(3))); | ||
|
||
using var enumerator = union.GetEnumerator(); | ||
enumerator.MoveNext().Should().BeTrue(); | ||
enumerator.Current.Should().Be(TimeSpan.FromSeconds(1)); | ||
enumerator.MoveNext().Should().BeTrue(); | ||
enumerator.Current.Should().Be(TimeSpan.FromSeconds(2)); | ||
enumerator.MoveNext().Should().BeTrue(); | ||
enumerator.Current.Should().Be(TimeSpan.FromSeconds(3)); | ||
enumerator.MoveNext().Should().BeTrue(); | ||
enumerator.Current.Should().Be(TimeSpan.FromSeconds(3)); | ||
|
||
#endregion | ||
} | ||
|
||
[Fact(DisplayName = "Union operator returns the min duration of either schedule")] | ||
public static void Case2() | ||
{ | ||
#region Example2 | ||
Schedule union = | ||
Schedule.Spaced(TimeSpan.FromSeconds(4)) | ||
| Schedule.Linear(TimeSpan.FromSeconds(1), factor: 2); | ||
|
||
using var enumerator = union.GetEnumerator(); | ||
enumerator.MoveNext().Should().BeTrue(); | ||
enumerator.Current.Should().Be(TimeSpan.FromSeconds(1)); | ||
enumerator.MoveNext().Should().BeTrue(); | ||
enumerator.Current.Should().Be(TimeSpan.FromSeconds(3)); | ||
enumerator.MoveNext().Should().BeTrue(); | ||
enumerator.Current.Should().Be(TimeSpan.FromSeconds(4)); | ||
enumerator.MoveNext().Should().BeTrue(); | ||
enumerator.Current.Should().Be(TimeSpan.FromSeconds(4)); | ||
|
||
#endregion | ||
} | ||
|
||
[Fact(DisplayName = "Union operator returns the longest 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(4); | ||
|
||
Schedule rightSideLonger = | ||
Schedule.Spaced(TimeSpan.FromSeconds(4)).Take(2) | ||
| Schedule.Linear(TimeSpan.FromSeconds(1), factor: 2).Take(3); | ||
|
||
rightSideLonger.Should().HaveCount(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
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