Esempio n. 1
0
        public void NodeIsNotLeaf()
        {
            var sut    = RoseTree.Node <Version, Guid>(new Version(2, 0));
            var actual = sut.IsLeaf();

            Assert.False(actual.ToBool());
        }
Esempio n. 2
0
        public void NodeIsNode()
        {
            var sut =
                RoseTree.Node <Guid, Version>(
                    new Guid(0x90B5DF4F, 0xE996, 0x416E, 0xB6, 0x77, 0xEF, 0x4F, 0x38, 0x5E, 0x03, 0xC3));
            var actual = sut.IsNode();

            Assert.True(actual.ToBool());
        }
Esempio n. 3
0
        public void MatchNode()
        {
            IRoseTree <string, int> tree =
                RoseTree.Node("foo",
                              new RoseLeaf <string, int>(42),
                              new RoseLeaf <string, int>(1337));
            int actual = tree.Accept(new MatchStringNodeVisitor());

            Assert.Equal(3, actual);
        }
Esempio n. 4
0
        public void CataNode()
        {
            IRoseTree <string, int> tree =
                RoseTree.Node(
                    "foo",
                    new RoseLeaf <string, int>(42),
                    new RoseLeaf <string, int>(1337));
            int actual = tree.Cata((x, xs) => x.Length + xs.Sum(), x => x);

            Assert.Equal(1382, actual);
        }
Esempio n. 5
0
        public void UseMeertensTree()
        {
            IRoseTree <Unit, int> meertensTree =
                RoseTree.Node(Unit.Instance,
                              RoseTree.Node(Unit.Instance,
                                            RoseTree.Node(Unit.Instance,
                                                          new RoseLeaf <Unit, int>(2112)),
                                            new RoseLeaf <Unit, int>(42),
                                            new RoseLeaf <Unit, int>(1337),
                                            new RoseLeaf <Unit, int>(90125)),
                              RoseTree.Node(Unit.Instance,
                                            new RoseLeaf <Unit, int>(1984)),
                              new RoseLeaf <Unit, int>(666));

            Assert.False(meertensTree.IsLeaf().ToBool());
        }
Esempio n. 6
0
        public void MenuExample()
        {
            IRoseTree <string, string> editMenuTemplate =
                RoseTree.Node("Edit",
                              RoseTree.Node("Find and Replace",
                                            new RoseLeaf <string, string>("Find"),
                                            new RoseLeaf <string, string>("Replace")),
                              RoseTree.Node("Case",
                                            new RoseLeaf <string, string>("Upper"),
                                            new RoseLeaf <string, string>("Lower")),
                              new RoseLeaf <string, string>("Cut"),
                              new RoseLeaf <string, string>("Copy"),
                              new RoseLeaf <string, string>("Paste"));

            var commandStore = new CommandStore();
            IRoseTree <string, Command> editMenu =
                from name in editMenuTemplate
                select commandStore.Lookup(name);

            var roundTripped = from command in editMenu
                               select command.Name;

            Assert.Equal(editMenuTemplate, roundTripped);
        }