public void Behavior_Setter_Not_Test()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {};

            //Since the Behavior was not set, the string should be empty
            bool expected = true;
            bool actual = target.Behaviour.Equals(string.Empty);

            //Assert they are the equal
            Assert.AreEqual(expected, actual);
        }
        public void Behavior_Getter_Test()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.Increasing
            };

            //Since the Behavior was set to decreasing, we want to check that this was set
            bool expected = true;
            bool actual = BehaviourTypes.Increasing.Equals(target.Behaviour);

            //Assert they are the equal
            Assert.AreEqual(expected, actual);
        }
        public IPrimitiveConditionData GenerateRuleData(List<TouchPoint2> points)
        {
            // Only check this if there are only TWO points and  the points are simultaneous and not in different moments

            String behaviour = "";
            double distanceN = 0f, distanceN_1 = 0f;

            int firstStrokeLen = points[0].Stroke.StylusPoints.Count;
            int secondStrokeLen = points[1].Stroke.StylusPoints.Count;

            //Sometimes we get to much precious data that captures unwanted behaviours...
            //try few times to match the pattern
            double maxDifference = 0;

            for (int n = 1; n < 4; n++)
            {
                if (firstStrokeLen - n < 0 || secondStrokeLen - n < 0)
                    break;

                // Get the point of two gestures at nth position
                StylusPoint p1 = points[0].Stroke.StylusPoints[n];
                StylusPoint p2 = points[1].Stroke.StylusPoints[n];
                distanceN = TrigonometricCalculationHelper.GetDistanceBetweenPoints(p1, p2);

                if (firstStrokeLen - n - 1 < 0 || secondStrokeLen - n - 1 < 0)
                  break;

                // Get the point of two gestures at (n-1)th position
                p1 = points[0].Stroke.StylusPoints[firstStrokeLen - n - 1];
                p2 = points[1].Stroke.StylusPoints[secondStrokeLen - n - 1];
                distanceN_1 = TrigonometricCalculationHelper.GetDistanceBetweenPoints(p1, p2);

                double maxValue = Math.Max(distanceN_1,distanceN);
                double currentDifference = Math.Abs(distanceN_1 - distanceN);

                currentDifference = currentDifference / maxValue;

                if (currentDifference > maxDifference)
                     maxDifference = currentDifference;

                if (distanceN < distanceN_1)
                    {
                        behaviour = BehaviourTypes.Increasing;
                        break;
                    }

                else if (distanceN > distanceN_1)
                {
                    behaviour = BehaviourTypes.Decreasing;
                    break;
                }
             /*   else if (_data.Behaviour.ToLower() == BehaviourTypes.Range)
                {
                    if (distanceN >= _data.Min && distanceN <= _data.Max)
                    {
                        result = true;
                        break;
                    }
                }
                else if (_data.Behaviour.ToLower() == BehaviourTypes.UnChanged)
                {
                    // Note: Check if the change is within acceptable range
                    // For example: unchanged 10% means if the change is
                    // below 10% of the distance than consider it acceptable

                    double diff = Math.Abs(distanceN - distanceN_1);
                    if (diff < distanceN / _data.Min)
                    {
                        result = true;
                        break;
                    }
                }*/
            }

            DistanceBetweenPoints data = new DistanceBetweenPoints();

            if (maxDifference > 0)
            {

                if (maxDifference <= UNCHANGED_TOLERANCE)
                {
                    behaviour = BehaviourTypes.UnChanged;
                    data.Min = Convert.ToInt16(maxDifference);

                }

            }

            data.Behaviour = behaviour;

            return data;
        }
 public void Init(IPrimitiveConditionData ruleData)
 {
     _data = ruleData as DistanceBetweenPoints;
 }
        public void Union_With_A_Null_Test()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.UnChanged,
                Max = 2,
                Min = 1
            };

            // Since the ruleData is null, the union should fail
            IPrimitiveConditionData anotherRuleData = null;

            //Union should fail
            target.Union(anotherRuleData);
        }
        public void Union_Unchanged_and_Unchanged()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.UnChanged,
                Max = 3,
                Min = 1
            };

            // Another instance of same type of ruleData
            IPrimitiveConditionData anotherRuleData = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.UnChanged,
                Max = 4,
                Min = 0
            };

            //Union the 2 rules
            target.Union(anotherRuleData);

            //We expect the min to be the original min and different from the 2nd rule
            bool expected = true;
            bool actual = target.Min.Equals(0);
            Assert.AreNotEqual(expected, actual);

            //We expect the behavior of the union'd rule to be "unchanged", as nothing was union'd
            expected = true;
            actual = target.Behaviour.Equals("unchanged");
            Assert.AreEqual(expected, actual);
        }
        public void Union_Unchanged_and_Increasing()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.UnChanged,
                Max = 2,
                Min = 1
            };

            // Another instance of same type of ruleData
            IPrimitiveConditionData anotherRuleData = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.Increasing,
                Max = 3,
                Min = 2
            };

            //Union the 2 rules
            target.Union(anotherRuleData);

            //We expect the max to be the max of 2nd rule, which is 3
            bool expected = true;
            bool actual = target.Max.Equals(3);
            Assert.AreEqual(expected, actual);

            //We expect the behavior of the union'd rule to be "increasing", given the union types
            expected = true;
            actual = target.Behaviour.Equals("increasing");
            Assert.AreEqual(expected, actual);
        }
        public void toGDL_Unchanged_test()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.UnChanged,
                Max = 2,
                Min = 0
            };

            // Since the behavior was set to unchanged, that should be reflected in the output of toGDL
            bool expected = true;
            bool actual = target.ToGDL().Equals("Distance between points: unchanged 0%");

            Assert.AreEqual(expected, actual);
        }
        public void Union_Decreasing_and_Decreasing()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.Decreasing,
                Max = 3,
                Min = 1
            };

            // Another instance of same type of ruleData
            IPrimitiveConditionData anotherRuleData = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.Decreasing,
                Max = 4,
                Min = 0
            };

            //Union the 2 rules
            target.Union(anotherRuleData);

            //We expect the min to be the min of 2nd rule, which is 0
            bool expected = true;
            bool actual = target.Min.Equals(0);
            Assert.AreEqual(expected, actual);

            //We expect the behavior of the union'd rule to be "decreasing", given the union types
            expected = true;
            actual = target.Behaviour.Equals("decreasing");
            Assert.AreEqual(expected, actual);
        }
        public void EqualsTest_Same_Type_of_RuleData_with_same_value()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.Increasing,
                Max = -1,
                Min = -1
            };

            // Another instance of same type of ruleData
            IPrimitiveConditionData anotherRuleData = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.Increasing,
                Max = -1,
                Min = -1
            };

            // Since the values are same, it should be equal
            bool expected = true;
            bool actual = target.Equals(anotherRuleData);

            Assert.AreEqual(expected, actual);
        }
        public void Invalid_Union_Test_with_Increasing_and_Decreasing()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.Increasing,
                Max = -1,
                Min = -1
            };

            // Another instance of same type of ruleData
            IPrimitiveConditionData anotherRuleData = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.Decreasing,
                Max = -1,
                Min = -1
            };

            // Since the behavior is different (increasing and decreasing), appropriate exception should be shown
            target.Union(anotherRuleData);
        }
        public void EqualsTest_Null_Check()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.Increasing,
                Max = -1,
                Min = -1
            };

            bool expected = false;
            bool actual = target.Equals(null);

            Assert.AreEqual(expected, actual);
        }
        public void EqualsTest_Different_Types_of_RuleData()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.Increasing,
                Max = -1,
                Min = -1
            };

            // Any random type - just not the type that we are testing
            IPrimitiveConditionData anotherRuleData = new ClosedLoop();

            // Since the ruleData are of different type, it should not be equal
            bool expected = false;
            bool actual = target.Equals(anotherRuleData);

            Assert.AreEqual(expected, actual, "Different types of rules should not match!");
        }
        public void DistanceBtwPoints_Min_Setter_Test()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.UnChanged,
                Min = 0
            };

            //The min was set to 0, so we confirm that the min was indeed set to 0
            bool expected = true;
            bool actual = target.Min.Equals(0);

            //Assert they are equal
            Assert.AreEqual(expected, actual);
        }
        public void DistanceBtwPoints_Min_Setter_Not_Set_Test()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.UnChanged,
            };

            //Since the min was not set, we are verifying that it was set to 0 as specified in original code
            bool expected = true;
            bool actual = target.Min.Equals(0);

            //Assert they are equal
            Assert.AreEqual(expected, actual);
        }
        public void DistanceBtwPoints_Min_Getter_Test()
        {
            // The type we are testing
            DistanceBetweenPoints target = new DistanceBetweenPoints()
            {
                Behaviour = BehaviourTypes.UnChanged,
                Min = -1
            };

            //The max was set to 5, so test the getter to check if it returns 5
            bool expected = true;
            int actualMin = -1;
            bool actual = actualMin == (target.Min);

            //Assert they are equal
            Assert.AreEqual(expected, actual);
        }