Created
November 20, 2020 07:28
-
-
Save DimsFromDergachy/987248be0c1a528ba9ec5d567a9da9dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| using System; | |
| using System.Linq; | |
| using FsCheck; | |
| using FsCheck.NUnit; | |
| namespace DiamondGenerator.Tests | |
| { | |
| [NUnit.Framework.TestFixture] | |
| public class DiamondTests | |
| { | |
| [Property(Arbitrary = new[] {typeof(LetterGenerator)})] | |
| public Property NotEmpty(char c) | |
| { | |
| return Diamond.Generate(c) | |
| .All(s => s != string.Empty) | |
| .ToProperty(); | |
| } | |
| [Property(Arbitrary = new[] {typeof(LetterGenerator)})] | |
| public Property FirstLineContainsA(char c) | |
| { | |
| return Diamond.Generate(c) | |
| .First().Contains('A') | |
| .ToProperty(); | |
| } | |
| [Property(Arbitrary = new[] {typeof(LetterGenerator)})] | |
| public Property LastLineContainsA(char c) | |
| { | |
| return Diamond.Generate(c) | |
| .Last().Contains('A') | |
| .ToProperty(); | |
| } | |
| [Property(Arbitrary = new[] {typeof(LetterGenerator)})] | |
| public Property DiamondWidthEqualsHeight(char c) | |
| { | |
| var diamond = Diamond.Generate(c).ToList(); | |
| return diamond | |
| .All(row => row.Length == diamond.Count()) | |
| .ToProperty(); | |
| } | |
| [Property(Arbitrary = new[] {typeof(LetterGenerator)})] | |
| public Property SymmetricAroundVerticalAxis(char c) | |
| { | |
| return Diamond.Generate(c) | |
| .All(row => row.SequenceEqual(row.Reverse())) | |
| .ToProperty(); | |
| } | |
| [Property(Arbitrary = new[] {typeof(LetterGenerator)})] | |
| public Property SymmetricAroundHorizontalAxis(char c) | |
| { | |
| var diamond = Diamond.Generate(c).ToArray(); | |
| return diamond.SequenceEqual(diamond.Reverse()) | |
| .ToProperty(); | |
| } | |
| [Property(Arbitrary = new[] {typeof(LetterGenerator)})] | |
| public Property ThereIsSingleLineContainsInputLetter(char c) | |
| { | |
| _ = Diamond.Generate(c).Single(row => row.Contains(c)); | |
| return true.ToProperty(); | |
| } | |
| [Property(Arbitrary = new[] {typeof(LetterGenerator)})] | |
| public Property InputLetterRowContainsNoPaddingSpaces(char c) | |
| { | |
| return Diamond.Generate(c) | |
| .Any(row => row.Contains(c) && row == row.Trim()) | |
| .ToProperty(); | |
| } | |
| [Property(Arbitrary = new[] {typeof(LetterGenerator)})] | |
| public Property EachLineContainsNoMoreTwoLetters(char c) | |
| { | |
| return Diamond.Generate(c) | |
| .All(row => row.Count(char.IsLetter) <= 2) | |
| .ToProperty(); | |
| } | |
| [Property(Arbitrary = new[] {typeof(LetterGenerator)})] | |
| public Property FirstHalfLinesIsOrderedByAlphabetic(char c) | |
| { | |
| var diamond = Diamond.Generate(c).ToList(); | |
| return diamond | |
| .Take(diamond.Count() / 2) | |
| .Select(row => row.First(char.IsLetter)) | |
| .SequenceEqual(Enumerable.Range('A', c).Select(Convert.ToChar)) | |
| .ToProperty(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment