public void TC_SimpleStack()
        {
            var stack = new SimpleStack <double>();

            var input = GetDoubleTestList();

            foreach (var item in input)
            {
                stack.Add(item, item);
            }
            Assert.AreEqual(input.Count, stack.GetSize());

            List <double> poppedItems = new List <double>();

            while (stack.GetSize() > 0)
            {
                poppedItems.Add(stack.RemoveMin());
            }
            input.Reverse();
            Assert.IsTrue(CollectionsEquality.Equals(input, poppedItems));

            stack.Clear();
            Assert.AreEqual(0, stack.GetSize());
            Assert.AreEqual("Simple Stack", stack.GetName());
        }
        public void TC_IStateOrConditions()
        {
            var problem   = new Planner.SAS.Problem(new SASInputData(GetFilePath("TC_Gripper.sas")));
            var heuristic = new FFHeuristic(problem);

            IStateOrConditions state  = problem.InitialState;
            IStateOrConditions state2 = new Planner.SAS.State(1, 1, 1, 1, 0, 4, 4);

            Assert.IsTrue(CollectionsEquality.Equals(problem.GetSuccessors((IState)state), state.DetermineTransitions(problem)));
            Assert.IsFalse(state.DetermineGoalNode(problem));
            Assert.IsTrue(state2.DetermineGoalNode(problem));
            Assert.AreEqual(heuristic.GetValue((IState)state), state.DetermineHeuristicValue(heuristic));

            IStateOrConditions conditions  = problem.GoalConditions;
            IStateOrConditions conditions2 = new Planner.SAS.Conditions(new Planner.SAS.Assignment(5, 4), new Planner.SAS.Assignment(6, 4));

            Assert.IsTrue(CollectionsEquality.Equals(problem.GetPredecessors((IConditions)conditions), conditions.DetermineTransitions(problem)));
            Assert.IsFalse(conditions.DetermineGoalNode(problem));
            Assert.IsTrue(conditions2.DetermineGoalNode(problem));
            Assert.AreEqual(heuristic.GetValue((IConditions)conditions), conditions.DetermineHeuristicValue(heuristic));

            IStateOrConditions relativeState  = problem.GoalConditions.GetCorrespondingRelativeStates(problem).First();
            IStateOrConditions relativeState2 = new Planner.SAS.RelativeState(-1, -1, -1, -1, -1, 4, 4);

            Assert.IsTrue(CollectionsEquality.Equals(problem.GetPredecessors((IRelativeState)relativeState), relativeState.DetermineTransitions(problem)));
            Assert.IsFalse(relativeState.DetermineGoalNode(problem));
            Assert.IsTrue(relativeState2.DetermineGoalNode(problem));
            Assert.AreEqual(heuristic.GetValue((IRelativeState)relativeState), relativeState.DetermineHeuristicValue(heuristic));
        }
        public void TC_Transitions()
        {
            var problem = new Planner.SAS.Problem(new SASInputData(GetFilePath("TC_Gripper.sas")));

            ISuccessor successor = problem.GetSuccessors(problem.InitialState).First();

            Assert.IsFalse(successor.IsComplexTransition());
            Assert.IsTrue(successor.GetSuccessorState().Equals(successor.GetTransitionResult()));
            var successorResults = successor.GetComplexTransitionResults().ToList();

            Assert.AreEqual(1, successorResults.Count);
            Assert.IsTrue(successorResults.First().Equals(successor.GetTransitionResult()));

            IPredecessor predecessor = problem.GetPredecessors(problem.GoalConditions).First();

            Assert.IsFalse(predecessor.IsComplexTransition());
            Assert.IsTrue(predecessor.GetPredecessorConditions().Equals(predecessor.GetTransitionResult()));
            var predecessorResults = predecessor.GetComplexTransitionResults().ToList();

            Assert.AreEqual(1, predecessorResults.Count);
            Assert.IsTrue(predecessorResults.First().Equals(predecessor.GetTransitionResult()));

            IPredecessor predecessor2 = problem.GetPredecessors(problem.GoalConditions.GetCorrespondingRelativeStates(problem).First()).First();

            Assert.IsTrue(predecessor2.IsComplexTransition());
            Assert.IsTrue(CollectionsEquality.Equals(predecessor2.GetPredecessorRelativeStates(), predecessor2.GetComplexTransitionResults()));
            var predecessorResults2 = predecessor2.GetComplexTransitionResults().ToList();

            Assert.AreEqual(1, predecessorResults2.Count);
            Assert.IsTrue(predecessorResults2.First().Equals(predecessor2.GetTransitionResult()));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Checks the equality of objects.
 /// </summary>
 /// <param name="obj">Object to be checked.</param>
 /// <returns>True if the objects are equal, false otherwise.</returns>
 public override bool Equals(object obj)
 {
     Multiply other = obj as Multiply;
     if (other == null)
     {
         return false;
     }
     return CollectionsEquality.Equals(Children, other.Children);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            Plus other = obj as Plus;

            if (other == null)
            {
                return(false);
            }
            return(CollectionsEquality.Equals(Children, other.Children));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            AndExpression other = obj as AndExpression;

            if (other == null)
            {
                return(false);
            }
            return(CollectionsEquality.Equals(Children, other.Children));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            ConditionsCNF other = obj as ConditionsCNF;

            if (other == null)
            {
                return(false);
            }

            return(CollectionsEquality.Equals(this, other));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            Parameters other = obj as Parameters;

            if (other == null)
            {
                return(false);
            }

            return(CollectionsEquality.Equals(this, other));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            RelativeState other = obj as RelativeState;

            if (other == null)
            {
                return(false);
            }

            return(CollectionsEquality.Equals(Values, other.Values));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            Atom other = obj as Atom;

            if (other == null)
            {
                return(false);
            }

            return((NameId == other.NameId) && CollectionsEquality.Equals(Terms, other.Terms));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            Parameter other = obj as Parameter;

            if (other == null)
            {
                return(false);
            }

            return(ParameterNameId == other.ParameterNameId && CollectionsEquality.Equals(TypeNamesIDs, other.TypeNamesIDs));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            Substitution other = obj as Substitution;

            if (other == null)
            {
                return(false);
            }

            return(CollectionsEquality.Equals(this, other));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            StateLabels other = obj as StateLabels;

            if (other == null)
            {
                return(false);
            }

            return(CollectionsEquality.Equals(this, other));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            WhenEffect other = obj as WhenEffect;

            if (other == null)
            {
                return(false);
            }

            return(Expression.Equals(other.Expression) &&
                   CollectionsEquality.Equals(Effects, other.Effects));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            ForallEffect other = obj as ForallEffect;

            if (other == null)
            {
                return(false);
            }

            return(Parameters.Equals(other.Parameters) &&
                   CollectionsEquality.Equals(Effects, other.Effects));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Checks the equality of objects.
        /// </summary>
        /// <param name="obj">Object to be checked.</param>
        /// <returns>True if the objects are equal, false otherwise.</returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            State other = obj as State;

            if (other == null)
            {
                return(false);
            }

            if (!CollectionsEquality.Equals(Predicates, other.Predicates) ||
                !CollectionsEquality.Equals(NumericFunctions, other.NumericFunctions) ||
                !CollectionsEquality.Equals(ObjectFunctions, other.ObjectFunctions))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 17
0
        public void TC_SimpleQueue()
        {
            var queue = new SimpleQueue <double>();

            var input = GetDoubleTestList();

            foreach (var item in input)
            {
                queue.Add(item, item);
            }
            Assert.AreEqual(input.Count, queue.GetSize());

            List <double> poppedItems = new List <double>();

            while (queue.GetSize() > 0)
            {
                poppedItems.Add(queue.RemoveMin());
            }
            Assert.IsTrue(CollectionsEquality.Equals(input, poppedItems));

            queue.Clear();
            Assert.AreEqual(0, queue.GetSize());
            Assert.AreEqual("Simple Queue", queue.GetName());
        }
Exemplo n.º 18
0
        /// <summary>
        /// Does a generic heap test.
        /// </summary>
        /// <param name="heap">Heap to be checked.</param>
        /// <param name="input">Input values.</param>
        private static void HeapTest <Value>(IHeap <Value, Value> heap, List <Value> input) where Value : IComparable
        {
            List <Value> sortedInput = new List <Value>(input);

            sortedInput.Sort();

            input.ForEach(number => heap.Add(number, number));
            Assert.AreEqual(input.Count, heap.GetSize());

            Assert.AreEqual(sortedInput[0], heap.GetMinKey());

            heap.Clear();
            Assert.AreEqual(0, heap.GetSize());

            input.ForEach(number => heap.Add(number, number));
            List <Value> result = new List <Value>();

            while (heap.GetSize() != 0)
            {
                result.Add(heap.RemoveMin());
            }

            Assert.IsTrue(CollectionsEquality.Equals(sortedInput, result));
        }