public void PassingTestWhereItWorksProperlyFluent() { Spec .For(GenExpr, e => e.Rewrite().Eval() == e.Eval()) .Shrink(ShrinkExpr) .Check(Config2.ToConfiguration()); }
private static void CheckPriceOfBooksSpec(Gen <string[]> gen, Func <string[], decimal> expectedPriceFunc) { Spec .For(gen, titles => CheckPriceOfBooks(titles, expectedPriceFunc(titles))) .Shrink(DontShrink <string[]>()) .QuickCheckThrowOnFailure(); }
public void FalsifiableTestToDemonstrateShrinkingFluent() { Spec .For(GenExpr, e => e.Rewrite(true).Eval() == e.Eval()) .Shrink(ShrinkExpr) .Check(Config2.ToConfiguration()); }
public Property Property(DontShrink <IList <int> > dsxsParam) { var generator = Any.Value(dsxsParam).Select(dsxs => dsxs.Item); Func <IList <int>, bool> assertion = xs => xs.Reverse().Reverse().SequenceEqual(xs); return(Spec.For(generator, assertion).Build()); }
public Property PropertyFluent(int n) { return(Spec .For(Any.Value(n), i => n + n == 2 * n) .Classify(x => x % 2 == 0, "even") .Classify(x => x % 2 != 0, "odd") .Classify(x => x < 0, "neg") .Classify(x => x >= 0, "pos") .Classify(x => Math.Abs(x) > 50, "large") .Build()); }
public void RunLengthEncodingTestFluent() { Spec .For(GenOutput, r => { var original = r.ToList(); var actual = RLE.RunLengthEnc(RLE.RunLengthDec(original)); return(actual.SequenceEqual(original)); }) .Check(Configuration); }
public Property RunLengthEncodingPropertyFluent(IEnumerable <Tuple <int, char> > rParam) { return(Spec .For(Any.Value(rParam), r => { var original = r.ToList(); var actual = RLE.RunLengthEnc(RLE.RunLengthDec(original)); return actual.SequenceEqual(original); }) .Build()); }
public void ToNumListPropertyBasedTest2() { Spec .For(GenNumRangeOrderedAndNonOverlapping, tuples => { var inputString = FormatInputStringFromTuples(tuples); var expected = ExpandTuples(tuples); var actual = inputString.ToNumList(); return(actual.SequenceEqual(expected)); }) .Check(Configuration); }
public void And() { // Arrange Drink coldWhiskey = Drink.ColdWhiskey(); Drink appleJuice = Drink.AppleJuice(); ISpecification <Drink> whiskeySpec = Spec.For <Drink>(d => d.Name.ToLower() == "whiskey"); ISpecification <Drink> coldSpec = Spec.For <Drink>(d => d.With.Any(a => a.ToLower() == "ice")); // Act var coldWhiskeySpec = whiskeySpec.And(coldSpec); // Assert coldWhiskeySpec.IsSatisfiedBy(coldWhiskey).Should().BeTrue(); coldWhiskeySpec.IsSatisfiedBy(appleJuice).Should().BeFalse(); }
public void AppleOrOrangeJuice() { // Arrange Drink blackberryJuice = Drink.BlackberryJuice(); Drink appleJuice = Drink.AppleJuice(); Drink orangeJuice = Drink.OrangeJuice(); ISpecification <Drink> juiceSpec = Spec.For <Drink>(d => d.With.Any(w => w.ToLower().Contains("juice"))); ISpecification <Drink> appleSpec = Spec.For <Drink>(d => d.With.Any(w => w.ToLower().Contains("apple"))); ISpecification <Drink> orangeSpec = Spec.For <Drink>(d => d.With.Any(w => w.ToLower().Contains("orange"))); // Act var appleOrOrangeJuiceSpec = juiceSpec.And(appleSpec.Or(orangeSpec)); // Assert appleOrOrangeJuiceSpec.IsSatisfiedBy(appleJuice).Should().BeTrue(); appleOrOrangeJuiceSpec.IsSatisfiedBy(orangeJuice).Should().BeTrue(); appleOrOrangeJuiceSpec.IsSatisfiedBy(blackberryJuice).Should().BeFalse(); }
public Property InterleavePropertyFluent(IList <int> xsParam, IList <int> ysParam) { return(Spec .For(Any.Value(xsParam), Any.Value(ysParam), (xs, ys) => { var res = Interleaving.Interleave(xs, ys); return xs.Count + ys.Count == res.Count(); }).Label("length") .And((xs, ys) => { var res = Interleaving.Interleave(xs, ys); var idxs = Enumerable.Range(0, Math.Min(xs.Count, ys.Count)).ToList(); return xs.SequenceEqual(idxs.Select(idx => res[2 * idx]).Concat(res.Skip(2 * ys.Count))); }, "zip xs") .And((xs, ys) => { var res = Interleaving.Interleave(xs, ys); var idxs = Enumerable.Range(0, Math.Min(xs.Count, ys.Count)).ToList(); return ys.SequenceEqual(idxs.Select(idx => res[2 * idx + 1]).Concat(res.Skip(2 * xs.Count))); }, "zip ys") .Build()); }
public void InterleaveTestFluent() { Spec .For(Any.OfType <IList <int> >(), Any.OfType <IList <int> >(), (xs, ys) => { var res = Interleaving.Interleave(xs, ys); return(xs.Count + ys.Count == res.Count()); }).Label("length") .And((xs, ys) => { var res = Interleaving.Interleave(xs, ys); var idxs = Enumerable.Range(0, Math.Min(xs.Count, ys.Count)).ToList(); return(xs.SequenceEqual(idxs.Select(idx => res[2 * idx]).Concat(res.Skip(2 * ys.Count)))); }, "zip xs") .And((xs, ys) => { var res = Interleaving.Interleave(xs, ys); var idxs = Enumerable.Range(0, Math.Min(xs.Count, ys.Count)).ToList(); return(ys.SequenceEqual(idxs.Select(idx => res[2 * idx + 1]).Concat(res.Skip(2 * xs.Count)))); }, "zip ys") .Check(Configuration); }
internal static TodoSpec ById(Guid id) { return(Spec.For <Todo>(t => t.Id == id)); }
public static TodoSpec ByStatus(TodoStatus status) { return(Spec.For <Todo>(t => t.Status == status)); }
public ProductValidator() { _specName = Spec.For <Product>(x => !String.IsNullOrEmpty(x.Name)); _specDate = Spec.For <Product>(x => x.EffectiveDate > DateTime.MinValue); }
public Property PropertyFluent() { var g = Any.IntBetween(-2, 5); return(Spec.For(g, n => n >= -2 && n <= 5).Build()); }
public void TestFluent() { var g = Any.IntBetween(-2, 5); Spec.For(g, n => n >= -2 && n <= 5).Check(Configuration); }
public static TodoSpec Due(DateTime when) { return(Spec.For <Todo>(t => t.Due == when)); }