Пример #1
0
        Permute_OneRowWithTwoItemsOneRowWithSingleItem_WithTwoRowsOfDoubleItems_4RowsWithTwoWithFourItemsAndTwoWithThreeItems
            ()
        {
            List <Dictionary <string, int> > result = GetOneRowWithTwoItemsOneRowWithSingleItemResult();

            Permuter.Permute(result, GetTwoRowsWithDoubleItemsResult());

            Dictionary <string, int>[] expectedResult = new Dictionary <string, int>[]
            {
                CreateResult(new KI("int", 2),
                             new KI("int2", 3),
                             new KI("int4", 9),
                             new KI("int5", 10)),
                CreateResult(new KI("int", 2),
                             new KI("int2", 3),
                             new KI("int4", 12),
                             new KI("int5", 13)),
                CreateResult(new KI("int", 4),
                             new KI("int4", 9),
                             new KI("int5", 10)),
                CreateResult(new KI("int", 4),
                             new KI("int4", 12),
                             new KI("int5", 13))
            };
            AssertResult(expectedResult, result);
        }
Пример #2
0
    public static List Permutations(List x)
    {
        var permuter = new Permuter(x);

        permuter.Permute(x.Length);
        return(permuter.Permutations);
    }
Пример #3
0
        /// <summary>
        /// Returns all permutations of the static property data sources.
        /// </summary>
        public override IEnumerable <object[]> GetData(MethodInfo methodUnderTest)
        {
            //TODO: Only works for immutable arguments.
            // Get arguments from each data source, using MemberDataAttribute.
            object[][][] dataSources = propertyNames_.Select(
                propertyName => new MemberDataAttribute(propertyName)
                .GetData(methodUnderTest)
                .ToArray( )
                ).ToArray( );

            // Permute indices into data sources.
            int parameterCount    = methodUnderTest.GetParameters( ).Length;
            var dataSourceIndices = dataSources.Select(dataSource => Enumerable.Range(0, dataSource.Length));

            foreach (int[] indices in Permuter.Permute(dataSourceIndices))
            {
                object[] buffer      = new object[parameterCount];
                int      bufferIndex = 0;

                // Build arguments buffer from data source at each index.
                for (int i = 0; i < indices.Length; ++i)
                {
                    int      index      = indices[i];
                    object[] dataSource = dataSources[i][index];
                    foreach (object data in dataSource)
                    {
                        buffer[bufferIndex++] = data;
                    }
                }

                yield return(buffer);
            }
        }
Пример #4
0
        public void Permute_SingleItem_WithEmptyList_NoChange()
        {
            List <Dictionary <string, int> > result = GetSingleItemResult();

            Permuter.Permute(result, "int2", new int[] {});
            Asserter.Assert(new DictionaryContentAsserter <string, int>(GetSingleItemResult(), result));
        }
Пример #5
0
        public void Permute_Empty_WithEmptyListOfList_Empty()
        {
            List <Dictionary <string, int> > result = GetEmptyResult();

            Permuter.Permute(result, GetEmptyResult());

            Asserter.Assert(new DictionaryContentAsserter <string, int>(GetEmptyResult(), result));
        }
Пример #6
0
        public void Permute_Empty_WithTwoRowsOfDoubleItems_TwoRowsOfDoubleItems()
        {
            List <Dictionary <string, int> > result = GetEmptyResult();

            Permuter.Permute(result, GetTwoRowsWithDoubleItemsResult());

            Asserter.Assert(new DictionaryContentAsserter <string, int>(GetTwoRowsWithDoubleItemsResult(), result));
        }
Пример #7
0
        public void Permute_SingleRowWithTwoItems_WithEmptyListOfList_NoChange()
        {
            List <Dictionary <string, int> > result = GetSingleRowWithTwoItemsResult();

            Permuter.Permute(result, GetEmptyResult());

            Asserter.Assert(new DictionaryContentAsserter <string, int>(GetSingleRowWithTwoItemsResult(), result));
        }
