Ejemplo n.º 1
0
        public void CopyConstructor()
        {
            IVariable <int> x = new Variable <int>("x")
            {
                Values = { 1, 2, 3 }
            };
            IVariable <double> y = new Variable <double>("y");
            IFunction          f = new Function {
                Arguments = { x }, Components = { y }
            };

            f.SetValues(new[] { 100.0, 200.0, 300.0 });
            var store = (MemoryFunctionStore)f.Store;

            var copy = new MemoryFunctionStore(store); // copy

            copy.Functions.Count
            .Should().Be.EqualTo(3);

            copy.Functions[0]
            .Should("check f").Be.OfType <Function>();

            copy.Functions[1]
            .Should("check x").Be.OfType <Variable <int> >();

            copy.Functions[2]
            .Should("check y").Be.OfType <Variable <double> >();

            var variables = copy.Functions.OfType <IVariable>();

            variables.ForEach(v => v.Values.Count.Should().Be.EqualTo(0));
        }
Ejemplo n.º 2
0
        public void RemovingAFunctionRemovesFunctionValues()
        {
            MemoryFunctionStore store = new MemoryFunctionStore();
            IFunction           f     = new Function();
            IVariable <double>  x     = new Variable <double>("x");

            store.Functions.Add(f);
            f.Components.Add(x);
            Assert.AreEqual(2, store.Functions.Count);
            f.Components.Clear();
            //store.Functions.Remove(x);
            Assert.AreEqual(1, store.Functions.Count);
        }
Ejemplo n.º 3
0
        public void CopyToStore()
        {
            var function = FunctionHelper.Get1DFunction<double, double>();
            function[1.0d] = 2.0d;
            function[3.0d] = 3.3d;

            var targetStore = new MemoryFunctionStore();
            function.CopyToStore(targetStore);

            var copiedFunction = targetStore.Functions[0];
            Assert.AreEqual(function.Arguments.Count, copiedFunction.Arguments.Count);
            Assert.AreEqual(function.Components.Count, copiedFunction.Components.Count);
            Assert.AreEqual(function.Arguments[0].Values, copiedFunction.Arguments[0].Values);
            Assert.AreEqual(function.Components[0].Values, copiedFunction.Components[0].Values);
        }
Ejemplo n.º 4
0
        public void CopyIndependendFunctionValuesWhenAdded()
        {
            //indep variable
            IVariable x = new Variable <double>();

            var values = new[] { 1.0, 2.0, 3.0 };

            x.Store.SetVariableValues(x, values);

            var store = new MemoryFunctionStore();

            store.Functions.Add(x);

            Assert.AreEqual(3.0, store.GetVariableValues(x)[2]);
            Assert.AreEqual(3, store.GetVariableValues(x).Count);
        }
Ejemplo n.º 5
0
        public void GetIndependentValuesFiltersGeneric()
        {
            IFunctionStore store = new MemoryFunctionStore();

            IVariable <double> x1 = new Variable <double>("x1");

            //add one independent variable
            store.Functions.Add(x1);

            x1.SetValues(new[] { 0.0d, 1.0d, 2.0d });
            Assert.AreEqual(0.0, x1.Values[0]);

            IMultiDimensionalArray <double> filteredValues = store.GetVariableValues <double>(x1, new VariableValueFilter <double>(x1, new[] { 0.0d, 2.0d }));

            Assert.AreEqual(0.0, filteredValues[0]);
            Assert.AreEqual(2.0, filteredValues[1]);
        }
Ejemplo n.º 6
0
        public void CopyToStore()
        {
            var function = FunctionHelper.Get1DFunction <double, double>();

            function[1.0d] = 2.0d;
            function[3.0d] = 3.3d;

            var targetStore = new MemoryFunctionStore();

            function.CopyToStore(targetStore);

            var copiedFunction = targetStore.Functions[0];

            Assert.AreEqual(function.Arguments.Count, copiedFunction.Arguments.Count);
            Assert.AreEqual(function.Components.Count, copiedFunction.Components.Count);
            Assert.AreEqual(function.Arguments[0].Values, copiedFunction.Arguments[0].Values);
            Assert.AreEqual(function.Components[0].Values, copiedFunction.Components[0].Values);
        }
Ejemplo n.º 7
0
 public void CopyComponentWhenAssignedToDifferentStore()
 {
     IFunction func = new Function();
     IVariable y = new Variable<int>("y");
     IVariable x = new Variable<int>("x");
     IVariable h = new Variable<int>("H");
     func.Arguments.Add(x);
     func.Arguments.Add(y);
     func.Components.Add(h);
     h[1, 1] = 1;
     Assert.AreEqual(1, h[1, 1]);
     
     //switch store
     IFunctionStore functionStore = new MemoryFunctionStore();
     functionStore.Functions.Add(func);
     Assert.AreEqual(4,functionStore.Functions.Count);
     Assert.AreEqual(1,func.Components[0][1,1]);
 }
