Example #1
0
        [Category(TestCategory.Jira)] //TOOLS-4934
        public void EventBubbleCorerctlyForFunctionWithReducedArgument()
        {
            IFunction function = new Function
                                     {
                                         Arguments = {new Variable<int>("x1"), new Variable<int>("x2")},
                                         Components = {new Variable<int>("f")}
                                     };

            function[0, 1] = new[] {1};
            function[0, 2] = new[] {2};
            function[1, 1] = new[] {3};
            function[1, 2] = new[] {4};

            var arg1 = function.Arguments[0];

            var filteredFunction = function.Filter(new VariableValueFilter<int>(arg1, 0), new VariableReduceFilter(arg1));
            
            int called = 0;

            filteredFunction.ValuesChanged += (s, e) => called++;

            function[0, 2] = 3; //set value

            Assert.AreEqual(1, called);
        }
Example #2
0
        public void FilterFunction()
        {
            IVariable<double> x = new Variable<double>("x");
            IVariable<double> y = new Variable<double>("y");
            IVariable<double> fx = new Variable<double>("fx");
            IVariable<double> fy = new Variable<double>("fy");

            IFunction f = new Function();
            f.Arguments.Add(x);
            f.Arguments.Add(y);
            f.Components.Add(fx);
            f.Components.Add(fy);

            x.SetValues(new[] { 1.0, 2.0, 3.0 });
            y.SetValues(new[] { 10.0, 20.0 });

            f.Components[0].Values[1, 1] = 100.0;
            f.Components[1].Values[1, 1] = 200.0;

            // fx       10.0  20.0 
            //          ------------
            //    1.0  | 0.0    0.0
            //    2.0  | 0.0  100.0 
            //    3.0  | 0.0    0.0
            //
            // fy       10.0  20.0 
            //          ------------
            //    1.0  | 0.0    0.0
            //    2.0  | 0.0  200.0 
            //    3.0  | 0.0    0.0

            var filteredFunction = f.Filter(x.CreateValueFilter(2.0), y.CreateValueFilter(20.0));

            Assert.AreEqual(2, filteredFunction.Components.Count);
            Assert.AreEqual(2, filteredFunction.Arguments.Count);

            Assert.AreEqual(1, filteredFunction.Arguments[0].Values.Count);
            Assert.AreEqual(1, filteredFunction.Arguments[1].Values.Count);
            Assert.AreEqual(1, filteredFunction.Components[0].Values.Count);
            Assert.AreEqual(1, filteredFunction.Components[1].Values.Count);

            Assert.AreEqual(100.0, filteredFunction.Components[0].Values[0]);
            Assert.AreEqual(200.0, filteredFunction.Components[1].Values[0]);
        }
        public void BindToFilteredFuntion()
        {
            //setup a 2D function and fix one dimension
            IFunction function = new Function();
            IVariable<int> x = new Variable<int>();

            function.Arguments.Add(x);
            function.Arguments.Add(new Variable<int>("Y"));
            function.Components.Add(new Variable<int>());

            function[0, 0] = 2;
            function[0, 1] = 3;
            function[1, 0] = 1;
            function[1, 1] = 4;

            IFunction filteredFunction = function.Filter(new VariableValueFilter<int>(x, 0));

            ILineChartSeries lineChartSeries = ChartSeriesFactory.CreateLineSeries();
            var variable = filteredFunction.Arguments[1];
            var component = filteredFunction.Components[0]; 
            
            lineChartSeries.XValuesDataMember = variable.DisplayName;
            lineChartSeries.YValuesDataMember = component.DisplayName;

            var functionBindingList = new FunctionBindingList(filteredFunction);
            lineChartSeries.DataSource = functionBindingList;
            while (functionBindingList.IsProcessing)
            {
                Application.DoEvents();
            }

            Assert.AreEqual(2, lineChartSeries.XValues.Count);
            Assert.AreEqual(2, lineChartSeries.YValues.Count);
            Assert.AreEqual(0.0, lineChartSeries.XValues[0]);
            Assert.AreEqual(1.0, lineChartSeries.XValues[1]);
            Assert.AreEqual(2.0, lineChartSeries.YValues[0]);
            Assert.AreEqual(3.0, lineChartSeries.YValues[1]);
        }
