public void ValidateFixedBranches7() { Setup(TestUtil.GetTestFile("relay\\gaffle.ppen")); FixedBranchAssignments branchAssignments = new FixedBranchAssignments(); branchAssignments.AddBranchAssignment('D', 0); branchAssignments.AddBranchAssignment('H', 1); branchAssignments.AddBranchAssignment('I', 0); branchAssignments.AddBranchAssignment('I', 2); List <string> errors; RelayVariations relayVariations = new RelayVariations(eventDB, CourseId(4), new RelaySettings(10, 3)); FixedBranchAssignments result = relayVariations.ValidateFixedBranches(branchAssignments, out errors); FixedBranchAssignments expected = new FixedBranchAssignments(); branchAssignments.AddBranchAssignment('D', 0); branchAssignments.AddBranchAssignment('H', 1); branchAssignments.AddBranchAssignment('I', 2); Assert.AreEqual(1, errors.Count); Assert.AreEqual("Leg 1 never reaches branch 'I': it was assigned to go a different way in a containing fork.", errors[0]); Assert.AreEqual(expected, result); }
public void ValidateFixedBranches3() { Setup(TestUtil.GetTestFile("relay\\relay.ppen")); // No Assignments. FixedBranchAssignments branchAssignments = new FixedBranchAssignments(); branchAssignments.AddBranchAssignment('D', 1); branchAssignments.AddBranchAssignment('D', 2); branchAssignments.AddBranchAssignment('E', 2); branchAssignments.AddBranchAssignment('E', 3); List <string> errors; RelayVariations relayVariations = new RelayVariations(eventDB, CourseId(4), new RelaySettings(1, 6)); FixedBranchAssignments result = relayVariations.ValidateFixedBranches(branchAssignments, out errors); FixedBranchAssignments expected = new FixedBranchAssignments(); expected.AddBranchAssignment('D', 1); expected.AddBranchAssignment('D', 2); expected.AddBranchAssignment('E', 3); Assert.AreEqual(1, errors.Count); Assert.AreEqual("Leg 3 is assigned to both branch 'D' and branch 'E'", errors[0]); Assert.AreEqual(expected, result); }
public VariationInfoEventArgs(int firstTeamNumber, int numberOfTeams, int numberOfLegs, FixedBranchAssignments fixedBranchAssignments) { FirstTeamNumber = firstTeamNumber; NumberOfTeams = numberOfTeams; NumberOfLegs = numberOfLegs; FixedBranchAssignments = fixedBranchAssignments; }
public void FixedBranches7() { Setup(TestUtil.GetTestFile("relay\\relay.ppen")); FixedBranchAssignments fixedBranchAssignments = new FixedBranchAssignments(); fixedBranchAssignments.AddBranchAssignment('B', 6); var teamAssignment = new RelayVariations(eventDB, CourseId(1), new RelaySettings(30, 7, fixedBranchAssignments)); ValidateRelayVariationsTest(teamAssignment, "relay\\complexfixed"); }
public void FixedBranchAssignmentsEquals() { FixedBranchAssignments a = new FixedBranchAssignments(); a.AddBranchAssignment('A', 1); a.AddBranchAssignment('B', 2); a.AddBranchAssignment('B', 3); FixedBranchAssignments other = a.Clone(); Assert.IsTrue(a.Equals(other)); }
public void FixedBranches1() { Setup(TestUtil.GetTestFile("relay\\relay.ppen")); FixedBranchAssignments fixedBranchAssignments = new FixedBranchAssignments(); fixedBranchAssignments.AddBranchAssignment('A', 3); fixedBranchAssignments.AddBranchAssignment('A', 1); var teamAssignment = new RelayVariations(eventDB, CourseId(8), new RelaySettings(30, 5, fixedBranchAssignments)); ValidateRelayVariationsTest(teamAssignment, "relay\\twowayfixed"); }
public void ValidateFixedBranches5() { Setup(TestUtil.GetTestFile("relay\\gaffle.ppen")); // No Assignments. FixedBranchAssignments branchAssignments = new FixedBranchAssignments(); List <string> errors; RelayVariations relayVariations = new RelayVariations(eventDB, CourseId(4), new RelaySettings(10, 3)); FixedBranchAssignments result = relayVariations.ValidateFixedBranches(branchAssignments, out errors); Assert.AreEqual(0, errors.Count); Assert.AreEqual(branchAssignments, result); }
public void FixedBranches9() { Setup(TestUtil.GetTestFile("relay\\gaffle.ppen")); FixedBranchAssignments fixedBranchAssignments = new FixedBranchAssignments(); fixedBranchAssignments.AddBranchAssignment('D', 0); fixedBranchAssignments.AddBranchAssignment('H', 1); fixedBranchAssignments.AddBranchAssignment('I', 2); var teamAssignment = new RelayVariations(eventDB, CourseId(4), new RelaySettings(10, 3, fixedBranchAssignments)); ValidateRelayVariationsTest(teamAssignment, "relay\\fixedinnnerbranch"); }
public void ValidateFixedBranches2() { Setup(TestUtil.GetTestFile("relay\\relay.ppen")); // No Assignments. FixedBranchAssignments branchAssignments = new FixedBranchAssignments(); branchAssignments.AddBranchAssignment('A', -1); branchAssignments.AddBranchAssignment('A', 4); List <string> errors; RelayVariations relayVariations = new RelayVariations(eventDB, CourseId(7), new RelaySettings(1, 4)); FixedBranchAssignments result = relayVariations.ValidateFixedBranches(branchAssignments, out errors); Assert.AreEqual(2, errors.Count); Assert.AreEqual("'0' is not a valid leg number for branch 'A'", errors[0]); Assert.AreEqual("'5' is not a valid leg number for branch 'A'", errors[1]); Assert.AreEqual(result, new FixedBranchAssignments()); }
public FixedBranchAssignments ValidateFixedBranches(FixedBranchAssignments assignments, out List <string> errors) { FixedBranchAssignments result = new FixedBranchAssignments(); errors = new List <string>(); // All legs reach the first fork. bool[] legsReachingHere = new bool[numberLegs]; for (int i = 0; i < legsReachingHere.Length; ++i) { legsReachingHere[i] = true; } ScanAllForks(); ValidateFixedBranchesForFork(assignments, firstForkInCourse, legsReachingHere, result, errors); return(result); }
public RelayVariations(EventDB eventDB, Id <Course> courseId, RelaySettings relaySettings) { this.eventDB = eventDB; this.courseId = courseId; this.firstTeamNumber = relaySettings.firstTeamNumber; this.numberTeams = relaySettings.relayTeams; this.numberLegs = relaySettings.relayLegs; if (!relaySettings.relayBranchAssignments.IsEmpty) { this.fixedBranchAssignments = ValidateFixedBranches(relaySettings.relayBranchAssignments); } else { this.fixedBranchAssignments = relaySettings.relayBranchAssignments; } forksScanned = false; }
public void RoundTripCourses() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); RectangleF mapBounds = new RectangleF(0, 0, 200, 300); Course course1, course2, course3, course4, course5; undomgr.BeginCommand(61, "Command1"); course1 = new Course(CourseKind.Normal, "White", 15000, 1); course1.descKind = DescriptionKind.Symbols; course1.secondaryTitle = "White is right"; course1.load = 0; course1.firstCourseControl = CourseControlId(1); course1.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course1); course2 = new Course(CourseKind.Normal, "Yellow", 15000, 2); course2.hideVariationsOnMap = true; course2.descKind = DescriptionKind.SymbolsAndText; course2.climb = 95; course2.labelKind = ControlLabelKind.Code; course2.firstCourseControl = CourseControlId(0); course2.printArea = new PrintArea(false, true, new RectangleF(50, 70, 200, 100)); course2.partPrintAreas[1] = new PrintArea(false, false, new RectangleF(10, 20, 30, 40), 1.1F); course2.partPrintAreas[0] = new PrintArea(true, false, new RectangleF(70, 10, 130, 140)); course2.partOptions[1] = new PartOptions() { ShowFinish = true }; course2.partOptions[0] = new PartOptions() { ShowFinish = false }; course2.relaySettings = new RelaySettings(6, 43, 3); course2.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course2); course3 = new Course(CourseKind.Score, "Rambo", 10000, 3); course3.secondaryTitle = ""; course3.firstCourseControl = CourseControlId(2); course3.load = 125; course3.climb = 0; course3.firstControlOrdinal = 7; course3.labelKind = ControlLabelKind.SequenceAndCode; course3.descKind = DescriptionKind.Text; course3.partPrintAreas[1] = new PrintArea(true, true, new RectangleF(-10, -20, 90, 80), 0.9F); course3.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course3); course4 = new Course(CourseKind.Score, "Silly1", 10000, 3); course4.secondaryTitle = ""; course4.firstCourseControl = CourseControlId(2); course4.load = 0; course4.climb = 25; course4.overrideCourseLength = 4243; course4.firstControlOrdinal = 3; course4.labelKind = ControlLabelKind.SequenceAndScore; course4.descKind = DescriptionKind.SymbolsAndText; course4.partPrintAreas[1] = new PrintArea(false, false, new RectangleF(-10, -20, 90, 80)); course4.partOptions[1] = new PartOptions() { ShowFinish = false }; course4.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course4); course5 = new Course(CourseKind.Score, "Silly2", 10000, 3); course5.secondaryTitle = ""; course5.firstCourseControl = CourseControlId(2); course5.load = 125; course5.climb = 0; course5.firstControlOrdinal = 1; course5.labelKind = ControlLabelKind.CodeAndScore; course5.descKind = DescriptionKind.Symbols; course5.partPrintAreas[1] = new PrintArea(false, false, new RectangleF(-10, -20, 90, 80), 1.25F); FixedBranchAssignments relayBranchAssignments = new FixedBranchAssignments(); relayBranchAssignments.AddBranchAssignment('B', 1); relayBranchAssignments.AddBranchAssignment('A', 2); relayBranchAssignments.AddBranchAssignment('A', 3); relayBranchAssignments.AddBranchAssignment('C', 4); course5.relaySettings = new RelaySettings(10, 5, 6, relayBranchAssignments); course5.UpdateUnknownPageSizes(mapBounds, 15000); eventDB.AddCourse(course5); undomgr.EndCommand(61); eventDB.Save(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); undomgr.Clear(); eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("eventdb\\testoutput_temp.xml")); Assert.AreEqual(eventDB.GetCourse(CourseId(1)), course1); Assert.AreEqual(eventDB.GetCourse(CourseId(2)), course2); Assert.AreEqual(eventDB.GetCourse(CourseId(3)), course3); Assert.AreEqual(eventDB.GetCourse(CourseId(4)), course4); Assert.AreEqual(eventDB.GetCourse(CourseId(5)), course5); TestUtil.TestEnumerableAnyOrder(eventDB.AllCoursePairs, new KeyValuePair <Id <Course>, Course>[] { new KeyValuePair <Id <Course>, Course>(CourseId(1), course1), new KeyValuePair <Id <Course>, Course>(CourseId(2), course2), new KeyValuePair <Id <Course>, Course>(CourseId(3), course3), new KeyValuePair <Id <Course>, Course>(CourseId(4), course4), new KeyValuePair <Id <Course>, Course>(CourseId(5), course5), } ); }
// Validate branfixed ches for this fork, sub-forks, and subsequents forks. private void ValidateFixedBranchesForFork(FixedBranchAssignments assignments, Fork fork, bool[] legsReachingHere, FixedBranchAssignments result, List <string> errors) { if (fork == null) { return; } if (fork.loop) { // Loops can't have fixed branches. Just validate sub-forks. for (int i = 0; i < fork.subForks.Length; ++i) { ValidateFixedBranchesForFork(assignments, fork.subForks[i], legsReachingHere, result, errors); } } else { char[] codeForLeg = new char[numberLegs]; foreach (char code in fork.codes) { if (assignments.BranchIsFixed(code)) { foreach (int leg in assignments.FixedLegsForBranch(code)) { if (leg < 0 || leg >= numberLegs) { errors.Add(string.Format(MiscText.BadLegNumber, leg + 1, code)); } else if (codeForLeg[leg] != 0) { errors.Add(string.Format(MiscText.LegUsedTwice, leg + 1, codeForLeg[leg], code)); } else if (!legsReachingHere[leg]) { // This leg can't be assigned, because it doesn't ever reach here. errors.Add(string.Format(MiscText.LegAssignedOuterBranch, leg + 1, code)); } else { codeForLeg[leg] = code; } } } } bool allLegsAssigned = true; // Are all legs that could reach here assigned to a branch? for (int leg = 0; leg < numberLegs; ++leg) { if (legsReachingHere[leg] && codeForLeg[leg] == 0) { allLegsAssigned = false; } } bool allBranchesAssigned = fork.codes.All(c => assignments.BranchIsFixed(c)); // Are all branches assigned one or more legs? if (allBranchesAssigned && !allLegsAssigned) { string allCodes = string.Join(", ", from c in fork.codes select c.ToString()); for (int leg = 0; leg < numberLegs; ++leg) { if (legsReachingHere[leg] && codeForLeg[leg] == 0) { errors.Add(string.Format(MiscText.LegNotAssigned, leg + 1, allCodes)); } } } else { for (int leg = 0; leg < numberLegs; ++leg) { if (legsReachingHere[leg] && codeForLeg[leg] != 0) { result.AddBranchAssignment(codeForLeg[leg], leg); } } } // Validate sub-forks, updating the legsReachingHere based on any fixed branches. for (int forkIndex = 0; forkIndex < fork.subForks.Length; ++forkIndex) { char code = fork.codes[forkIndex]; bool[] legsReachingSubFork = (bool[])legsReachingHere.Clone(); if (result.BranchIsFixed(code)) { // Only allow legs that are fixed to this branch. for (int leg = 0; leg < legsReachingSubFork.Length; ++leg) { legsReachingSubFork[leg] &= result.FixedLegsForBranch(code).Contains(leg); } } else { // Only allow legs that are NOT fixed to another branch. foreach (char otherCode in fork.codes) { if (otherCode != code && result.BranchIsFixed(otherCode)) { for (int leg = 0; leg < legsReachingSubFork.Length; ++leg) { legsReachingSubFork[leg] &= !result.FixedLegsForBranch(otherCode).Contains(leg); } } } } ValidateFixedBranchesForFork(assignments, fork.subForks[forkIndex], legsReachingSubFork, result, errors); } } // Validate the next fork. ValidateFixedBranchesForFork(assignments, fork.next, legsReachingHere, result, errors); }
// Validate the fixed branches, and create a new FixedBranchAssignments that doesn't // have errors in it. public FixedBranchAssignments ValidateFixedBranches(FixedBranchAssignments assignments) { List <string> dummy; return(ValidateFixedBranches(assignments, out dummy)); }
public TeamVariationsForm() { InitializeComponent(); FixedBranchAssignments = new FixedBranchAssignments(); }