Beispiel #1
0
        public static void AssertGenericType(this TicNode node, StatePrimitive desc, StatePrimitive anc,
                                             bool isComparable = false)
        {
            var generic = node.State as ConstrainsState;

            Assert.IsNotNull(generic);
            if (desc == null)
            {
                Assert.IsFalse(generic.HasDescendant);
            }
            else
            {
                Assert.AreEqual(desc, generic.Descedant);
            }

            if (anc == null)
            {
                Assert.IsFalse(generic.HasAncestor);
            }
            else
            {
                Assert.AreEqual(anc, generic.Ancestor);
            }

            Assert.AreEqual(isComparable, generic.IsComparable, "IsComparable claim missed");
        }
Beispiel #2
0
 public bool Apply(ConstrainsState ancestor, StatePrimitive descendant, TicNode ancestorNode, TicNode descendantNode)
 {
     if (ancestor.Fits(descendant))
     {
         ancestorNode.State = descendant;
     }
     return(true);
 }
Beispiel #3
0
 public bool Apply(ConstrainsState ancestor, StatePrimitive descendant, TicNode ancestorNode,
                   TicNode descendantNode)
 {
     if (!ancestor.HasAncestor)
     {
         return(true);
     }
     return(descendant.CanBeImplicitlyConvertedTo(ancestor.Ancestor));
 }
Beispiel #4
0
        public void GetLastCommonAncestor(PrimitiveTypeName a, PrimitiveTypeName b, PrimitiveTypeName expected)
        {
            var result = new StatePrimitive(a).GetLastCommonPrimitiveAncestor(new StatePrimitive(b)).Name;

            Assert.AreEqual(expected, result);
            var revresult = new StatePrimitive(b).GetLastCommonPrimitiveAncestor(new StatePrimitive(a)).Name;

            Assert.AreEqual(expected, revresult);
        }
Beispiel #5
0
        public void GetFirstCommonDescedant(PrimitiveTypeName a, PrimitiveTypeName b, PrimitiveTypeName expected)
        {
            var result = new StatePrimitive(a).GetFirstCommonDescendantOrNull(new StatePrimitive(b))?.Name;

            Assert.AreEqual(expected, result);
            var revresult = new StatePrimitive(b).GetFirstCommonDescendantOrNull(new StatePrimitive(a))?.Name;

            Assert.AreEqual(expected, revresult);
        }
Beispiel #6
0
        public void GetFirstCommonDescendantToAnyReturnsSelf(PrimitiveTypeName type)
        {
            var result = new StatePrimitive(type).GetFirstCommonDescendantOrNull(StatePrimitive.Any).Name;

            Assert.AreEqual(type, result);
            var reversed = StatePrimitive.Any.GetFirstCommonDescendantOrNull(new StatePrimitive(type)).Name;

            Assert.AreEqual(type, reversed);
        }
Beispiel #7
0
        public void GetFirstCommonDescedant_returnsNull(PrimitiveTypeName a, PrimitiveTypeName b)
        {
            var result = new StatePrimitive(a).GetFirstCommonDescendantOrNull(new StatePrimitive(b));

            Assert.IsNull(result);
            var revresult = new StatePrimitive(b).GetFirstCommonDescendantOrNull(new StatePrimitive(a));

            Assert.IsNull(revresult);
        }
Beispiel #8
0
        public static TicNode AssertAndGetSingleGeneric(this ITicResults result, StatePrimitive desc,
                                                        StatePrimitive anc, bool isComparable = false)
        {
            Assert.AreEqual(1, result.GenericsCount, "Incorrect generics count");
            var genericNode = result.GenericNodes.Single();

            AssertGenericType(genericNode, desc, anc, isComparable);
            return(genericNode);
        }
Beispiel #9
0
        public static void SetCall(this GraphBuilder builder, StatePrimitive ofTheCall, params int[] argumentsThenResult)
        {
            var types = new ITicNodeState[argumentsThenResult.Length];

            for (int i = 0; i < types.Length; i++)
            {
                types[i] = ofTheCall;
            }
            builder.SetCall(types, argumentsThenResult);
        }
Beispiel #10
0
        public bool Apply(StatePrimitive ancestor, ConstrainsState descendant, TicNode _, TicNode descendantNode)
        {
            descendant.AddAncestor(ancestor);
            var result = descendant.GetOptimizedOrNull();

            if (result == null)
            {
                return(false);
            }
            descendantNode.State = result;
            return(true);
        }
Beispiel #11
0
        public Player()
        {
            avatarID     = new StatePrimitive <string>();
            networkID    = new StatePrimitive <string>();
            roleID       = new StatePrimitive <string>();
            ownedItemIDs = new StatePrimitiveList <string>();

            healthLevel = new StatePrimitive <float>();
            hungryLevel = new StatePrimitive <float>();
            thirstLevel = new StatePrimitive <float>();
            temperature = new StatePrimitive <float>();
        }
Beispiel #12
0
 public bool Apply(StatePrimitive ancestor, ConstrainsState descendant, TicNode ancestorNode, TicNode descendantNode)
 {
     if (descendant.Fits(ancestor))
     {
         if (descendant.Prefered != null && descendant.Fits(descendant.Prefered))
         {
             descendantNode.State = descendant.Prefered;
         }
         else
         {
             descendantNode.State = ancestor;
         }
     }
     return(true);
 }
Beispiel #13
0
        public void GetLastCommonAncestorToSelfReturnsSelf(PrimitiveTypeName type)
        {
            var result = new StatePrimitive(type).GetLastCommonPrimitiveAncestor(new StatePrimitive(type)).Name;

            Assert.AreEqual(type, result);
        }
Beispiel #14
0
 public GenericConstrains(StatePrimitive ancestor = null, StatePrimitive descendant = null, bool isComparable = false)
 {
     Ancestor     = ancestor;
     Descendant   = descendant;
     IsComparable = isComparable;
 }
Beispiel #15
0
        public void GetLastCommonAncestorToAnyReturnsAny(PrimitiveTypeName type)
        {
            var result = new StatePrimitive(type).GetLastCommonPrimitiveAncestor(StatePrimitive.Any);

            Assert.AreEqual(StatePrimitive.Any, result);
        }
Beispiel #16
0
 public bool Apply(ConstrainsState ancestor, StatePrimitive descendant, TicNode ancestorNode, TicNode descendantNode)
 => ApplyAncestorConstrains(ancestorNode, ancestor, descendant);
Beispiel #17
0
 public bool Apply(ICompositeState ancestor, StatePrimitive descendant, TicNode _, TicNode __)
 => false;
Beispiel #18
0
 public Item()
 {
     modelID = new StatePrimitive <string>();
 }
Beispiel #19
0
 public bool Apply(StatePrimitive ancestor, StatePrimitive descendant, TicNode _, TicNode __)
 => descendant.CanBeImplicitlyConvertedTo(ancestor);
Beispiel #20
0
 public bool Apply(StatePrimitive ancestor, StatePrimitive descendant, TicNode _, TicNode __)
 => true;
Beispiel #21
0
 public bool Apply(StatePrimitive ancestor, ConstrainsState descendant, TicNode _, TicNode __)
 => !descendant.HasDescendant || descendant.Descedant.CanBeImplicitlyConvertedTo(ancestor);