private void ProcessMovements()
 {
     if (!IsRearing())
     {
         ResetPositions();
         return;
     }
     if (FirstPosition.Length == 0)
     {
         FirstPosition = Succ;
         return;
     }
     if (SecondPosition.Length == 0)
     {
         SetSecondPosition();
         return;
     }
     if (!Succ.Equals(FirstPosition) && !Succ.Equals(SecondPosition))
     {
         ResetPositions();
         return;
     }
     var startCount = RepetitiveFlag;
     if (Succ.Equals(FirstPosition) && Pred.Equals(SecondPosition)) RepetitiveFlag++;
     if (Succ.Equals(SecondPosition) && Pred.Equals(FirstPosition) && RepetitiveFlag > 0) RepetitiveFlag++;
     if (RepetitiveFlag > 1 && startCount < RepetitiveFlag) Counter++;
 }
Esempio n. 2
0
 public static bool IsNumericalVal(ITerm t)
 {
     return(t switch
     {
         Zero _ => true,
         Succ s => IsNumericalVal(s.Of),
         _ => false
     });
Esempio n. 3
0
 private void FillGapWithLastByte()
 {
     while (Succ != ReadTime)
     {
         WriteLine(Succ, PredByte);
         Succ = Succ.AddSeconds(1);
     }
 }
Esempio n. 4
0
        public override void Execute()
        {
            var succRear = Succ.Substring(Succ.Length - 1, 1);

            if (succRear.Equals("1"))
            {
                Counter++;
            }
        }
Esempio n. 5
0
 public static bool IsNumericVal(Context ctx, ITerm t)
 {
     return t switch
     {
         Zero => true,
         Succ s => IsNumericVal(ctx, s.Of),
         _ => false
     };
 }
Esempio n. 6
0
        public override void Execute()
        {
            var predRear = Pred.Substring(Pred.Length - 1, 1);
            var succRear = Succ.Substring(Succ.Length - 1, 1);

            if ((succRear.Equals("1")) && (predRear.Equals("0")))
            {
                Counter++;
            }
        }
 private int GetChangeCount()
 {
     var count = 0;
     var first = FirstPosition.ToCharArray(0, 7);
     var second = Succ.ToCharArray(0, 7);
     for (var x = 0; x < 7; x++)
     {
         if (first[x] != second[x]) count++;
     }
     return count;
 }
Esempio n. 8
0
        public Node Succ()
        {
            Expect(Token.SUCC);
            Expect(Token.COROPEN);
            var p = new Succ()
            {
                Exp()
            };

            Expect(Token.CORCLOSE);
            return(p);
        }
Esempio n. 9
0
        public void EvaluationTest()
        {
            var zero = new Zero();

            Assert.Equal(0, zero.Evaluate());
            var one = new Succ <Zero>();

            Assert.Equal(1, one.Evaluate());
            var five = new Succ <Succ <Succ <Succ <Succ <Zero> > > > >();

            Assert.Equal(5, five.Evaluate());
        }
        public override void Execute()
        {
            var predRear = Pred.Substring(Pred.Length - 1, 1);
            var succRear = Succ.Substring(Succ.Length - 1, 1);
            var predHorz = Pred.Substring(0, Pred.Length - 1);
            var succHorz = Succ.Substring(0, Succ.Length - 1);

            if (predRear.Equals("1") && succRear.Equals("1") && !predHorz.Equals(succHorz))
            {
                Counter++;
            }
        }
Esempio n. 11
0
        public void EvalSuccFalse()
        {
            // Arrange
            var s = new Succ(new False());

            // Act
            var term = Eval(s);

            // Assert
            Assert.IsType <Succ>(term);
            var succ = term as Succ;

            Assert.IsType <False>(succ?.Of);
        }
Esempio n. 12
0
        public void InequalityTest()
        {
            var rei  = new Zero();
            var zero = new Zero();
            var ichi = new Succ <Zero>();
            var one  = new Succ <Zero>();
            var ni   = new Succ <Succ <Zero> >();
            var two  = new Succ <Succ <Zero> >();

            Assert.True(zero != one);
            Assert.True(one != two);
            Assert.True(two != zero);
            Assert.False(rei != zero);
            Assert.False(ichi != one);
            Assert.False(ni != two);
        }
Esempio n. 13
0
        public override void Execute()
        {
            if (Pred.Length == 0)
            {
                Pred = "00000000";                   // Pred == null on first iteration
            }
            var succRear = Succ.Substring(Succ.Length - 1, 1);
            var predRear = Pred.Substring(Pred.Length - 1, 1);
            var succX1   = Succ.Substring(1, 1);
            var succX2   = Succ.Substring(2, 1);
            var succY2   = Succ.Substring(5, 1);

            if (((succRear.Equals("1")) && (predRear.Equals("0"))) && (succY2.Equals("1")) &&
                ((succX1.Equals("1")) || (succX2.Equals("1"))))
            {
                Counter++;
            }
        }
Esempio n. 14
0
 private static List <Node> ConstructNodes(List <NodeWindow> nodeWindows, List <Connection> connections)
 {
     return(nodeWindows.Select(node =>
     {
         Node result = new Node();
         result.Base = node.baseClassName;
         result.Name = node.nodeName;
         if (result.Base == "") // Group node
         {
             Group g = node as Group;
             result.Members = ConstructNodes(g.nodes, g.InterConnections);
             result.StartMember = (from c in g.connections
                                   where c.outPoint == g.startPoint
                                   select c.inPoint.masterNode.nodeName)
                                  .First();
             result.EndMember = (from c in g.connections
                                 where c.inPoint == g.endPoint
                                 select c.outPoint.masterNode.nodeName)
                                .First();
         }
         else
         {
             result.Params = new Dictionary <string, string>();
             foreach (var p in node.paramPairs)
             {
                 result.Params.Add(p.Key, p.Value);
             }
         }
         result.Position = new Position(node.rect.position.x, node.rect.position.y);
         result.Succ = new List <Succ>();
         var succConns = from c in connections
                         where c.outPoint.masterNode == node
                         select c;
         foreach (var c in succConns)
         {
             Succ succ = new Succ();
             succ.Condition = c.conditions.Select(n => n.nodeName).ToList();
             succ.EndPrev = c.stopPrev;
             succ.Dest = c.inPoint.masterNode.nodeName;
             result.Succ.Add(succ);
         }
         return result;
     }).ToList());
 }
Esempio n. 15
0
        public void ComparisonTest()
        {
            var rei  = new Zero();
            var zero = new Zero();
            var ichi = new Succ <Zero>();
            var one  = new Succ <Zero>();
            var ni   = new Succ <Succ <Zero> >();
            var two  = new Succ <Succ <Zero> >();

            Assert.True(zero < one);
            Assert.True(one < two);
            Assert.True(zero < two);
            Assert.True(two > one);
            Assert.True(one > zero);
            Assert.True(two > zero);
            Assert.True(zero <= rei);
            Assert.True(zero <= one);
            Assert.True(one <= ichi);
            Assert.True(one <= two);
            Assert.True(two <= ni);
            Assert.True(zero <= two);
            Assert.True(two >= ni);
            Assert.True(two >= one);
            Assert.True(one >= ichi);
            Assert.True(one >= zero);
            Assert.True(zero >= rei);
            Assert.True(two >= zero);
            Assert.False(zero > one);
            Assert.False(one > two);
            Assert.False(zero > two);
            Assert.False(two < one);
            Assert.False(one < zero);
            Assert.False(two < zero);
            Assert.False(zero >= one);
            Assert.False(one >= two);
            Assert.False(zero >= two);
            Assert.False(two <= one);
            Assert.False(one <= zero);
            Assert.False(two <= zero);
        }
Esempio n. 16
0
        public void EqualityTest()
        {
            var rei   = new Zero();
            var zero  = new Zero();
            var san   = new Succ <Succ <Succ <Zero> > >();
            var three = new Succ <Succ <Succ <Zero> > >();
            var yon   = new Succ <Succ <Succ <Succ <Zero> > > >();
            var four  = new Succ <Succ <Succ <Succ <Zero> > > >();

            Assert.True(rei.Equals(zero));
            Assert.True(rei == zero);
            Assert.True(san.Equals(three));
            Assert.True(san == three);
            Assert.True(yon.Equals(four));
            Assert.True(yon == four);
            Assert.False(zero.Equals(three));
            Assert.False(zero == three);
            Assert.False(three.Equals(four));
            Assert.False(three == four);
            Assert.False(four.Equals(zero));
            Assert.False(four == zero);
        }
Esempio n. 17
0
        public static void Run()
        {
            //Succ(Succ(Succ(Succ(Zero( )))))
            var fourNumeral = new Succ(rest: new Succ(rest: new Succ(rest: new Succ(rest: new Zero()))));

            (Func <int> Zero, Func <int, int> Succ)algebraInt = (
                Zero : () => 0,
                Succ : (n) => n + 1
                );

            (Func <string> Zero, Func <string, string> Succ)algebraString = (
                Zero : () => $"Zero( )",
                Succ : (Rest) => $"Add one -({Rest })"
                );

            (Func <string> Zero, Func <string, string> Succ)algebraQuestionMarks = (
                Zero : () => $"",
                Succ : (Rest) => $"!{Rest }"
                );

            Func <int, string> f = null;

            f = n => n == 0 ? "" : $"!{ f(n - 1)}";

            (Func <string> E, Func <string, string> F)algebra = (
                E : () => $"",
                F : (Rest) => $"!{Rest }"
                );

            Func <int, string> recursion = null;

            recursion = n => n == 0 ? algebra.E() : $"!{ algebra.F(recursion(n - 1))}";

            var four = fourNumeral.Cata <int>(algebraInt);

            Console.WriteLine(four);
        }
Esempio n. 18
0
 private static ITerm Eval1(Context ctx, ITerm t)
 {
     return t switch
     {
         If ift when ift.Condition is True => ift.Then,
         If ift when ift.Condition is False => ift.Else,
         If ift => new If(ift.Info, Eval1(ctx, ift.Condition), ift.Then, ift.Else),
         Tag tag => new Tag(tag.Info, tag.Label, Eval1(ctx, tag.Term), tag.Type),
         Case c when c.Term is Tag tag && IsVal(ctx, tag.Term) => CaseTag(c.Cases, tag.Label, tag.Term),
         Case c => new Case(c.Info, Eval1(ctx, c.Term), c.Cases),
         App app when app.Left is Abs abs && IsVal(ctx, app.Right) => TermSubsTop(app.Right, abs.Body),
         App app when IsVal(ctx, app.Left) => new App(app.Info, app.Left, Eval1(ctx, app.Right)),
         App app => new App(app.Info, Eval1(ctx, app.Left), app.Right),
         Let let when IsVal(ctx, let.LetTerm) => TermSubsTop(let.LetTerm, let.InTerm),
         Let let => new Let(let.Info, let.Variable, Eval1(ctx, let.LetTerm), let.InTerm),
         Fix fix when IsVal(ctx, fix.Term) => FixVal(fix.Term, t),
         Fix fix => new Fix(fix.Info, Eval1(ctx, fix.Term)),
         Var var => Var(ctx, var),
         Ascribe ascribe when IsVal(ctx, ascribe.Term) => ascribe.Term,
         Ascribe ascribe => new Ascribe(ascribe.Info, Eval1(ctx, ascribe.Term), ascribe.Type),
         Record rec => Record(ctx, rec),
         Proj proj when proj.Term is Record rec && IsVal(ctx, rec) => ProjRec(rec.Fields, proj.Label),
         Proj proj => new Proj(proj.Info, Eval1(ctx, proj.Term), proj.Label),
         TimesFloat tf when tf.Left is Float fl && tf.Right is Float fr => new Float(tf.Info, fl.Value * fr.Value),
         TimesFloat tf when tf.Left is Float => new TimesFloat(tf.Info, tf.Left, Eval1(ctx, tf.Right)),
         TimesFloat tf => new TimesFloat(tf.Info, Eval1(ctx, tf.Left), tf.Right),
         Succ succ => new Succ(succ.Info, Eval1(ctx, succ.Of)),
         Pred p when p.Of is Zero => new Zero(new UnknownInfo()),
         Pred p when p.Of is Succ s && IsNumericVal(ctx, s.Of) => s.Of,
         Pred s => new Pred(s.Info, Eval1(ctx, s.Of)),
         IsZero isZero when isZero.Term is Zero => new True(new UnknownInfo()),
         IsZero isZero when isZero.Term is Succ s && IsNumericVal(ctx, s.Of) => new False(new UnknownInfo()),
         IsZero isZero => new IsZero(isZero.Info, Eval1(ctx, isZero.Term)),
         _ => throw new NoRulesAppliesException()
     };
 }
Esempio n. 19
0
 public string Visit(Succ node)
 {
     return(Visit((dynamic)node[0]) +
            "call string class ['lunklib']'LibLunk'.'Utils'::'Successor'()\n");
 }
Esempio n. 20
0
 public static String FormatSelection <T>(String pSeparator, IList <T> pSelectedItems, Succ <T> Successor, Func <T, T, String> pRangeFormatter = null)
 {
     return(String.Join(",", GetSelectionRanges(pSelectedItems, Successor, pRangeFormatter)));
 }
Esempio n. 21
0
        public static IEnumerable <SelectionRange <T> > GetSelectionRanges <T>(IList <T> pSelectedItems, Succ <T> Successor, Func <T, T, String> pRangeFormatter = null)
        {
            List <T> SelectedItems = (from sel in pSelectedItems orderby sel select sel).ToList();
            List <SelectionRange <T> > ChosenRanges = new List <SelectionRange <T> >();

            for (int i = 0; i < SelectedItems.Count; i++)
            {
                T   StartItem   = SelectedItems[i];
                T   CurrentItem = StartItem;
                int offset      = 0;

                while ((i + offset < (SelectedItems.Count - 1)) && (Successor(CurrentItem).Equals(SelectedItems[i + offset])))
                {
                    CurrentItem = Successor(CurrentItem);
                    offset++;
                }

                if (offset > 0)
                {
                    offset--;
                }

                T EndItem = SelectedItems[i + offset];
                if (offset == 1)
                {
                    ChosenRanges.Add(new SelectionRange <T>(StartItem, StartItem));
                    ChosenRanges.Add(new SelectionRange <T>(EndItem, EndItem));
                }
                else
                {
                    SelectionRange <T> BuildRange = new SelectionRange <T>(StartItem, EndItem, pRangeFormatter);
                    ChosenRanges.Add(BuildRange);
                }

                i += offset;
            }
            return(ChosenRanges);
        }
Esempio n. 22
0
 protected bool IsRearing()
 {
     return(Succ.Length == 8 && Succ.Substring(7, 1).Equals("1"));
 }