Exemplo n.º 1
0
        public Property CleanMessageContainsLeastFrequentWhenUsingModifiedProtocol()
        {
            var msgSetGen = LengthGen.SelectMany(len => CountGen, (len, count) => new { len, count })
                            .SelectMany(x => AlphaStringSetGen(x.len, x.count).Select(messages => new { x.len, messages }));
            var cleaner = new RepeatedMessageCleaner(RepeatedMessageCleaner.Protocol.Modified);

            return(Prop.ForAll(msgSetGen.ToArbitrary(),
                               msgset =>
                               cleaner.CleanMessage(msgset.messages)
                               .Select(
                                   (c, i) =>
                                   msgset.messages.Select(msg => msg[i]).GroupBy(ch => ch).Min(g => g.Count()) ==
                                   msgset.messages.Select(msg => msg[i]).Count(ch => ch == c))
                               .All(mostFrequent => mostFrequent)));
        }
Exemplo n.º 2
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));
        }