Esempio n. 1
0
        public void TestInTask()
        {
            //arrenge
            var input    = @"{
    'data': {
        'a': {
            'x':3.14, 
            'b': {'c':15}, 
            'c': {'c':9}
        }, 
        'z':42
    },
    'queries': [
        'a.b.c',
        'z',
        'a.x'
    ]
}";
            var expected = @"a.b.c = 15
z = 42
a.x = 3.14";
            //act
            var resultFull = "";

            foreach (var result in SimQLProgram.ExecuteQueries(input))
            {
                resultFull += $"{result}\r\n";
            }

            //Assert
            Assert.AreEqual(expected, resultFull.Substring(0, resultFull.Length - 2));
        }
Esempio n. 2
0
        public void SumSingleItem()
        {
            var results = SimQLProgram.ExecuteQueries(
                "{ 'data': {'itemsCount':42, 'foo':'bar'}, " +
                "'queries': ['sum(itemsCount)']}");

            Assert.AreEqual(new[] { 42 }, results);
        }
Esempio n. 3
0
        public void SumEmptyDataToZero()
        {
            var results = SimQLProgram.ExecuteQueries(
                "{" +
                "'data': [], " +
                "'queries': ['sum(item.cost)', 'sum(itemsCount)']}");

            Assert.AreEqual(new[] { 0, 0 }, results);
        }
Esempio n. 4
0
        public void testFrom_example()
        {
            var results = SimQLProgram.ExecuteQueries(
                "{" +
                "'data': {'a': {'x':3.14, 'b': { 'c':15}, 'c': { 'c':9}}, 'z':42 }," +
                "'queries': ['a.b.c', 'z', 'a.x']}");

            Assert.AreEqual(new[] { "a.b.c = 15", "z = 42", "a.x = 3.14" }, results);
        }
Esempio n. 5
0
        public void testShouldBe_Green()
        {
            var results = SimQLProgram.ExecuteQueries(
                "{" +
                "'data': {'empty': {}, 'ab':'0', 'x1': '1', 'x2': '2', 'y1': {'y2': {'y3': '3'}}}, " +
                "'queries': ['empty', 'xyz', 'x1.x2', 'y1.y2.z', 'empty.foobar']}");

            Assert.AreEqual(new string[0], results);
        }
Esempio n. 6
0
        public void ReturnData_WhenCompositePath()
        {
            var str = "{'data': {'a': {'x': 3.14}}," +
                      "'queries':['a.x']}";

            var result = SimQLProgram.ExecuteQueries(str);

            Assert.AreEqual("a.x = 3.14", result.Single());
        }
Esempio n. 7
0
        public void ReturnData()
        {
            var str = "{'data':{'a':4}," +
                      "'queries':['a']}";

            var result = SimQLProgram.ExecuteQueries(str);

            Assert.AreEqual("a = 4", result.Single());
        }
Esempio n. 8
0
        public void SimSQLShould()
        {
            var results =
                SimQLProgram.ExecuteQueries(
                    "{'data':{'empty':{},'ab':0,'x1':1,'x2':2,'y1':{'y2':{'y3':3}}},'queries':['empty','xyz','x1.x2','y1.y2.z','empty.foobar']}");

            Console.WriteLine();
            Assert.AreEqual(new String[] { "empty", "xyz", "x1.x2", "y1.y2.z", "empty.foobar" }, results.ToArray());
        }
Esempio n. 9
0
        public void ReturnValues_WhenGetArrays()
        {
            var str = "{'data': { 'a':{ 'x':3.14, 'b':[{'c':15}, {'c':9}]}, 'z':[2.65, 35]}," +
                      "'queries': ['sum(a.b.c)','min(z)','max(a.x)']}";

            var result = SimQLProgram.ExecuteQueries(str).ToArray();

            Assert.AreEqual(3, result.Length);
            Assert.AreEqual(new[] { "sum(a.b.c) = 24", "min(z) = 2.65", "max(a.x) = 3.14" }, result);
        }
Esempio n. 10
0
        public void FaildTest()
        {
            var str = "{\"data\":{\"empty\":{},\"ab\":0,\"x1\":1,\"x2\":2,\"y1\":{\"y2\":{\"y3\":3}}}," +
                      "\"queries\":[\"empty\",\"xyz\",\"x1.x2\",\"y1.y2.z\",\"empty.foobar\"]}";

            var result = SimQLProgram.ExecuteQueries(str).ToArray();

            Assert.AreEqual(5, result.Length);
            Assert.AreEqual(new [] { "empty", "xyz", "x1.x2", "y1.y2.z", "empty.foobar" }, result);
        }
Esempio n. 11
0
        public void ReturnMultiData()
        {
            var str = "{'data': {'a': 2," +
                      "'x': 3.14}," +
                      "'queries':['a', 'x']}";

            var result = SimQLProgram.ExecuteQueries(str);

            Assert.AreEqual(new [] { "a = 2", "x = 3.14" }, result.ToArray());
        }
Esempio n. 12
0
        public void ReturnValues_InBaseTestQL()
        {
            var str =
                "{\"data\":{\"empty\":[],\"x\":[0.1,0.2,0.3],\"a\":[{\"b\":10,\"c\":[1,2,3]},{\"b\":30,\"c\":[4]},{\"d\":500}]}," +
                "\"queries\":[\"sum(empty)\",\"sum(a.b)\",\"sum(a.c)\",\"sum(a.d)\",\"sum(x)\"]}";

            var result = SimQLProgram.ExecuteQueries(str);

            Assert.AreEqual(5, result.Count());
            Assert.AreEqual(new[] { "sum(empty) = 0", "sum(a.b) = 40", "sum(a.c) = 10", "sum(a.d) = 500", "sum(x) = 0.6" }, result);
        }
Esempio n. 13
0
        public void TestInRelease1()
        {
            //arrenge
            var input    = @"{""data"":{""empty"":{},""ab"":0,""x1"":1,""x2"":2,""y1"":{""y2"":{""y3"":3}}},""queries"":[""empty"",""xyz"",""x1.x2"",""y1.y2.z"",""empty.foobar""]}";
            var expected = @"empty =
xyz = 
x1.x2 = 
y1.y2.z = 
empty.foobar = 
";
            //act
            var resultFull = "";

            foreach (var result in SimQLProgram.ExecuteQueries(input))
            {
                resultFull += $"{result}\r\n";
            }

            //Assert
            Assert.AreEqual(expected, resultFull.Substring(0, resultFull.Length - 2));
        }
Esempio n. 14
0
 public void GetValue_ByQuery(string query, IEnumerable <string> result)
 {
     SimQLProgram.ExecuteQueries(query)
     .ShouldBeEquivalentTo(result);
 }