Esempio n. 1
0
    public static SUnit TranslateMethodCall(Statement statement)
    {
        var expressions = statement.GetExpressions();

        // Give an empty SUnit if statement has no expressions.
        if (expressions.Count() == 0)
        {
            return(new SUnit(SUnitType.SingleMethodCall, "", "", "", new List <string>(), "void"));
        }

        // Build a minimal method context and declaration node required by SWUM.
        var                   exp  = expressions.First();
        string                type = exp.ResolveType().ToString();
        MethodContext         mc   = new MethodContext(type);
        MethodDeclarationNode mdn  = new MethodDeclarationNode(exp.ToString(), mc);

        // Apply the SWUM to our statement
        var swumRule = SetupBaseVerbRule();

        swumRule.InClass(mdn);
        swumRule.ConstructSwum(mdn);

        // Build and return SUnit from the SWUM
        SUnit sunit = new SUnit();

        sunit.action = GetAction(mdn);
        sunit.theme  = GetTheme(mdn);
        sunit.args   = GetArgs(mdn);

        return(sunit);
    }
Esempio n. 2
0
        public async Task ReplaceItem_SoftDelete_DeletedItem_Returns404()
        {
            var item = new SUnit()
            {
                Id = "sunit-7", Data = "Replaced"
            };
            var deleteResponse = await SendRequestToServer <SUnit>(HttpMethod.Delete, $"/tables/sunits/{item.Id}", null);

            Assert.AreEqual(HttpStatusCode.NoContent, deleteResponse.StatusCode);

            var response = await SendRequestToServer <SUnit>(HttpMethod.Put, $"/tables/sunits/{item.Id}", item);

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
Esempio n. 3
0
        public float GetUnitCoef()
        {
            if (SUnit == null)
            {
                SUnit = SaveAndLoad.GetUnit(sunit_id);
            }
            if (SType == null)
            {
                SType = SaveAndLoad.GetSport(stype_id);
            }


            return(SUnit.GetCoef() * (1 + Weight / 10));
        }
Esempio n. 4
0
 // SUnits for soft-delete, HUnits for hard-delete
 public static void SeedSUnits(E2EDbContext context)
 {
     for (var i = 0; i < 20; i++)
     {
         var offset = 180 + (new Random()).Next(180);
         var sunit  = new SUnit
         {
             Id        = $"sunit-{i}",
             Version   = Guid.NewGuid().ToByteArray(),
             UpdatedAt = DateTimeOffset.UtcNow.AddDays(-offset),
             Deleted   = false,
             Data      = $"sunit-{i}"
         };
         context.SUnits.Add(sunit);
     }
 }
Esempio n. 5
0
        public void TestSUnitNoReturnType()
        {
            // a.getPatterns(findString)
            var sunit = new SUnit(SUnitType.SingleMethodCall,
                                    "get",
                                    "patterns",
                                    null,
                                    new List<string>(1){ "findString" },
                                    null );

            Assert.AreEqual(sunit.action, "get");
            Assert.AreEqual(sunit.theme, "patterns");
            Assert.Contains("findString", (System.Collections.ICollection) sunit.args );

            Assert.IsFalse(sunit.hasReturnType);
        }
Esempio n. 6
0
    public void TestTextGenerationForSingleMethodCall()
    {
        // addUser( username, password);
        SUnit sunit = new SUnit(SUnitType.SingleMethodCall,
                                "add",
                                "user",
                                null,
                                new List <string> {
            "username", "password"
        },
                                "void");

        var sentence = TextGenerator.GenerateText(sunit);

        // Allow vaguer assertion and print output
        Assert.AreEqual("Add user given username, password.", sentence);
        Console.WriteLine(sentence);
    }
Esempio n. 7
0
        public void TestSUnitWithReturnType()
        {
            // string foob = FindAndBreakTwoVerbs("blahblahbreak");
            var sunit = new SUnit(  SUnitType.SingleMethodCall,
                                    "Find and Break",
                                    "Two Verbs",
                                    null,
                                    new List<string>(1) { "blahblahbreak" },
                                    "string"
                                    );

            Assert.AreEqual(sunit.action, "Find and Break");
            Assert.AreEqual(sunit.theme, "Two Verbs");
            Assert.Contains("blahblahbreak", (System.Collections.ICollection)sunit.args);

            Assert.IsTrue(sunit.hasReturnType);
            Assert.AreEqual(sunit.returnType, "string");
        }
Esempio n. 8
0
        public void TestSUnitNoReturnType()
        {
            // a.getPatterns(findString)
            var sunit = new SUnit(SUnitType.SingleMethodCall,
                                  "get",
                                  "patterns",
                                  null,
                                  new List <string>(1)
            {
                "findString"
            },
                                  null);

            Assert.AreEqual(sunit.action, "get");
            Assert.AreEqual(sunit.theme, "patterns");
            Assert.Contains("findString", (System.Collections.ICollection)sunit.args);

            Assert.IsFalse(sunit.hasReturnType);
        }
Esempio n. 9
0
        public void TestSUnitWithReturnType()
        {
            // string foob = FindAndBreakTwoVerbs("blahblahbreak");
            var sunit = new SUnit(SUnitType.SingleMethodCall,
                                  "Find and Break",
                                  "Two Verbs",
                                  null,
                                  new List <string>(1)
            {
                "blahblahbreak"
            },
                                  "string"
                                  );

            Assert.AreEqual(sunit.action, "Find and Break");
            Assert.AreEqual(sunit.theme, "Two Verbs");
            Assert.Contains("blahblahbreak", (System.Collections.ICollection)sunit.args);

            Assert.IsTrue(sunit.hasReturnType);
            Assert.AreEqual(sunit.returnType, "string");
        }
Esempio n. 10
0
 /// <summary>
 /// Initial with float and UnitType to Word Base Unit
 /// </summary>
 /// <param name="numerical">Numerical of Unit, like 1 in 1cm</param>
 /// <param name="unitType">UnitType of Unit, like cm in 1cm</param>
 public Unit(float numerical, SUnit unitType = SUnit.Centi)
 {
     _unitType = unitType;
     Numerical = numerical;
 }
Esempio n. 11
0
 /// <summary>
 /// Initial with float and UnitType string to Word Base Unit
 /// </summary>
 /// <param name="numerical">Numerical of Unit, like 1 in 1cm</param>
 /// <param name="unitType">UnitType of Unit, like cm in 1cm</param>
 public Unit(float numerical, string unitType)
 {
     _unitType = (SUnit)Enum.Parse(typeof(SUnit), unitType);
     Numerical = numerical;
 }
Esempio n. 12
0
    private static SUnit TranslateAssignment(Statement statement)
    {
        // action = "Assign"
        // define left-hand-side (lhs)
        // theme = right hand side

        var fieldRule = SetupFieldRule();

        //        var equalsSign = statement.GetDescendants<OperatorUse>()
        //                                .Where(o => o.Text.Equals("=")).First();

        //        var lhs = equalsSign.GetSiblingsBeforeSelf<VariableUse>().First();

        var assignExpression = (VariableDeclaration)statement.GetExpressions().First();
        var lhs = assignExpression.Name;


        var lhsFieldContext = new FieldContext(assignExpression.VariableType.ToString(), false, "");
        var lhsDecNode      = new FieldDeclarationNode(lhs.ToString(), lhsFieldContext);

        fieldRule.InClass(lhsDecNode);
        fieldRule.ConstructSwum(lhsDecNode);

        var        rhsString = "";
        var        rhsAction = "";
        var        rhsTheme  = "";
        Expression rhs       = new Expression();

        if (assignExpression.Initializer != null)
        {
            rhs = assignExpression.Initializer;
        }

        if (rhs is VariableUse)
        {
            var rhsFieldContext = new FieldContext(rhs.ResolveType().First().ToString(), false, "");
            var rhsDecNode      = new FieldDeclarationNode(rhs.ToString(), lhsFieldContext);
            fieldRule.InClass(rhsDecNode);
            fieldRule.ConstructSwum(rhsDecNode);
            rhsAction = "Assign";
            rhsString = rhsDecNode.ToPlainString();
        }
        else if (rhs is MethodCall)
        {
            string type = rhs.ResolveType().ToString();

            MethodContext         mc  = new MethodContext(type);
            MethodDeclarationNode mdn = new MethodDeclarationNode(rhs.ToString(), mc);

            var swumRule = SetupBaseVerbRule();
            swumRule.InClass(mdn);
            swumRule.ConstructSwum(mdn);

            rhsAction = mdn.Action.ToPlainString();
            rhsTheme  = mdn.Action.ToPlainString();
            rhsString = mdn.ToPlainString();
        }
        else
        {
            rhsString = rhs.ToString();
        }


        var sunit = new SUnit();

        sunit.type   = SUnitType.Assignment;
        sunit.action = rhsString;
        //sunit.lhs = lhsDecNode.ToPlainString();
        sunit.lhs   = lhs.ToString();
        sunit.theme = rhsString;

        return(sunit);
    }