コード例 #1
0
 public Property ShouldProduceASquareOutput() =>
 Prop.ForAll(UpperCase(), c =>
 {
     var lines  = DiamondShaped.DiamonLines(c);
     var height = lines.Count();
     return(lines.All(l => l.Length == height));
 });
コード例 #2
0
 public void ExampleC()
 {
     Assert.That(
         DiamondShaped.DiamonLines('C').ToArray(),
         Is.EquivalentTo(new[] { "  A  ", " B B ", "C   C", " B B ", "  A  " })
         );
 }
コード例 #3
0
 public void ExampleA()
 {
     Assert.That(
         DiamondShaped.DiamonLines('A'),
         Is.EquivalentTo(new[] { "A" })
         );
 }
コード例 #4
0
 public Property ShouldHaveVerticalSymetry() =>
 Prop.ForAll(UpperCase(), c =>
 {
     var lines = DiamondShaped.DiamonLines(c);
     return(lines.Reverse()
            .Zip(lines)
            .All(tuple => tuple.First == tuple.Second));
 });
コード例 #5
0
 public Property EachLineShouldOnlyHaveOneLetter() =>
 Prop.ForAll(UpperCase(), c =>
 {
     var lines = DiamondShaped.DiamonLines(c);
     return(lines.Select(l => l.Replace(" ", ""))
            .Select(l => l.Distinct())
            .All(l => l.Count() == 1));
 });
コード例 #6
0
 public Property ShouldPositionLettersCorrectly() =>
 Prop.ForAll(UpperCase(), c =>
 {
     var lines    = DiamondShaped.DiamonLines(c).ToArray();
     var midPoint = lines.Length / 2 + 1;
     var matrix   = lines.Take(midPoint).Reverse().Select(l => l.Substring(0, midPoint).ToCharArray()).ToArray();
     foreach (var i in Enumerable.Range(0, midPoint))
     {
         var expectedC = (char)(c - i);
         if (matrix[i][i] != expectedC)
         {
             return(false);
         }
     }
     return(true);
 });
コード例 #7
0
 public Property ShouldHaveHorizontalSymetry() =>
 Prop.ForAll(UpperCase(), c =>
 {
     DiamondShaped.DiamonLines(c)
     .All(line => string.Join("", line.Reverse()) == line);
 });
コード例 #8
0
 public Property ShouldAlwaysProduceAnOddNumberOfLines() =>
 Prop.ForAll(UpperCase(), c =>
             DiamondShaped.DiamonLines(c).Count() % 2 == 1
             );
コード例 #9
0
 public Property ShouldAlwaysProduceLines() =>
 Prop.ForAll(UpperCase(), c =>
             DiamondShaped.DiamonLines(c).Count() != 0
             );