forked from overengineering/sharpasonne
-
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.
Adds FeatureListValidator and some tests.
- Loading branch information
Lee Richardson
committed
Dec 13, 2017
1 parent
6e564da
commit febeb2c
Showing
4 changed files
with
76 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Optional.Unsafe; | ||
using Sharpasonne.Models.Features; | ||
using Xunit; | ||
|
||
namespace Sharpasonne.Models.Tests | ||
{ | ||
public class FeatureListValidatorTests | ||
{ | ||
[Fact] | ||
void Given_EmptyTile_When_CheckingForOverlaps_Then_IsValid() | ||
{ | ||
var featureList = Enumerable.Empty<IFeature>().ToImmutableList(); | ||
var isValid = new FeatureListValidator().CheckFeaturesDontOverlap(featureList); | ||
|
||
Assert.True(isValid); | ||
} | ||
|
||
[Fact] | ||
void Given_OverlappingFeaturesTile_When_CheckingForOverlaps_Then_IsNotValid() | ||
{ | ||
var segments = Enumerable.Repeat(Segment.Left, 2) | ||
.ToImmutableHashSet(); | ||
var overlappingFeatures = Enumerable.Repeat(new Field(segments) as IFeature, 2) | ||
.ToImmutableList(); | ||
|
||
var isValid = new FeatureListValidator().CheckFeaturesDontOverlap(overlappingFeatures); | ||
|
||
Assert.False(isValid); | ||
} | ||
|
||
[Fact] | ||
void Given_EmptyTile_When_CheckingForFields_Then_AllFields() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
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,28 @@ | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using JetBrains.Annotations; | ||
|
||
namespace Sharpasonne.Models | ||
{ | ||
public class FeatureListValidator | ||
{ | ||
public bool IsValid([NotNull] IImmutableList<IFeature> featureList) | ||
{ | ||
var isValid = CheckFeaturesDontOverlap(featureList); | ||
|
||
return isValid; | ||
} | ||
|
||
public bool CheckFeaturesDontOverlap( | ||
[NotNull] [ItemNotNull] IImmutableList<IFeature> featureList) | ||
{ | ||
var segments = featureList | ||
.SelectMany(f => f.Connections) | ||
.ToList(); | ||
|
||
var distinctSegments = segments.Distinct(); | ||
|
||
return segments.Count() == distinctSegments.Count(); | ||
} | ||
} | ||
} |
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