Exemplo n.º 1
0
        public void PerlinNoiseNodeToDebugNodeParsedCommands()
        {
            var builder = PWGraphBuilder.NewGraph <PWMainGraph>()
                          .NewNode(typeof(PWNodePerlinNoise2D), "perlin")
                          .NewNode(typeof(PWNodeDebugInfo), "debug")
                          .Link("perlin", "debug");

            //list of the expected created commands
            List <PWGraphCommand> expectedCommands = new List <PWGraphCommand>()
            {
                new PWGraphCommand(typeof(PWNodePerlinNoise2D), "perlin"),
                new PWGraphCommand(typeof(PWNodeDebugInfo), "debug"),
                new PWGraphCommand("perlin", "debug"),
            };

            //get the commands as string
            var builderCommands = builder.GetCommands();

            for (int i = 0; i < expectedCommands.Count; i++)
            {
                //Parse the command and get the resulting command object
                PWGraphCommand cmd = PWGraphCLI.Parse(builderCommands[i]);

                Assert.That(cmd == expectedCommands[i]);
            }
        }
Exemplo n.º 2
0
        public void WhiteSpaceLinkCommand()
        {
            PWGraphCommand cmd = PWGraphCLI.Parse("    	 	 	Link 		 	 node1   	node2	 	      ");

            Assert.That(cmd.type == PWGraphCommandType.Link);
            Assert.That(cmd.fromNodeName == "node1");
            Assert.That(cmd.toNodeName == "node2");
        }
Exemplo n.º 3
0
 public void UnknowCommand()
 {
     try {
         PWGraphCLI.Parse("BlaBlaBla arg1 arg2");
         throw new Exception("no exception was thrown by unknow command");
     } catch {
         //the exception was thrown so the commmand works as excpected
     }
 }
Exemplo n.º 4
0
        public void WellFormatedLinkCommandNameWhitespaces()
        {
            string         s   = PWGraphCLI.GenerateLinkCommand("node 1", "node 2");
            PWGraphCommand cmd = PWGraphCLI.Parse(s);

            Assert.That(cmd.type == PWGraphCommandType.Link);
            Assert.That(cmd.fromNodeName == "node 1");
            Assert.That(cmd.toNodeName == "node 2");
        }
Exemplo n.º 5
0
 public void missingNameNewNodeCommand()
 {
     try {
         PWGraphCLI.Parse("NewNode PWNodeAdd");
     } catch {
         return;
     }
     throw new Exception("Missing name in newNode command did't throw an exception");
 }
Exemplo n.º 6
0
 public void EmptyCommand()
 {
     try {
         PWGraphCLI.Parse("");
         throw new Exception("no exception was thrown by an empty command");
     } catch {
         //the exception was thrown so the commmand works as excpected
     }
 }
Exemplo n.º 7
0
        public void WhiteSpaceNewNodeWithPositionCommand()
        {
            PWGraphCommand cmd = PWGraphCLI.Parse("  	  NewNode 	      PWNodeAdd  	    add  	    (  	 42,   -42 	   )	 ");

            Assert.That(cmd.type == PWGraphCommandType.NewNodePosition);
            Assert.That(cmd.nodeType == typeof(PWNodeAdd));
            Assert.That(cmd.name == "add");
            Assert.That(cmd.forcePositon == true);
            Assert.That(cmd.position == new Vector2(42, -42));
        }
Exemplo n.º 8
0
        public void WellFormatedWhitespaceNewNodeCommand()
        {
            string         s   = PWGraphCLI.GenerateNewNodeCommand(typeof(PWNodeAdd), "add node name");
            PWGraphCommand cmd = PWGraphCLI.Parse(s);

            Assert.That(cmd.type == PWGraphCommandType.NewNode);
            Assert.That(cmd.nodeType == typeof(PWNodeAdd));
            Assert.That(cmd.name == "add node name");
            Assert.That(cmd.forcePositon == false);
        }
Exemplo n.º 9
0
        public void BadTypeNewNodeCommand()
        {
            try {
                PWGraphCLI.Parse("NewNode PWNodeUnknown unknown");
            } catch {
                //the exception was thrown so the commmand works as excpected
                return;
            }

            throw new Exception("Unknow node type in newNode command didn't throw an exception");
        }
Exemplo n.º 10
0
        public void WellFormatedNewNodeWithPositionCommand()
        {
            string         s   = PWGraphCLI.GenerateNewNodeCommand(typeof(PWNodeAdd), "addName", new Vector2(42, -42));
            PWGraphCommand cmd = PWGraphCLI.Parse(s);

            Assert.That(cmd.type == PWGraphCommandType.NewNodePosition, "Bad command type: " + cmd.type + " instead of " + PWGraphCommandType.NewNodePosition);
            Assert.That(cmd.nodeType == typeof(PWNodeAdd), "Bad node type: " + cmd.nodeType + " instead of " + typeof(PWNodeAdd));
            Assert.That(cmd.name == "addName", "Bad node name: " + cmd.name + " instead of addName");
            Assert.That(cmd.forcePositon == true, "Forceposition is false but expected to be true");
            Assert.That(cmd.position == new Vector2(42, -42), "Bad node position: " + cmd.position + " instead of " + new Vector2(42, -42));
        }