Пример #8
0
        public void Permute_TwoRowsWithSingleItem_WithEmptyListOfList_NoChange()
        {
            List <Dictionary <string, int> > result = GetTwoRowsWithSingleItemEachResult();

            Permuter.Permute(result, GetEmptyResult());

            Asserter.Assert(new DictionaryContentAsserter <string, int>(GetTwoRowsWithSingleItemEachResult(), result));
        }
Пример #9
0
        public void Permute_Empty_WithSingleItem_SingleItem()
        {
            List <Dictionary <string, int> > result = GetEmptyResult();

            Permuter.Permute(result, "int", 9);

            IDictionary <string, int>[] expectedResult = new IDictionary <string, int>[]
            { CreateResult(new KI("int", 9)) };

            Asserter.Assert(new DictionaryContentAsserter <string, int>(expectedResult, result));
        }
Пример #10
0
        public void MultiMemberDataAttribute_succeeds_for_multiple_data_sources( )
        {
            var method          = IntCharMethod(default(int), default(char));
            var attribute       = new MultiMemberDataAttribute(IntsName, CharsName);
            var rawPropertyData = new[] { ToObjectArray(ints_), ToObjectArray(chars_) };
            var propertyData    = Permuter.Permute(rawPropertyData);

            var attributeData = attribute.GetData(method).ToArray( );

            Assert.Equal(propertyData, attributeData, Comparer);
        }
        private static IEnumerable <object[]> GetDataCore(IEnumerable <IEnumerable <IInstanceCreator> > parameterCreators)
        {
            foreach (var permutation in Permuter.Permute(parameterCreators))
            {
                object[] data = new object[permutation.Length];
                for (int i = 0; i < data.Length; ++i)
                {
                    data[i] = permutation[i].CreateInstance( );
                }

                yield return(data);
            }
        }
Пример #12
0
        public void Permute_SingleItem_WithSingleItem_SingleRowWithBothItems()
        {
            List <Dictionary <string, int> > result = GetSingleItemResult();

            Permuter.Permute(result, "value", 9);

            IDictionary <string, int>[] expectedResult = new Dictionary <string, int>[]
            {
                CreateResult(new KI("int", 2),
                             new KI("value", 9))
            };
            Asserter.Assert(new DictionaryContentAsserter <string, int>(expectedResult, result));
        }
Пример #13
0
        public void Permute_Empty_WithTwoItems_TwoRowsOfSingleItem()
        {
            List <Dictionary <string, int> > result = GetEmptyResult();

            Permuter.Permute(result, "int", new int[] { 9, 12 });

            Dictionary <string, int>[] expectedResult = new Dictionary <string, int>[]
            {
                CreateResult(new KI("int", 9)),
                CreateResult(new KI("int", 12))
            };
            AssertResult(expectedResult, result);
        }
Пример #14
0
        private static object[][] GetFlattenedPermutations(object[][][] rawData)
        {
            var permutations          = Permuter.Permute(rawData);
            var flattenedPermutations = new object[permutations.Length][];

            for (int i = 0; i < permutations.Length; ++i)
            {
                object[][] permutation = permutations[i];
                object[]   flattened   = permutation.SelectMany(data => data).ToArray( );
                flattenedPermutations[i] = flattened;
            }

            return(flattenedPermutations);
        }
Пример #15
0
        public void Permute_SingleItem_WithTwoRowsOfSingleItems_TwoRowsWithSingleItemAndEachOfItems()
        {
            List <Dictionary <string, int> > result = GetSingleItemResult();

            Permuter.Permute(result, GetTwoRowsWithSingleItemEachAtInt5Result());

            Dictionary <string, int>[] expectedResult = new Dictionary <string, int>[]
            {
                CreateResult(new KI("int", 2),
                             new KI("int5", 9)),
                CreateResult(new KI("int", 2),
                             new KI("int5", 12))
            };
            AssertResult(expectedResult, result);
        }