Ejemplo n.º 8
0
        public void CopyDependendFunctionValuesWhenAdded()
        {
            //depended variable
            IVariable y = new Variable <int>("y");
            IVariable x = new Variable <int>("x");

            y.Arguments.Add(x);
            y.SetValues(new[] { 10, 20, 30 }, new VariableValueFilter <int>(x, new[] { 1, 2, 3 }));

            //switch store
            var store = new MemoryFunctionStore();

            store.Functions.Add(y);

            //get values for x and y
            Assert.AreEqual(3, store.GetVariableValues(x).Count);
            Assert.AreEqual(3, store.GetVariableValues(y).Count);

            Assert.AreEqual(30, y[3]);
        }
Ejemplo n.º 9
0
        public void CopyComponentWhenAssignedToDifferentStore()
        {
            IFunction func = new Function();
            IVariable y    = new Variable <int>("y");
            IVariable x    = new Variable <int>("x");
            IVariable h    = new Variable <int>("H");

            func.Arguments.Add(x);
            func.Arguments.Add(y);
            func.Components.Add(h);
            h[1, 1] = 1;
            Assert.AreEqual(1, h[1, 1]);

            //switch store
            IFunctionStore functionStore = new MemoryFunctionStore();

            functionStore.Functions.Add(func);
            Assert.AreEqual(4, functionStore.Functions.Count);
            Assert.AreEqual(1, func.Components[0][1, 1]);
        }
Ejemplo n.º 10
0
        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 });
        }
Ejemplo n.º 11
0
        public void CopyDependendFunctionValuesWhenAdded()
        {
            //depended variable 
            IVariable y = new Variable<int>("y");
            IVariable x = new Variable<int>("x");
            
            y.Arguments.Add(x);
            y.SetValues(new[] { 10, 20, 30 }, new VariableValueFilter<int>(x, new[] { 1, 2, 3 }));

            //switch store
            var store = new MemoryFunctionStore();
            store.Functions.Add(y);

            //get values for x and y
            Assert.AreEqual(3, store.GetVariableValues(x).Count);
            Assert.AreEqual(3, store.GetVariableValues(y).Count);

            Assert.AreEqual(30,y[3]);
        }
Ejemplo n.º 12
0
        public void CopyConstructor()
        {
            IVariable<int> x = new Variable<int>("x") { Values = { 1, 2, 3 } };
            IVariable<double> y = new Variable<double>("y");
            IFunction f = new Function { Arguments = { x }, Components = { y } };
            f.SetValues(new[] { 100.0, 200.0, 300.0 });
            var store = (MemoryFunctionStore)f.Store;

            var copy = new MemoryFunctionStore(store); // copy

            copy.Functions.Count
                .Should().Be.EqualTo(3);

            copy.Functions[0]
                .Should("check f").Be.OfType<Function>();

            copy.Functions[1]
                .Should("check x").Be.OfType<Variable<int>>();

            copy.Functions[2]
                .Should("check y").Be.OfType<Variable<double>>();

            var variables = copy.Functions.OfType<IVariable>();
            
            variables.ForEach(v => v.Values.Count.Should().Be.EqualTo(0));
        }
Ejemplo n.º 13
0
 public void RemovingAFunctionRemovesFunctionValues()
 {
     MemoryFunctionStore store= new MemoryFunctionStore();
     IFunction f = new Function();
     IVariable<double> x = new Variable<double>("x");
     store.Functions.Add(f);
     f.Components.Add(x);
     Assert.AreEqual(2,store.Functions.Count);
     f.Components.Clear();
     //store.Functions.Remove(x);
     Assert.AreEqual(1, store.Functions.Count);
 }
Ejemplo n.º 14
0
        public void GetIndependentValuesFiltersGeneric()
        {
            IFunctionStore store = new MemoryFunctionStore();

            IVariable<double> x1 = new Variable<double>("x1");
            //add one independent variable
            store.Functions.Add(x1);

            x1.SetValues(new[] { 0.0d, 1.0d, 2.0d });
            Assert.AreEqual(0.0, x1.Values[0]);

            IMultiDimensionalArray<double> filteredValues = store.GetVariableValues<double>(x1, new VariableValueFilter<double>(x1, new[] {0.0d, 2.0d}));
            Assert.AreEqual(0.0, filteredValues[0]);
            Assert.AreEqual(2.0, filteredValues[1]);
        }
Ejemplo n.º 15
0
        public void CopyIndependendFunctionValuesWhenAdded()
        {
            //indep variable 
            IVariable x = new Variable<double>();

            var values = new[] { 1.0, 2.0, 3.0 };
            x.Store.SetVariableValues(x, values);

            var store = new MemoryFunctionStore();
            store.Functions.Add(x);

            Assert.AreEqual(3.0, store.GetVariableValues(x)[2]);
            Assert.AreEqual(3, store.GetVariableValues(x).Count);
        }