Example #4
0
        public void GetValuesOfFilteredFunction()
        {
            IFunction function = new Function();
            function.Components.Add(new Variable<int>());
            function.Arguments.Add(new Variable<int>());
            function[0] = 1;
            function[1] = 2;
            function[2] = 3;


            IFunction filtered =
                function.Filter(new VariableValueFilter<int>(function.Arguments[0], new[] {0, 1}));

            Assert.AreEqual(1, filtered[0]);
        }
Example #5
0
        public void FilterUsingComponent()
        {
            IFunction f = new Function();
            IVariable c1 = new Variable<int>("c1");
            IVariable c2 = new Variable<int>("c2");
            IVariable x = new Variable<int>("x");
            IVariable y = new Variable<int>("y");
            f.Components.Add(c1);
            f.Components.Add(c2);
            f.Arguments.Add(x);
            f.Arguments.Add(y);

            f.SetValues(
                new[] { 100, 200 },
                new VariableValueFilter<int>(x, new[] { 1, 2, 3, 4, 5 }),
                new VariableValueFilter<int>(y, new[] { 1, 2, 3 })
                );

            IFunction filtered = f.Filter(new ComponentFilter(c1));

            IMultiDimensionalArray<int> values = filtered.GetValues<int>(new VariableValueFilter<int>(x, new[] { 1, 2, 3 }));

            Assert.IsTrue(values.Shape.SequenceEqual(new[] { 3, 3 }));
            Assert.AreEqual(100, values[2, 2]);
        }
Example #6
0
        public void FilteredFunctionArgumentInterpolationAndExtrapolationTakenFromParent()
        {
            IFunction function = new Function();
            function.Components.Add(new Variable<int>());
            function.Arguments.Add(new Variable<int>{InterpolationType = InterpolationType.Constant});
            function.Arguments[0].ExtrapolationType = ExtrapolationType.Linear;
            function[0] = 1;
            function[1] = 2;

            IFunction filtered =
                function.Filter(new VariableValueFilter<int>(function.Arguments[0], new[] { 0, 1 }));

            Assert.AreEqual(InterpolationType.Constant, filtered.Arguments[0].InterpolationType);
            Assert.AreEqual(ExtrapolationType.Linear, filtered.Arguments[0].ExtrapolationType);
        }
Example #7
0
 public void SettingNoDataValuesOfFilteredFunctionGivesException()
 {
     IFunction function = new Function();
     function.Components.Add(new Variable<int>());
     function.Arguments.Add(new Variable<int>());
     function[0] = 1;
     function[1] = 2;
     function[2] = 3;
     function.Components[0].NoDataValue = 79;
     var filtered = function.Filter(new VariableValueFilter<int>(function.Arguments[0], new[] { 0, 1 }));
     filtered.Components[0].NoDataValue = 88;
 }
Example #8
0
 [Category(TestCategory.Jira)] //TOOLS-4258
 public void NoDataValuesOfFilteredFunction()
 {
     IFunction function = new Function();
     function.Components.Add(new Variable<int>());
     function.Arguments.Add(new Variable<int>());
     function[0] = 1;
     function[1] = 2;
     function[2] = 3;
     function.Components[0].NoDataValue = 79;
     var filtered = function.Filter(new VariableValueFilter<int>(function.Arguments[0], new[] { 0, 1 }));
     Assert.AreEqual(79, filtered.Components[0].NoDataValue);
 }
        public void ClearSourceFunctionShouldClearFilteredBindingList()
        {
            IFunction function = new Function
            {
                Arguments = { new Variable<int>("x")},
                Components = { new Variable<int>("f") }
            };

            function[1] = 1;
            function[2] = 4;

            var filteredFunction = function.Filter(new VariableValueFilter<int>(function.Arguments[0], new[] { 1 }));

            IFunctionBindingList functionBindingList = new FunctionBindingList { Function = filteredFunction };

            functionBindingList.Count
                .Should().Be.EqualTo(1);

            function.Clear();

            functionBindingList.Count
                .Should().Be.EqualTo(0);
        }
        public void Filtered2DFunction()
        {
            IFunction function = new Function
                                     {
                                         Arguments = { new Variable<int>("x"), new Variable<int>("y") },
                                         Components = {new Variable<int>("f")}
                                     };

            function[1, 1] = 1;
            function[1, 2] = 2;
            function[2, 1] = 3;
            function[2, 2] = 4;

            var filteredFunction = function.Filter(new VariableValueFilter<int>(function.Arguments[0], new[]{1}));

            IFunctionBindingList functionBindingList = new FunctionBindingList { Function = filteredFunction };

            functionBindingList.Count
                .Should().Be.EqualTo(2);
        }