Пример #16
0
        public void Permute_TwoRowsWithSingleItem_WithSingleItem_TwoRowsWithTwoItems()
        {
            List <Dictionary <string, int> > result = GetTwoRowsWithSingleItemEachResult();

            Permuter.Permute(result, "int2", 9);

            IDictionary <string, int>[] expectedResult = new Dictionary <string, int>[]
            {
                CreateResult(new KI("int", 2),
                             new KI("int2", 9)),
                CreateResult(new KI("int", 4),
                             new KI("int2", 9))
            };

            AssertResult(expectedResult, result);
        }
Пример #17
0
        public void Permute_SingleRowWithTwoItems_WithTwoItems_TwoRowsWithTheTwoItemsAndEachOfItems()
        {
            List <Dictionary <string, int> > result = GetSingleRowWithTwoItemsResult();

            Permuter.Permute(result, "int3", new int[] { 9, 12 });

            Dictionary <string, int>[] expectedResult = new Dictionary <string, int>[]
            {
                CreateResult(new KI("int", 2),
                             new KI("int2", 4),
                             new KI("int3", 9)),
                CreateResult(new KI("int", 2),
                             new KI("int2", 4),
                             new KI("int3", 12))
            };

            AssertResult(expectedResult, result);
        }
Пример #18
0
        Permute_OneRowWithTwoItemsOneRowWithSingleItem_WithTwoItems_4RowsWithTwoWithThreeItemsAndTwoWithTwoItems
            ()
        {
            List <Dictionary <string, int> > result = GetOneRowWithTwoItemsOneRowWithSingleItemResult();

            Permuter.Permute(result, "int3", new int[] { 9, 12 });

            Dictionary <string, int>[] expectedResult = new Dictionary <string, int>[]
            {
                CreateResult(new KI("int", 2),
                             new KI("int2", 3),
                             new KI("int3", 9)),
                CreateResult(new KI("int", 2),
                             new KI("int2", 3),
                             new KI("int3", 12)),
                CreateResult(new KI("int", 4),
                             new KI("int3", 9)),
                CreateResult(new KI("int", 4),
                             new KI("int3", 12))
            };
            AssertResult(expectedResult, result);
        }
Пример #19
0
        public void Permute_TwoRowsWithSingleItem_WithTwoRowsOfDoubleItems_4RowsWithThreeItems()
        {
            List <Dictionary <string, int> > result = GetTwoRowsWithSingleItemEachResult();

            Permuter.Permute(result, GetTwoRowsWithDoubleItemsResult());

            Dictionary <string, int>[] expectedResult = new Dictionary <string, int>[]
            {
                CreateResult(new KI("int", 2),
                             new KI("int4", 9),
                             new KI("int5", 10)),
                CreateResult(new KI("int", 2),
                             new KI("int4", 12),
                             new KI("int5", 13)),
                CreateResult(new KI("int", 4),
                             new KI("int4", 9),
                             new KI("int5", 10)),
                CreateResult(new KI("int", 4),
                             new KI("int4", 12),
                             new KI("int5", 13))
            };
            AssertResult(expectedResult, result);
        }
Пример #20
0
 public void Permute_NullResultSingleItem_Throws()
 {
     Assert.Throws <ArgumentNullException>(() => Permuter.Permute(null, "", 9));
 }
Пример #21
0
        public void Permute_NullSingleItem_Succeeds()
        {
            var result = new List <Dictionary <string, object> >();

            Permuter.Permute(result, "", (object)null);
        }
Пример #22
0
        public void Permute_NullListOfItems_Throws()
        {
            List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();

            Assert.Throws <ArgumentNullException>(() => Permuter.Permute(result, null));
        }
Пример #23
0
 public void Permute_NullResultListOfListOfItems_Throws()
 {
     Assert.Throws <ArgumentNullException>(() => Permuter.Permute(null, "", new int[][] { new int[] { 9 } }));
 }
Пример #24
0
 public void Permute_NullResultListResults_Throws()
 {
     Assert.Throws <ArgumentNullException>(() => Permuter.Permute(null, GetSingleItemResult()));
 }