public void CheckIteratorCompositionOfCompositions()
        {
            IExecute<int> identity = new SingleFunction<int>(x => x);
            IExecute<int> linearfunction = new SingleFunction<int>(x => x + 2);
            IExecute<int> quadraticfunction = new SingleFunction<int>(x => 2 * x * x);

            var comp1 = new Composition<int>(linearfunction, quadraticfunction);
            var comp2 = new Composition<int>(quadraticfunction, linearfunction);

            var compOfComps = new Composition<int>(comp1, comp2);

            var functionList = new[] { identity, linearfunction, quadraticfunction, compOfComps };

            var comp = new Composition<int>(functionList);

            var tab0 = new[] { 0, 2, 0, 2, 0, 0, 2 };
            var tab1 = new[] { 1, 3, 2, 3, 2, 2, 3 };
            var tab2 = new[] { 2, 4, 8, 4, 8, 8, 4 };
            var i = 0;

            Assert.AreEqual(7, comp.Count());

            foreach (var f in comp)
            {
                Assert.AreEqual(tab0[i], f.Execute(0));
                Assert.AreEqual(tab1[i], f.Execute(1));
                Assert.AreEqual(tab2[i], f.Execute(2));
                i++;
            }
        }
Пример #2
0
        public void IndexerTest()
        {
            var c1 = new Composition();
            c1[1] = 0.9;
            c1[11] = 0.1;

            var c2 = new Composition();
            c2[2] = 1.0;

            Assert.AreEqual(2, c1.Count());
            Assert.AreEqual(1, c2.Count());

            Assert.AreEqual(0.1, c1[11]);
        }