Exemplo n.º 11
0
        public void WellFormatedLinkAnchorNameCommand()
        {
            string         s   = PWGraphCLI.GenerateLinkAnchorNameCommand("node1", "a1", "node2", "a2");
            PWGraphCommand cmd = PWGraphCLI.Parse(s);

            Assert.That(cmd.type == PWGraphCommandType.LinkAnchorName);
            Assert.That(cmd.fromNodeName == "node1");
            Assert.That(cmd.toNodeName == "node2");
            Assert.That(cmd.fromAnchorFieldName == "a1");
            Assert.That(cmd.toAnchorFieldName == "a2");
        }
Exemplo n.º 12
0
        public void WellFormatedLinkAnchorCommandNameWhitespaces()
        {
            string         s   = PWGraphCLI.GenerateLinkAnchorCommand("node 1", 1, "node 2", 4);
            PWGraphCommand cmd = PWGraphCLI.Parse(s);

            Assert.That(cmd.type == PWGraphCommandType.LinkAnchor);
            Assert.That(cmd.fromNodeName == "node 1");
            Assert.That(cmd.toNodeName == "node 2");
            Assert.That(cmd.fromAnchorIndex == 1);
            Assert.That(cmd.toAnchorIndex == 4);
        }
Exemplo n.º 13
0
        public void WhiteSpaceNewNodeCommand()
        {
            PWGraphCommand cmd;

            cmd = PWGraphCLI.Parse("  	  NewNode 	      PWNodeAdd  	    add  	    	 ");

            Assert.That(cmd.type == PWGraphCommandType.NewNode);
            Assert.That(cmd.nodeType == typeof(PWNodeAdd));
            Assert.That(cmd.name == "add");
            Assert.That(cmd.forcePositon == false);
        }
Exemplo n.º 14
0
        public void TooManyArgumentsNewNodeCommand()
        {
            try {
                PWGraphCLI.Parse("NewNode PWNodeAdd node node node node");
            } catch {
                //the exception was thrown so the commmand works as excpected
                return;
            }

            throw new Exception("too many arguments in newNode command didn't throw an exception");
        }
Exemplo n.º 15
0
        public void PWGraphExport()
        {
            var graph = TestUtils.GenerateTestMainGraph();

            graph.Export(tmpFilePath);

            string[] lines = File.ReadAllLines(tmpFilePath);

            foreach (var line in lines)
            {
                PWGraphCLI.Parse(line);
            }
        }
Exemplo n.º 16
0
        public void WellFormatedNewNodeWithPositionAndDataCommand()
        {
            string s = PWGraphCLI.GenerateNewNodeCommand(typeof(PWNodePerlinNoise2D), "perlin noise", new Vector2(21, 84), new PWGraphCLIAttributes()
            {
                { "persistance", 1.4f }, { "octaves", 2 }
            });
            PWGraphCommand cmd = PWGraphCLI.Parse(s);

            var parsedAttrs     = PWJson.Parse(cmd.attributes);
            var persistanceAttr = parsedAttrs[0];
            var octavesAttr     = parsedAttrs[1];

            Assert.That(persistanceAttr.first == "persistance", "The persistance name expected to be 'persistance' but was '" + persistanceAttr.first + "'");
            Assert.That((float)persistanceAttr.second == 1.4f, "The persistance value expected to be 1.4 but was '" + persistanceAttr.second + "'");
            Assert.That(octavesAttr.first == "octaves", "The octaves name expected to be 'octaves' but was '" + octavesAttr.first + "'");
            Assert.That((int)octavesAttr.second == 2, "The octaves value expected to be 2 but was '" + octavesAttr.second + "'");
        }
Exemplo n.º 17
0
        public void SliderNodeToAddNodeWithAnchorLink()
        {
            var builder = PWGraphBuilder.NewGraph <PWMainGraph>()
                          .NewNode <PWNodeSlider>("s1")
                          .NewNode <PWNodeSlider>("s2")
                          .NewNode <PWNodeSlider>("s3")
                          .NewNode <PWNodeSlider>("s4")
                          .NewNode <PWNodeAdd>("add")
                          .Link("s1", "outValue", "add", "values")
                          .Link("s2", "outValue", "add", "values")
                          .Link("s3", 1, "add", 1)
                          .Link("s4", 1, "add", 1);

            var expectedCommands = new List <PWGraphCommand>()
            {
                new PWGraphCommand(typeof(PWNodeSlider), "s1"),
                new PWGraphCommand(typeof(PWNodeSlider), "s2"),
                new PWGraphCommand(typeof(PWNodeSlider), "s3"),
                new PWGraphCommand(typeof(PWNodeSlider), "s4"),
                new PWGraphCommand(typeof(PWNodeAdd), "add"),
                new PWGraphCommand("s1", "outValue", "add", "values"),
                new PWGraphCommand("s2", "outValue", "add", "values"),
                new PWGraphCommand("s3", 1, "add", 1),
                new PWGraphCommand("s4", 1, "add", 1),
            };

            var commands = builder.GetCommands();

            for (int i = 0; i < expectedCommands.Count; i++)
            {
                //Parse the command and get the resulting command object
                PWGraphCommand cmd = PWGraphCLI.Parse(commands[i]);

                Assert.That(cmd == expectedCommands[i]);
            }
        }