Example #1
0
        private static Gen <string[]> AlphaStringSetGen(int length, int count)
        {
            var regex = $"[a-z]{{{length}}}";
            var xeger = new Xeger(regex);

            return(Gen.ArrayOf(count, Arb.Generate <bool>().Select(_ => xeger.Generate())));
        }
Example #2
0
        static Gen <string> Domain()
        {
            var characters = Gen.Elements("abcdefghijklmnopqrstuvwxyz0123456789".ToCharArray());

            return(Gen.Choose(1, 63)
                   .SelectMany(i => Gen.ArrayOf(i, characters))
                   .Select(a => new string(a)));
        }
Example #3
0
            public static Arbitrary <int[]> A()
            {
                var len    = Gen.Choose(1, 100);
                var aValue = Gen.Choose(1, 1000);
                var a      = len.SelectMany(l => Gen.ArrayOf(l, aValue));

                return(a.ToArbitrary());
            }
Example #4
0
        public void polygon_area_should_be_positive()
        {
            var size = Gen.Resize(100, Arb.Default.Int16().Generator);

            var points = Gen.Two(Arb.Default.Float32().Generator).Select(tuple => new Point(tuple.Item1, tuple.Item2));

            var args = size.SelectMany(s => Gen.ArrayOf(s, points)).Select(ps => new Polygon(ps)).ToArbitrary();

            Prop.ForAll(args, polygon => Area.Calculate(polygon).AssertIsPositiveOrError()).QuickCheckThrowOnFailure();
        }
Example #5
0
 private Gen <PersonEntity> GeneratePersons()
 {
     return
         (from nationalId in Gen.ArrayOf(10, Gen.Choose(0, 9))
          from country in Gen.Elements("Sweden", "Denmark", "Norway")
          from name in Arb.Generate <string>()
          from eyeColor in Gen.Elements("Blue", "Green", "Brown")
          select new PersonEntity {
         RowKey = DigitsToString(nationalId), PartitionKey = country, Name = name, EyeColor = eyeColor
     });
 }
Example #6
0
 private Arbitrary <string> Dna() =>
 Gen.Sized(n =>
           Gen.ArrayOf(n, Gen.OneOf(new List <Gen <string> > {
     Gen.Constant("A"),
     Gen.Constant("C"),
     Gen.Constant("G"),
     Gen.Constant("T")
 }))
           .Select(r => string.Join("", r)))
 .Select(r => r ?? "")
 .ToArbitrary();
Example #7
0
 public static Arbitrary <AesKey> AesKey()
 {
     using (Aes aes = Aes.Create())
     {
         const int BITS_PER_BYTE = 8;
         int[]     keySizes      = new int[] {
             (aes.LegalKeySizes[0].MinSize / BITS_PER_BYTE),
             (aes.LegalKeySizes[0].MaxSize / BITS_PER_BYTE)
         };
         return((from len in Gen.Elements <int>(keySizes)
                 from ba in Gen.ArrayOf <byte>(len, Arb.Generate <byte>())
                 select new AesKey(ba)
                 ).ToArbitrary());
     }
 }
Example #8
0
        public Property CleanMessageHasProperLength()
        {
            var msgSetGen = LengthGen.SelectMany(len => CountGen, (len, count) => new { len, count })
                            .SelectMany(
                x =>
                Gen.ArrayOf(x.count, Gen.ArrayOf(x.len, Arb.Generate <char>()).Select(msg => new string(msg)))
                .Select(messages => new { x.len, messages }));

            // alternative way to write it
            var msgSetGen2 = from len in LengthGen
                             from count in CountGen
                             from messages in
                             Gen.ArrayOf(count, Gen.ArrayOf(len, Arb.Generate <char>()).Select(msg => new string(msg)))
                             select new { len, messages };

            var cleaner  = new RepeatedMessageCleaner(RepeatedMessageCleaner.Protocol.Simple);
            var modified = new RepeatedMessageCleaner(RepeatedMessageCleaner.Protocol.Modified);

            return(Prop.ForAll(msgSetGen.ToArbitrary(),
                               msgset =>
                               cleaner.CleanMessage(msgset.messages).Length == msgset.len &&
                               modified.CleanMessage(msgset.messages).Length == msgset.len));
        }
