Ejemplo n.º 1
0
    public void Resolve_ThreeReds()
    {
        var constraint = new ResponseConstraint(new[] { Orange, Yellow, Teal, Purple }, new Response {
            RedCount = 3
        });
        var scenario = GetScenario(Orange, null, Yellow, Purple);

        Assert.True(constraint.Resolve(scenario));
        Assert.Equal(Yellow, scenario[1]);
    }
Ejemplo n.º 2
0
    public void GetHashCode_Test()
    {
        var constraint1a = new ResponseConstraint(new CodeColor[Rules.CodeSize], default);
        var constraint1b = new ResponseConstraint(new CodeColor[Rules.CodeSize], default);
        var constraint2  = new ResponseConstraint(new CodeColor[Rules.CodeSize], new Response {
            RedCount = 2
        });

        Assert.Equal(constraint1a.GetHashCode(), constraint1b.GetHashCode());
        Assert.NotEqual(constraint1a.GetHashCode(), constraint2.GetHashCode());
    }
Ejemplo n.º 3
0
    public void Equality_Object()
    {
        var constraint1a = new ResponseConstraint(new CodeColor[Rules.CodeSize], default);
        var constraint1b = new ResponseConstraint(new CodeColor[Rules.CodeSize], default);
        var constraint2  = new ResponseConstraint(new CodeColor[Rules.CodeSize], new Response {
            RedCount = 2
        });

        Assert.True(constraint1a.Equals((object)constraint1b));
        Assert.False(constraint1a.Equals((object)constraint2));
    }
Ejemplo n.º 4
0
    public void Resolve_TwoReds()
    {
        var constraint = new ResponseConstraint(new[] { Orange, Yellow, Teal, Purple }, new Response {
            RedCount = 2
        });

        var scenario = GetScenario(Orange, null, Purple, Teal);

        Assert.True(constraint.Resolve(scenario));
        Assert.Equal(Yellow, scenario[1]);

        Assert.False(constraint.Resolve(new Scenario <CodeColor>(Rules.Nodes)));
    }
Ejemplo n.º 5
0
    public void Equality()
    {
        var constraint1a = new ResponseConstraint(new CodeColor[Rules.CodeSize], default);
        var constraint1b = new ResponseConstraint(new CodeColor[Rules.CodeSize], default);
        var constraint2  = new ResponseConstraint(new CodeColor[Rules.CodeSize], new Response {
            RedCount = 2
        });
        var constraint3 = new ResponseConstraint(new CodeColor[Rules.CodeSize] {
            Magenta, Yellow, White, Orange
        }, new Response {
            RedCount = 2
        });

        Assert.Equal(constraint1a, constraint1b);
        Assert.NotEqual(constraint1a, constraint2);
        Assert.NotEqual(constraint1a, constraint3);
        Assert.NotEqual(constraint2, constraint3);
    }
Ejemplo n.º 6
0
    public void GetState_TwoReds()
    {
        var constraint = new ResponseConstraint(new[] { Orange, Yellow, Teal, Purple }, new Response {
            RedCount = 2
        });

        // Three exact matches is an invalid solution.
        var result = constraint.GetState(GetScenario(Orange, Yellow, White, Purple));

        Assert.Equal(ConstraintStates.Resolved, result);

        // Only one position is the same as the original guess, so it is not satisfiable.
        result = constraint.GetState(GetScenario(White, Orange, Yellow, Purple));
        Assert.Equal(ConstraintStates.Resolved, result);

        // There are two indeterminate nodes, so it can be satisfied.
        result = constraint.GetState(GetScenario(White, Orange, null, null));
        Assert.Equal(ConstraintStates.Satisfiable | ConstraintStates.Breakable | ConstraintStates.Resolvable, result);

        // One node matches, one is indeterminate.
        result = constraint.GetState(GetScenario(Orange, null, Purple, Teal));
        Assert.Equal(ConstraintStates.Satisfiable | ConstraintStates.Breakable | ConstraintStates.Resolvable, result);
    }