public static void Main(string[] args) { CollisionEntry[] collisions = CollisionEntry.ReadCollisionsFromFile(args[0]); RulesGenerator gen = new RulesGenerator(args[1]); C4p5 alg = new C4p5(collisions.ToList(), gen.CurrentRules); if (args.Length == 4) { if (args[3] == "-o") { alg.LearnOrTree(alg.Root); alg.PrintRules(args[2]); return; } else { C4p5.SetHeaderToPredict(args[3]); } } Node root = alg.Root; C4p5.MaxDepth = 4; C4p5.MinDivSize = 10000; alg.Learn(); alg.PrintRules(args[2]); }
private static IEnumerable <TestCaseData> GenerateRulesApplierCases() { var noUnpackRules = RulesGenerator.GenerateValidRules(false); var noUnpackRights = noUnpackRules .Select(rule => new Rights(rule.PlatformAccesses, rule.ProductAccesses)) .ToList(); var withUnpackRules = RulesGenerator.GenerateValidRules(true); var withExtraProduct = RulesGenerator.GenerateValidRules(false); withExtraProduct[0].ProductAccesses[Platform.Support].Add("Unknown", Role.RoleII); var specifiedRoleAndAllFlag = RulesGenerator.GenerateValidRules(true); specifiedRoleAndAllFlag[0].ProductAccesses[Platform.Support]["Product1"] = Role.Admin; var rightsForSpecifiedRole = GetRightWithAllFlag(); rightsForSpecifiedRole[0].ProductAccesses[Platform.Support]["Product1"] = Role.Admin; yield return(new TestCaseData(new List <Rule>(), new List <Rights>()) .SetName("Нет правил для применения. Возвращает пустой лист")); yield return(new TestCaseData(noUnpackRules, noUnpackRights) .SetName("Нет флага All. Успех")); yield return(new TestCaseData(withExtraProduct, noUnpackRights) .SetName("Продукт, которого нет в списке. Игнорирует этот продукт")); yield return(new TestCaseData(withUnpackRules, GetRightWithAllFlag()) .SetName("Есть флаг All. Успех")); yield return(new TestCaseData(specifiedRoleAndAllFlag, rightsForSpecifiedRole) .SetName("Роль, указанная в All, имеет наименьший приоретет")); }
public void TestRulesValidatorOnInvalidRules(bool wrongPlatformAccesses) { var invalidRules = RulesGenerator.GenerateInvalidRules(wrongPlatformAccesses); foreach (var rule in invalidRules) { validator.IsValid(rule).Should().BeFalse(); } }
public void TestRulesValidatorOnValidRules(bool allProductsFlag) { var validRules = RulesGenerator.GenerateValidRules(allProductsFlag); foreach (var rule in validRules) { validator.IsValid(rule).Should().BeTrue(); } }
private static IEnumerable <TestCaseData> GenerateRulesReaderSuccesses() { var currentDirectory = System.AppDomain.CurrentDomain.BaseDirectory; var rulesDirectory = Path.Combine(currentDirectory, "Rules"); var validRulesDirectory = Path.Combine(rulesDirectory, "Valid"); var testRules = RulesGenerator.GenerateValidRules(true); var multipleRules = RulesGenerator.GenerateMultipleRules(); yield return(new TestCaseData( Path.Combine(validRulesDirectory, "TestRules.xml"), testRules ).SetName("Корректный файл. Успех")); yield return(new TestCaseData( Path.Combine(validRulesDirectory, "MultipleRules.xml"), multipleRules ).SetName("Множественные правила в одном файле. Успех")); yield return(new TestCaseData( validRulesDirectory, testRules.Concat(multipleRules).ToList() ).SetName("Чтение всех правил в директории. Успех")); }
public static void GenerateComplexeGridRules() { RulesGenerator.workingStringBuilder.Clear(); for (int i = 0; i < 3; ++i) { RuleDefinitionGrid rowRule = ScriptableObject.CreateInstance <RuleDefinitionGrid>(); RuleDefinitionGrid colRule = ScriptableObject.CreateInstance <RuleDefinitionGrid>(); for (int j = 0; j < 9; ++j) { rowRule.AllowedCells[j] = (j / 3 != i); colRule.AllowedCells[j] = (j % 3 != i); } string rowRuleName = $"GridRules_Row_{i + 1}"; RulesGenerator.CreateAssetsFromGridRule("GridRules/Simple", rowRule, rowRuleName); string colRuleName = $"GridRules_Col_{i + 1}"; RulesGenerator.CreateAssetsFromGridRule("GridRules/Simple", colRule, colRuleName); } RuleDefinitionGrid antiSlash = ScriptableObject.CreateInstance <RuleDefinitionGrid>(); antiSlash.AllowedCells = new bool[] { false, true, true, true, false, true, true, true, false, }; RuleDefinitionGrid slashRule = ScriptableObject.CreateInstance <RuleDefinitionGrid>(); slashRule.AllowedCells = new bool[] { true, true, false, true, false, true, false, true, true, }; RulesGenerator.CreateAssetsFromGridRule("GridRules/Simple", antiSlash, "GridRules_AntiSlash"); RulesGenerator.CreateAssetsFromGridRule("GridRules/Simple", slashRule, "GridRules_Slash"); for (int x = 0; x < 3; ++x) { for (int y = 0; y < 3; ++y) { RuleDefinitionGrid gridRule = ScriptableObject.CreateInstance <RuleDefinitionGrid>(); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { gridRule.AllowedCells[i + j * 3] = !(i == x || j == y); } } string ruleName = $"GridRules_Col_{x + 1}_row{y + 1}"; RulesGenerator.CreateAssetsFromGridRule("GridRules/Complex", gridRule, ruleName); } } for (int i = 0; i < 3; ++i) { { RuleDefinitionGrid slashColRule = ScriptableObject.CreateInstance <RuleDefinitionGrid>(); slashColRule.AllowedCells = new bool[] { true, true, false, true, false, true, false, true, true, }; slashColRule.AllowedCells[i] = false; slashColRule.AllowedCells[i + 3] = false; slashColRule.AllowedCells[i + 6] = false; string ruleName = $"slash_Col_{i + 1}"; RulesGenerator.CreateAssetsFromGridRule("GridRules/Complex", slashColRule, ruleName); } { RuleDefinitionGrid slashRowRule = ScriptableObject.CreateInstance <RuleDefinitionGrid>(); slashRowRule.AllowedCells = new bool[] { true, true, false, true, false, true, false, true, true, }; slashRowRule.AllowedCells[i * 3] = false; slashRowRule.AllowedCells[i * 3 + 1] = false; slashRowRule.AllowedCells[i * 3 + 2] = false; string ruleName = $"slash_Row_{i + 1}"; RulesGenerator.CreateAssetsFromGridRule("GridRules/Complex", slashRowRule, ruleName); } { RuleDefinitionGrid antislashColRule = ScriptableObject.CreateInstance <RuleDefinitionGrid>(); antislashColRule.AllowedCells = new bool[] { false, true, true, true, false, true, true, true, false, }; antislashColRule.AllowedCells[i] = false; antislashColRule.AllowedCells[i + 3] = false; antislashColRule.AllowedCells[i + 6] = false; string ruleName = $"antislash_Col_{i + 1}"; RulesGenerator.CreateAssetsFromGridRule("GridRules/Complex", antislashColRule, ruleName); } { RuleDefinitionGrid antislashRowRule = ScriptableObject.CreateInstance <RuleDefinitionGrid>(); antislashRowRule.AllowedCells = new bool[] { false, true, true, true, false, true, true, true, false, }; antislashRowRule.AllowedCells[i * 3] = false; antislashRowRule.AllowedCells[i * 3 + 1] = false; antislashRowRule.AllowedCells[i * 3 + 2] = false; string ruleName = $"antislash_Row_{i + 1}"; RulesGenerator.CreateAssetsFromGridRule("GridRules/Complex", antislashRowRule, ruleName); } } UnityEditor.AssetDatabase.SaveAssets(); TextEditor te = new TextEditor(); te.text = RulesGenerator.workingStringBuilder.ToString(); te.SelectAll(); te.Copy(); Debug.Log($"Copied {RulesGenerator.workingStringBuilder.ToString()}"); }