Example #9
0
        public static Arbitrary <IDictionary <string, string> > Model()
        {
            var tagOpeningChars =
                "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            var tagOtherChars =
                tagOpeningChars + "0123456789";

            Func <char, char[], string> merge = (first, rest) =>
            {
                var target = new char[rest.Length + 1];
                target[0] = first;
                Array.Copy(rest, 0, target, 1, rest.Length);
                return(new string(target));
            };

            var tagGen =
                from opening in
                Gen.Elements(tagOpeningChars.ToCharArray())
                from rest in
                Gen.ArrayOf(Gen.Elements(tagOtherChars.ToCharArray()))
                from replacement in
                Arb.Generate <NonNull <string> >()
                select
                new KeyValuePair <string, string>(merge(opening, rest),
                                                  replacement.Get);

            var modelGen =
                Gen.NonEmptyListOf(tagGen)
                .Select(tags =>
                        new Dictionary <string, string>(
                            tags.GroupBy(kv => kv.Key)
                            .Select(g => g.First()))
                        as IDictionary <string, string>);

            return(Arb.From(modelGen));
        }
 public static Arbitrary <char[]> NotEmptyStringWithAllowedCharacters()
 {
     return(Gen.ArrayOf(RandomNumber(5, 100).Sample(20, 1).First(), Gen.Elements($"{_alphabet}{_alphabet.ToUpper()}{_numbers}{_allowedCharacters}".ToCharArray())).ToArbitrary());
 }
Example #11
0
 private static Gen <OutputDescriptor> MultisigOutputDescriptorGen(int maxN, Network?network = null) =>
 from n in Gen.Choose(2, maxN)
 from m in Gen.Choose(2, n).Select(i => (uint)i)
 from pkProviders in Gen.ArrayOf(n, PubKeyProviderGen(network))
 from isSorted in Arb.Generate <bool>()
 select OutputDescriptor.NewMulti(m, pkProviders, isSorted);
Example #12
0
 public static Gen <string> Identifier() =>
 from count in Gen.Choose(5, 10)
 from chars in Gen.ArrayOf(count, Gen.Elements <char>("abcdefghijklmnopqrstuvwxyz"))
 select new string(chars);
 public static Arbitrary <char[]> Alphanumeric()
 {
     return(Gen.ArrayOf(RandomNumber(5, 100).Sample(20, 1).First(), Gen.Elements($"{_alphabet}{_alphabet.ToUpper()}{_numbers}".ToCharArray())).ToArbitrary());
 }
Example #14
0
 public static Gen <string> String() => Gen.ArrayOf(Character()).Select(array => new string(array));
Example #15
0
            static Gen <string> ConfigStrings()
            {
                var z =
                    from size in Gen.Choose(1, 50)
                    let letters                                                         = Arb.toGen(Arb.Default.Char().Filter(c => (c >= 'A' && c <= 'z') || c == '.'))
                                                        let len                         = Gen.Choose(1, 200)
                                                                              let words = len
                                                                                          .SelectMany(i => Gen.ArrayOf(i, letters)
                                                                                                      .SelectMany(ls => Arb.Generate <bool>()
                                                                                                                  .Select(b => ls.Contains('.') || b ? "\"" + new string(ls) + "\"" : new string(ls))))
                                                                                          from wx in Gen.ArrayOf(size, words).Select(ww => String.Join(".", ww))
                                                                                          select wx;

                return(z);
            }
Example #16
0
 public static Gen <SupportedEvent[]> GenEvents()
 {
     return(Gen.ArrayOf(Gen.Elements(AllValidEvent)));
 }
Example #17
0
 public static Gen <Operation <SpecCounter, CounterModel> > ScheduledInterleavedSetGen()
 {
     return
         (Gen.ArrayOf(Arb.Default.Int32().Generator)
          .Select(incs => (Operation <SpecCounter, CounterModel>) new ScheduledSetInterleaved(incs)));
 }
 public static Gen <Operation <ITcpServerSocketModel, ITcpServerSocketModel> > Generator()
 {
     return
         (Gen.ArrayOf(Arb.Default.Int32().Generator)
          .Select(x => (Operation <ITcpServerSocketModel, ITcpServerSocketModel>) new ClientWrite(x)));
 }
Example #19
0
 public static Gen <Operation <SpecCounter, CounterModel> > IncrementGen()
 {
     return
         (Gen.ArrayOf(Arb.Default.Int32().Generator)
          .Select(incs => (Operation <SpecCounter, CounterModel>) new Increment(incs)));
 }
 internal static Gen <BlockMap> BlockMapsGen() => Gen.Sized(s => Gen.Map <bool[], BlockMap>((Converter <bool[], BlockMap>)ToBlockMap, Gen.Filter((Converter <bool[], bool>)(a => a.Any(b => !b)), Gen.ArrayOf(s, Gen.Elements(true, false)))));