当前位置: 首页>>代码示例>>C#>>正文


C# Function.Clone方法代码示例

本文整理汇总了C#中System.Function.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Function.Clone方法的具体用法?C# Function.Clone怎么用?C# Function.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Function的用法示例。


在下文中一共展示了Function.Clone方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CloneShouldBeFast

        public void CloneShouldBeFast()
        {
            var f = new Function();
            IVariable<double> component = new Variable<double>();
            IVariable<double> x = new Variable<double>();
            IVariable<double> y = new Variable<double>();
            f.Components.Add(component);
            f.Arguments.Add(x);
            f.Arguments.Add(y);

            x.SetValues(new[] { 0.1, 0.2, 1, 2, 3, 4, 5, 6, 7 });
            y.SetValues(new[] { 0.1, 0.2, 1, 2, 3, 4, 5, 6, 7 });
            component.SetValues(new[] { 1.0 });

            var t = DateTime.Now; // measure time
            for (int i = 0; i < 1000; i++)
            {
                var f2 = f.Clone();
            }
            var cloneDt = DateTime.Now.Subtract(t).TotalMilliseconds;
            log.DebugFormat("Cloned 2d function 10000 times in {0} ms", cloneDt);
            Assert.Less(cloneDt, 700);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:23,代码来源:FunctionTest.cs

示例2: ClonedArgumentShouldNotChangeTheValueOfOriginalArgument

        public void ClonedArgumentShouldNotChangeTheValueOfOriginalArgument()
        {
            var x = new Variable<int>("x");
            var y = new Variable<int>("y");
            var component = new Variable<int>("f");
            var f = new Function
                        {
                            Arguments = { x, y },
                            Components = { component }
                        };

            f[1, 10] = 100;
            f[2, 20] = 200;

            var clone = (IFunction)f.Clone();

            f[1, 10] = 199;
            f[2, 20] = 299;

            Assert.AreNotEqual(199, clone[1, 10]);
            Assert.AreNotEqual(299, clone[2, 20]);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:22,代码来源:FunctionTest.cs

示例3: CloneWithTargetStore

        public void CloneWithTargetStore()
        {
            var x = new Variable<int>("x");
            var y = new Variable<int>("y");

            var f = new Variable<int>("f");
            
            var function = new Function
                               {
                                   Arguments = { x, y },
                                   Components = { f }
                               };

            f[1, 10] = 100;
            f[2, 20] = 200;

            var targetStore = new MemoryFunctionStore();
            targetStore = (MemoryFunctionStore) f.Store;

            var clonedFunction = (IFunction)function.Clone();//(targetStore);

            // assserts
            //clonedFunction.Store
            //    .Should().Be.EqualTo(targetStore);

            targetStore.Functions.Count
                .Should("function in the new store should be: function, f, x, y").Be.EqualTo(4);

            clonedFunction.Components.Count
                .Should("1 component: f").Be.EqualTo(1);
            clonedFunction.Arguments.Count
                .Should("2 arguments: x, y").Be.EqualTo(2);
            
            var clonedX = (IVariable<int>)clonedFunction.Arguments[0];
            var clonedY = (IVariable<int>)clonedFunction.Arguments[1];
            var clonedF = (IVariable<int>)clonedFunction.Components[0];

            clonedX.Values
                .Should("values of cloned x").Have.SameSequenceAs(new[] { 1, 2 });
            
            clonedY.Values
                .Should("values of cloned y").Have.SameSequenceAs(new[] { 10, 20 });
            
            clonedF.Values
                .Should("values of cloned f component").Have.SameSequenceAs(new[] { 100, 0, 0, 200 });
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:46,代码来源:FunctionTest.cs

示例4: CloneFuntionWithTwoVariablesWhereTheClonedVariablesShouldHaveSameStore

        public void CloneFuntionWithTwoVariablesWhereTheClonedVariablesShouldHaveSameStore()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> x2 = new Variable<double>("x2");
            IVariable<double> y = new Variable<double>("y");

            IFunction f = new Function
                              {
                                  Arguments = { x,x2 },
                                  Components = { y }
                              };

            var clone = (IFunction)f.Clone();

            Assert.AreEqual(4, f.Store.Functions.Count);
            Assert.AreEqual(4, clone.Store.Functions.Count);
            Assert.AreEqual(4, clone.Arguments[0].Store.Functions.Count);

            Assert.AreNotSame(f.Store,clone.Store);
            Assert.AreSame(clone.Arguments[0].Store, clone.Components[0].Store);
            Assert.AreSame(clone.Arguments[0].Store, clone.Arguments[1].Store);

        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:23,代码来源:FunctionTest.cs

示例5: CloneWith2Arguments

        public void CloneWith2Arguments()
        {
            var x = new Variable<int>("x");
            var y = new Variable<int>("y");
            var component = new Variable<int>("f");
            var f = new Function
                        {
                            Arguments = {x, y},
                            Components = {component}
                        };

            f[1, 10] = 100;
            f[2, 20] = 200;

            var clone = (IFunction) f.Clone();

            Assert.AreEqual(f.Name, clone.Name);
            Assert.AreEqual(f.Arguments.Count, clone.Arguments.Count);
            Assert.AreEqual(f.Components.Count, clone.Components.Count);

            var clonedX = (IVariable<int>) clone.Arguments[0];
            var clonedY = (IVariable<int>) clone.Arguments[1];

            Assert.AreEqual(x.Values.Count, clonedX.Values.Count);
            Assert.AreEqual(y.Values.Count, clonedY.Values.Count);
            Assert.AreEqual(component.Values.Count, component.Values.Count);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:27,代码来源:FunctionTest.cs

示例6: Clone

        public void Clone()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y");

            IFunction f = new Function { Arguments = {x}, Components = {y} };

            f[10.0] = 100.0;
            f[20.0] = 200.0;
            f[30.0] = 300.0;

            var clone = (IFunction) f.Clone();

            Assert.AreEqual(f.Name, clone.Name);
            Assert.AreEqual(f.Arguments.Count, clone.Arguments.Count);
            Assert.AreEqual(f.Components.Count, clone.Components.Count);

            var clonedValues = clone.GetValues();
            var expectedValues = f.GetValues();
            Assert.AreEqual(expectedValues, clonedValues, "values must be cloned");
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:21,代码来源:FunctionTest.cs

示例7: CloneFunctionNotCallGetSetValues

        public void CloneFunctionNotCallGetSetValues()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y");

            IFunction f = new Function { Arguments = { x }, Components = { y } };

            var fileBasedStore = mocks.Stub<IMockFileBasedFunctionStore>();
            fileBasedStore.Functions = new EventedList<IFunction> { f, x, y };

            using (mocks.Record())
            {
                fileBasedStore.Expect(s => s.Clone()).Return(fileBasedStore); // assert, clone should be called

                fileBasedStore.FunctionValuesChanged += null;
                LastCall.Constraints(Is.NotNull()).Repeat.Any();

                fileBasedStore.FunctionValuesChanging += null;
                LastCall.Constraints(Is.NotNull()).Repeat.Any();
            }

            using (mocks.Playback())
            {
                f.Store = fileBasedStore;
                f.Clone();
            }
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:27,代码来源:FunctionTest.cs

示例8: InsertAtForClonedFunction

        public void InsertAtForClonedFunction()
        {
            var x = new Variable<int>("x");
            var y = new Variable<int>("y");

            var f = new Function { Arguments = { x }, Components = { y } };

            f[1] = 1;
            f[5] = 5;
            f[10] = 10;
            f[15] = 15;

            var clone = (IFunction) f.Clone();
            clone.Arguments[0].Values.InsertAt(0,4);

            //clone.Arguments[0].Values.InsertAt(0, 4);
            Assert.AreEqual(5,clone.Components[0].Values.Count);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:18,代码来源:FunctionTest.cs

示例9: CloneWithoutValues

        public void CloneWithoutValues()
        {
            var x = new Variable<int>("x") { Values = { 1, 2, 3 } };
            var y = new Variable<double>("y") { Values = { 1, 2, 3 } };
            var f = new Function("f") { Arguments = { x }, Components = { y } };
            
            var clone = (IFunction) f.Clone(false);

            Assert.AreEqual(1, clone.Arguments.Count);
            Assert.AreEqual(1, clone.Components.Count);
            Assert.IsTrue(clone is Function);
            Assert.IsTrue(clone.Arguments[0] is IVariable<int>);
            Assert.IsTrue(clone.Components[0] is IVariable<double>);

            var store = clone.Store;
            Assert.AreEqual(store, clone.Arguments[0].Store);
            Assert.AreEqual(store, clone.Components[0].Store);
            
            Assert.AreEqual(0, clone.Arguments[0].Values.Count);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:20,代码来源:FunctionTest.cs

示例10: CloneTwoComponentsFunctionAndAddValues

        public void CloneTwoComponentsFunctionAndAddValues()
        {
            IVariable x = new Variable<double>("x");
            IVariable l = new Variable<double>("left");
            IVariable r = new Variable<double>("right");

            IFunction f = new Function();
            f.Arguments.Add(x);
            f.Components.Add(l);
            f.Components.Add(r);

            f[0.0] = new[] {10.0,3.0 };
            f[1.0] = new[] { 20.0, 6.0 };

            var clone = (IFunction)f.Clone();

            clone[2.0] = new[] { 30.0, 9.0 };

            Assert.AreEqual(3,clone.Arguments[0].Values.Count);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:20,代码来源:FunctionTest.cs

示例11: CloneShouldRetainDefaultValueBehaviour

        public void CloneShouldRetainDefaultValueBehaviour()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y") {DefaultValue = 1.23};

            IFunction f = new Function { Arguments = { x }, Components = { y } };
            var clone = (IFunction) f.Clone();

            Assert.AreEqual(1.23, (double)f.Components[0].DefaultValue, 1.0e-6);
            Assert.AreEqual(1.23, (double)f.Components[0].Values.DefaultValue, 1.0e-6);

            Assert.AreEqual(1.23, (double)clone.Components[0].DefaultValue, 1.0e-6);
            Assert.AreEqual(1.23, (double)clone.Components[0].Values.DefaultValue, 1.0e-6);

            f.Arguments[0].AddValues(new[] {100.0});
            Assert.AreEqual(1.23, (double)f[100.0], 1.0e-6);

            clone.Arguments[0].AddValues(new[] {100.0});
            // next line fails if clone.Components[0].Values.DefaultValue is incorrect
            Assert.AreEqual(1.23, (double)clone[100.0], 1.0e-6);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:21,代码来源:FunctionTest.cs

示例12: CloneShouldBeFast

        public void CloneShouldBeFast()
        {
            var f = new Function { Name = "f" };
            IVariable<double> component = new Variable<double> { Name = "component" };
            IVariable<double> x = new Variable<double> { Name = "x" };
            IVariable<double> y = new Variable<double> { Name = "y"};
            f.Components.Add(component);
            f.Arguments.Add(x);
            f.Arguments.Add(y);

            x.SetValues(new[] { 0.1, 0.2, 1, 2, 3, 4, 5, 6, 7 });
            y.SetValues(new[] { 0.1, 0.2, 1, 2, 3, 4, 5, 6, 7 });
            component.SetValues(new[] { 1.0 });

            Action action = delegate
                                {
                                    for (int i = 0; i < 1000; i++)
                                    {
                                        var f2 = f.Clone();
                                    }
                                };

            TestHelper.AssertIsFasterThan(840, action);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:24,代码来源:FunctionTest.cs


注:本文中的System.Function.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。