Example #11
0
        [Category(TestCategory.WorkInProgress)] //TOOLS-
        public void PropertyChangeBubbleCorerctlyForFilteredFunction()
        {
            IFunction function = new Function
            {
                Arguments = { new Variable<int>("x1"), new Variable<int>("x2") },
                Components = { new Variable<int>("f") }
            };

            function[0, 1] = new[] { 1 };
            function[0, 2] = new[] { 2 };
            function[1, 1] = new[] { 3 };
            function[1, 2] = new[] { 4 };

            var arg1 = function.Arguments[0];

            var filteredFunction = function.Filter(new VariableValueFilter<int>(arg1, 0), new VariableReduceFilter(arg1));

            int called = 0;

            ((INotifyPropertyChange)filteredFunction).PropertyChanged += (s, e) => called++;

            filteredFunction[0] = 3; //set value

            Assert.AreEqual(2, called); // Expect IsEditing is changed twice (true, false)
        }
Example #12
0
        public void SetFunctionValuesUsingFilteredFunction()
        {
            IFunction function = new Function
            {
                Arguments = { new Variable<int>("x") },
                Components = { new Variable<int>("f1"), new Variable<int>("f2") }
            };

            function[1] = new[] { 1, 10 };
            function[2] = new[] { 2, 20 };

            var filteredFunction = function.Filter(new VariableValueFilter<int>(function.Arguments[0], new[] { 2 }));

            var f1ValueChangeCount = 0;
            filteredFunction.Components[0].ValuesChanged += delegate { f1ValueChangeCount++; };

            // replace value
            filteredFunction.Components[0].Values[0] = 3;

            function.Components[0].Values.Cast<int>()
                .Should().Have.SameSequenceAs(new[] {1, 3});

            function.Components[1].Values.Cast<int>()
                .Should().Have.SameSequenceAs(new[] { 10, 20 });

            f1ValueChangeCount
                .Should().Be.EqualTo(1);
        }
Example #13
0
        public void FilteredFunctionStore()
        {
            IFunction function = new Function { Arguments = { new Variable<int>("x") }, Components = { new Variable<int>("y") } };

            function[1] = 1;
            function[2] = 2;

            var store = function.Store;
            
            var filteredFunction = function.Filter(new VariableValueFilter<int>(function.Arguments[0], new[] {2}));

            filteredFunction.Store
                .Should().Be.EqualTo(store);

            store.Functions.Count
                .Should("Filtered functions not added to store").Be.EqualTo(3);
        }
Example #14
0
        public void EventShouldNotBubbleIfFunctionOutsideReducedFunctionIsRemoved()
        {
            int called = 0;
            IFunction function = new Function
            {
                Arguments = { new Variable<int>("x1"), 
                    new Variable<int>("x2") },
                Components = { new Variable<int>("f") }
            };

            function[0, 1] = new[] { 1 };
            function[0, 2] = new[] { 2 };
            function[1, 1] = new[] { 3 };
            function[1, 2] = new[] { 4 };

            var arg1 = function.Arguments[0];

            var filteredFunction = function.Filter(new VariableValueFilter<int>(arg1, 0), new VariableReduceFilter(arg1));

            filteredFunction.ValuesChanged += (s, e) => called++;

            function.Arguments[0].Values.Remove(1);
            Assert.AreEqual(0, called, "Removing unrelated argument value: should not fire events");
        }
Example #15
0
        public void EventShouldNotBubbleIfReducedFunctionIsUnaffected()
        {
            int called = 0;
            IFunction function = new Function
            {
                Arguments = { new Variable<int>("x1"), 
                    new Variable<int>("x2") },
                Components = { new Variable<int>("f") }
            };

            function[0, 1] = new[] { 1 };
            function[0, 2] = new[] { 2 };
            function[1, 1] = new[] { 3 };
            function[1, 2] = new[] { 4 };

            var arg1 = function.Arguments[0];

            var filteredFunction = function.Filter(new VariableValueFilter<int>(arg1, 0), new VariableReduceFilter(arg1));
            
            filteredFunction.ValuesChanged += (s, e) => called++;

            called = 0;
            function[1, 1] = 55; //set value
            Assert.AreEqual(0, called, "Filtered function should be unaffected: should not fire events");

            called = 0;
            function[0, 1] = 3; //set value
            Assert.AreEqual(1, called, "Filtered function should be affected: should fire events");
        }