예제 #1
0
        public void WhenYOfConstraintIsNull_ThenThrowException()
        {
            var variables = new List <Variable>()
            {
                new Variable("A", null)
            };
            var domains = new List <Domain>
            {
                new Domain("red", 1)
            };
            var constraints = new List <Constraint>
            {
                new Constraint(1, variables[0], CompareEnum.Greater, null)
            };

            try
            {
                var isValid = CSPValidator.Validate(variables, domains, constraints, true);
            }
            catch (Exception e)
            {
                Approvals.Verify(e.Message);
                return;
            }
            Assert.Fail();
        }
예제 #2
0
        private void Run()
        {
            try
            {
                Info = "";
                var constraints = new List <Constraint>();
                int i           = 0;
                foreach (var item in ConstraintItems)
                {
                    constraints.Add(new Constraint(i, item.SelectedVariable1, item.SelectedComparator, item.SelectedVariable2));
                    i++;
                }

                foreach (var variable in _allVariables)
                {
                    variable.Value = null;
                }

                if (!CSPValidator.Validate(_allVariables, _allDomains, constraints, IsPairwiseDisjunct))
                {
                    return;
                }
                LoadVisibility = Visibility.Visible;
                if (!_worker.IsBusy)
                {
                    _watch.Start();
                    _worker.RunWorkerAsync(constraints);
                }
            }
            catch (Exception e)
            {
                Info = e.Message;
            }
        }
예제 #3
0
 public void WhenVariablesPairwiseDisjunctAndTooLessDomains_ThenThrowException()
 {
     try
     {
         CSPValidator.Validate(new List <Variable> {
             new Variable("a", null), new Variable("b", null)
         },
                               new List <Domain> {
             new Domain("x", 1)
         }, null, true);
     }
     catch (Exception e)
     {
         Approvals.Verify(e.Message);
         return;
     }
     Assert.Fail("no exception thrown");
 }
예제 #4
0
        public void GivenAValidCSP_ThenResultShouldBeTrue()
        {
            var variables = new List <Variable>()
            {
                new Variable("A", null),
                new Variable("B", null),
                new Variable("C", null)
            };
            var domains = new List <Domain>
            {
                new Domain("red", 1),
                new Domain("green", 2),
                new Domain("blue", 3)
            };
            var constraints = new List <Constraint>
            {
                new Constraint(1, variables[0], CompareEnum.Greater, variables[1]),
                new Constraint(2, variables[1], CompareEnum.Greater, variables[2]),
                new Constraint(3, variables[2], CompareEnum.Smaller, variables[0])
            };
            var isValid = CSPValidator.Validate(variables, domains, constraints, true);

            Assert.IsTrue(isValid);
        }