Ejemplo n.º 1
0
        public void AssignmentXUpStream()
        {
            var x = new WTF.TypeProblem2(new TestScopeConverter());

            var m1 = x.CreateMember(x.Root, new NameKey("m1"), new TestMemberConverter(new NameKey("m1")));
            var m2 = x.CreateMember(x.Root, new NameKey("m2"), new TestMemberConverter(new NameKey("m2")));
            var m3 = x.CreateMember(x.Root, new NameKey("m3"), new TestMemberConverter(new NameKey("m3")));
            var m4 = x.CreateMember(x.Root, new NameKey("m4"), new TestMemberConverter(new NameKey("m4")));

            x.CreateHopefulMember(m4, new NameKey("x"), new TestMemberConverter(new NameKey("x")));
            var m5 = x.CreateMember(x.Root, new NameKey("m5"), new TestMemberConverter(new NameKey("m5")));

            x.CreateHopefulMember(m5, new NameKey("y"), new TestMemberConverter(new NameKey("y")));

            m1.AssignTo(m3);
            m2.AssignTo(m3);
            m3.AssignTo(m4);
            m3.AssignTo(m5);

            var solution = x.Solve(new TestExplictTypeConverter());

            HasCount(2, MemberToType(solution.GetMember(m1).GetValue()));
            HasCount(2, MemberToType(solution.GetMember(m2).GetValue()));
            HasCount(2, MemberToType(solution.GetMember(m3).GetValue()));
            HasCount(1, MemberToType(solution.GetMember(m4).GetValue()));
            HasCount(1, MemberToType(solution.GetMember(m5).GetValue()));
        }
Ejemplo n.º 2
0
        public void AddType()
        {
            var x        = new WTF.TypeProblem2(new TestScopeConverter());
            var hello    = x.CreateType(x.Root, new NameKey("Hello"), new TestExplictTypeConverter());
            var hello_x  = x.CreateMember(hello, new NameKey("x"), new TestMemberConverter(new NameKey("x")));
            var hello_y  = x.CreateMember(hello, new NameKey("y"), new TestMemberConverter(new NameKey("y")));
            var solution = x.Solve(new TestExplictTypeConverter());

            var resultHello = solution.GetExplicitType(hello).GetValue();

            HasCount(2, resultHello);
            HasMember(resultHello, new NameKey("x"));
            HasMember(resultHello, new NameKey("y"));
        }
Ejemplo n.º 3
0
        public void AddMethod()
        {
            var x = new WTF.TypeProblem2(new TestScopeConverter());

            var hello   = x.CreateType(x.Root, new NameKey("hello"), new TestExplictTypeConverter());
            var hello_x = x.CreateMember(hello, new NameKey("x"), new TestMemberConverter(new NameKey("x")));
            var hello_y = x.CreateMember(hello, new NameKey("y"), new TestMemberConverter(new NameKey("y")));

            var input  = x.CreateValue(x.Root, new NameKey("hello"), new TestValueConverter());
            var method = x.CreateMethod(x.Root, "input", new TestMethodConverter(), new TestMemberConverter(new NameKey("input")), new TestMemberConverter(new NameKey("result")));

            var input_x = x.CreateHopefulMember(method.Input(), new NameKey("x"), new TestMemberConverter(new NameKey("x")));
            var input_y = x.CreateHopefulMember(method.Input(), new NameKey("y"), new TestMemberConverter(new NameKey("y")));

            var method_x = x.CreateMember(method, new NameKey("x"), new TestMemberConverter(new NameKey("x")));
            var method_y = x.CreateMember(method, new NameKey("y"), new TestMemberConverter(new NameKey("y")));

            input_x.AssignTo(method_x);
            input_y.AssignTo(method_y);

            method.Input().AssignTo(method.Returns());

            input.AssignTo(method.Input());

            var result = x.Solve(new TestExplictTypeConverter());

            var methodResult = result.GetMethod(method).GetValue();

            HasCount(4, methodResult);
            HasMember(methodResult, new NameKey("x"));
            HasMember(methodResult, new NameKey("y"));
            var inputResult = MemberToType(HasMember(methodResult, new NameKey("input")));

            HasCount(2, inputResult);
            HasMember(inputResult, new NameKey("x"));
            HasMember(inputResult, new NameKey("y"));

            var helloResult = result.GetExplicitType(hello).GetValue();

            HasCount(2, helloResult);
            HasMember(helloResult, new NameKey("x"));
            HasMember(helloResult, new NameKey("y"));

            // things don't flow downstream
            var methodReturns = MemberToType(result.GetMember(method.Returns()).GetValue());

            HasCount(0, methodReturns);
        }
Ejemplo n.º 4
0
        public void AssignmentMutual()
        {
            var x = new WTF.TypeProblem2(new TestScopeConverter());

            var m1 = x.CreateMember(x.Root, new NameKey("m1"), new TestMemberConverter(new NameKey("m1")));

            x.CreateHopefulMember(m1, new NameKey("x"), new TestMemberConverter(new NameKey("x")));
            var m2 = x.CreateMember(x.Root, new NameKey("m2"), new TestMemberConverter(new NameKey("m2")));

            x.CreateHopefulMember(m2, new NameKey("y"), new TestMemberConverter(new NameKey("y")));

            m1.AssignTo(m2);
            m2.AssignTo(m1);

            var solution = x.Solve(new TestExplictTypeConverter());

            HasCount(2, MemberToType(solution.GetMember(m1).GetValue()));
            HasCount(2, MemberToType(solution.GetMember(m2).GetValue()));
        }