-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pr#32 issue#31-issue#33-marked-composite
Marked composite types, functions, and tests.
- Loading branch information
Showing
20 changed files
with
526 additions
and
87 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
51 changes: 51 additions & 0 deletions
51
Composite/Composite.Cs.Tests/Composites/EnsureHasContainerTests.cs
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,51 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
using Xunit; | ||
using Composite.Cs.Tests.Infrastructure; | ||
|
||
namespace Composite.Cs.Tests.Composites | ||
{ | ||
public class EnsureHasContainerTests | ||
{ | ||
[Fact] | ||
public void TransformationTest() | ||
{ | ||
var obj = MarkedComposite.Create(string.Empty, new[] { | ||
MarkedComposite.Create("inner composite", new[]{ | ||
MarkedComposite.CreateValue("mark", new Simple { Number = 1, }), | ||
MarkedComposite.Create("inner composite level2", new[]{ | ||
MarkedComposite.CreateValue("mark2", new Simple { Number = 2, }) | ||
}) | ||
}) | ||
}); | ||
|
||
var result = obj.EnsureHasContainer( | ||
"inner composite", | ||
"inner composite level2", | ||
(x, y) => x == y); | ||
|
||
Assert.Equal("[ ( inner composite )[ ( mark )1, ( inner composite level2 )[ ( mark2 )2 ] ] ]", result.ToStringShort()); | ||
|
||
result = obj.EnsureHasContainer( | ||
string.Empty, | ||
"inner composite2", | ||
(x, y) => x == y); | ||
|
||
Assert.Equal("[ ( inner composite )[ ( mark )1, ( inner composite level2 )[ ( mark2 )2 ] ], ( inner composite2 )[ ] ]", result.ToStringShort()); | ||
} | ||
|
||
[Fact] | ||
public void TrivialCaseTest() | ||
{ | ||
var obj = MarkedComposite.CreateValue("mark", new Simple { Number = 1, }); | ||
|
||
var result = obj.EnsureHasContainer( | ||
string.Empty, | ||
"mark", | ||
(x, y) => x == y); | ||
|
||
Assert.Equal("( mark )1", result.ToStringShort()); | ||
} | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
Composite/Composite.Cs.Tests/Composites/MarkedCompositeEmptyTests.cs
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,20 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
using Xunit; | ||
|
||
using Composite; | ||
using Composite.Cs.Tests.Infrastructure; | ||
|
||
namespace Composite.Cs.Tests.Composites | ||
{ | ||
public class MarkedCompositeEmptyTests | ||
{ | ||
[Fact] | ||
public void GenerationTest(){ | ||
var result = MarkedComposite.Empty<string, Simple>("mark"); | ||
|
||
Assert.Equal("( mark )[ ]", result.ToStringShort()); | ||
} | ||
} | ||
} |
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,51 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
using Xunit; | ||
using Composite.Cs.Tests.Infrastructure; | ||
|
||
namespace Composite.Cs.Tests.Composites | ||
{ | ||
public class SetValueTests | ||
{ | ||
[Fact] | ||
public void TransformationTest() | ||
{ | ||
var obj = MarkedComposite.Create(string.Empty, new[] { | ||
MarkedComposite.Create("inner composite", new[]{ | ||
MarkedComposite.CreateValue("mark", new Simple { Number = 1, }) | ||
}) | ||
}); | ||
|
||
var result = obj.SetValue( | ||
"inner composite", | ||
"mark", | ||
new Simple { Number = 2, }, | ||
(x, y) => x == y); | ||
|
||
Assert.Equal("[ ( inner composite )[ ( mark )2 ] ]", result.ToStringShort()); | ||
|
||
result = obj.SetValue( | ||
"inner composite", | ||
"mark2", | ||
new Simple { Number = 2, }, | ||
(x, y) => x == y); | ||
|
||
Assert.Equal("[ ( inner composite )[ ( mark )1, ( mark2 )2 ] ]", result.ToStringShort()); | ||
} | ||
|
||
[Fact] | ||
public void TrivialCaseTest() | ||
{ | ||
var obj = MarkedComposite.CreateValue("mark", new Simple { Number = 1, }); | ||
|
||
var result = obj.SetValue( | ||
string.Empty, | ||
"mark", | ||
new Simple { Number = 2, }, | ||
(x, y) => x == y); | ||
|
||
Assert.Equal("( mark )1", result.ToStringShort()); | ||
} | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
Composite/Composite.Cs.Tests/Infrastructure/AllowTakeTests.cs
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,34 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
using Xunit; | ||
|
||
namespace Composite.Cs.Tests.Infrastructure | ||
{ | ||
public class AllowTakeTests | ||
{ | ||
[Fact] | ||
public void TransformationTest() | ||
{ | ||
var limitedEnumerable = Enumerable.Range(1, 5).AllowTake(4); | ||
|
||
var result = limitedEnumerable.Take(4).ToArray(); | ||
Assert.Equal(new[]{1, 2, 3, 4}, result); | ||
|
||
Assert.Throws<InvalidOperationException>(() => limitedEnumerable.Take(5).ToArray()); | ||
} | ||
|
||
[Fact] | ||
public void TrivialParametersTest() | ||
{ | ||
var limitedEnumerable = Enumerable.Empty<int>().AllowTake(0); | ||
Assert.Throws<InvalidOperationException>(() => limitedEnumerable.ToArray()); | ||
|
||
limitedEnumerable = Enumerable.Range(1, 5).AllowTake(0); | ||
Assert.Throws<InvalidOperationException>(() => limitedEnumerable.Take(1).ToArray()); | ||
|
||
limitedEnumerable = Enumerable.Empty<int>().AllowTake(1); | ||
limitedEnumerable.ToArray(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.