Exemple #1
0
        public void PartTwo()
        {
            var to     = new TaskOrdering(@"C:\Users\joshu\github\AdventOfCode2018\src\DaySeven\input.txt");
            var answer = to.PartTwo("ADEFKLBVJQWUXCNGORTMYSIHPZ", 5, 60);

            Assert.Equal(1120, answer);
        }
Exemple #2
0
        public void PartOne()
        {
            var to     = new TaskOrdering(@"C:\Users\joshu\github\AdventOfCode2018\src\DaySeven\input.txt");
            var answer = to.GetStringOrder();

            Assert.Equal("ADEFKLBVJQWUXCNGORTMYSIHPZ", answer);
        }
        private string GetTaskOrderDescription()
        {
            TaskOrdering taskOrdering1 = this.Workbook.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType1);
            TaskOrdering taskOrdering2 = this.Workbook.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType2);
            TaskOrdering taskOrdering3 = this.Workbook.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType3);

            return(string.Format(StringResources.OptionSettingsPage_SectionOrderingFormat, taskOrdering1.GetDescription(), taskOrdering2.GetDescription(), taskOrdering3.GetDescription()));
        }
Exemple #4
0
            public SortTestCase(TaskOrdering ordering1, bool ascending1, TaskOrdering ordering2, bool ascending2, TaskOrdering ordering3, bool ascending3, params string[] titles)
                : this()
            {
                this.Titles = titles;

                this.Ordering1 = ordering1;
                this.Ordering2 = ordering2;
                this.Ordering3 = ordering3;

                this.Ascending1 = ascending1;
                this.Ascending2 = ascending2;
                this.Ascending3 = ascending3;
            }
        public TaskOrderSettingsPageViewModel(IWorkbook workbook, INavigationService navigationService) : base(workbook, navigationService)
        {
            TaskOrdering taskOrdering1 = this.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType1);

            this.sortOption1  = taskOrdering1.GetDescription();
            this.isAscending1 = this.Settings.GetValue <bool>(CoreSettings.TaskOrderingAscending1);

            TaskOrdering taskOrdering2 = this.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType2);

            this.sortOption2  = taskOrdering2.GetDescription();
            this.isAscending2 = this.Settings.GetValue <bool>(CoreSettings.TaskOrderingAscending2);

            TaskOrdering taskOrdering3 = this.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType3);

            this.sortOption3  = taskOrdering3.GetDescription();
            this.isAscending3 = this.Settings.GetValue <bool>(CoreSettings.TaskOrderingAscending3);
        }
Exemple #6
0
        public void ExamplePartTwo()
        {
            var lines = new string[]
            {
                "Step C must be finished before step A can begin.",
                "Step C must be finished before step F can begin.",
                "Step A must be finished before step B can begin.",
                "Step A must be finished before step D can begin.",
                "Step B must be finished before step E can begin.",
                "Step D must be finished before step E can begin.",
                "Step F must be finished before step E can begin."
            };

            var to     = new TaskOrdering(lines);
            var answer = to.PartTwo("CABFDE", 2, 0);

            Assert.Equal(15, answer);
        }
Exemple #7
0
        public void ExamplePartOne()
        {
            var lines = new string[]
            {
                "Step C must be finished before step A can begin.",
                "Step C must be finished before step F can begin.",
                "Step A must be finished before step B can begin.",
                "Step A must be finished before step D can begin.",
                "Step B must be finished before step E can begin.",
                "Step D must be finished before step E can begin.",
                "Step F must be finished before step E can begin."
            };

            var to     = new TaskOrdering(lines);
            var answer = to.GetStringOrder();

            Assert.Equal("CABDFE", answer);
        }
        public override void Dispose()
        {
            TaskOrdering ordering1 = TaskOrderingConverter.FromDescription(this.sortOption1);

            if (this.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType1) != ordering1)
            {
                this.Settings.SetValue(CoreSettings.TaskOrderingType1, ordering1);
            }

            if (this.Settings.GetValue <bool>(CoreSettings.TaskOrderingAscending1) != this.IsAscending1)
            {
                this.Settings.SetValue(CoreSettings.TaskOrderingAscending1, this.IsAscending1);
            }

            TaskOrdering ordering2 = TaskOrderingConverter.FromDescription(this.sortOption2);

            if (this.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType2) != ordering2)
            {
                this.Settings.SetValue(CoreSettings.TaskOrderingType2, ordering2);
            }

            if (this.Settings.GetValue <bool>(CoreSettings.TaskOrderingAscending2) != this.IsAscending2)
            {
                this.Settings.SetValue(CoreSettings.TaskOrderingAscending2, this.IsAscending2);
            }

            TaskOrdering ordering3 = TaskOrderingConverter.FromDescription(this.sortOption3);

            if (this.Settings.GetValue <TaskOrdering>(CoreSettings.TaskOrderingType3) != ordering3)
            {
                this.Settings.SetValue(CoreSettings.TaskOrderingType3, ordering3);
            }

            if (this.Settings.GetValue <bool>(CoreSettings.TaskOrderingAscending3) != this.IsAscending3)
            {
                this.Settings.SetValue(CoreSettings.TaskOrderingAscending3, this.IsAscending3);
            }
        }
Exemple #9
0
        private static Func <ITask, ITask, int> CreateCompareFunc(TaskOrdering ordering, bool ascending)
        {
            switch (ordering)
            {
            case TaskOrdering.AddedDate:
                return((x, y) => ascending?x.Added.CompareTo(y.Added) : y.Added.CompareTo(x.Added));

            case TaskOrdering.ModifiedDate:
                return((x, y) => ascending?x.Modified.CompareTo(y.Modified) : y.Modified.CompareTo(x.Modified));

            case TaskOrdering.DueDate:
                return((x, y) =>
                {
                    if (x.Due.HasValue && y.Due.HasValue)
                    {
                        // both have due date
                        if (x.Due.Value.Date < y.Due.Value.Date)
                        {
                            return ascending ? -1 : 1;
                        }
                        else if (x.Due.Value.Date > y.Due.Value.Date)
                        {
                            return ascending ? 1 : -1;
                        }
                        else
                        {
                            return 0;
                        }
                    }
                    else if (x.Due.HasValue && !y.Due.HasValue)
                    {
                        // only x has due date
                        return ascending ? -1 : 1;
                    }
                    else if (!x.Due.HasValue && y.Due.HasValue)
                    {
                        // only y has due date
                        return ascending ? 1 : -1;
                    }
                    else
                    {
                        return 0;
                    }
                });

            case TaskOrdering.StartDate:
                return((x, y) =>
                {
                    if (x.Start.HasValue && y.Start.HasValue)
                    {
                        // both have start date
                        if (x.Start.Value < y.Start.Value)
                        {
                            return ascending ? -1 : 1;
                        }
                        else if (x.Start.Value > y.Start.Value)
                        {
                            return ascending ? 1 : -1;
                        }
                        else
                        {
                            return 0;
                        }
                    }
                    else if (x.Start.HasValue && !y.Start.HasValue)
                    {
                        // only x has start date
                        return -1;
                    }
                    else if (!x.Start.HasValue && y.Start.HasValue)
                    {
                        // only y has start date
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
                });

            case TaskOrdering.Alarm:
                return((x, y) =>
                {
                    if (x.Alarm.HasValue && y.Alarm.HasValue)
                    {
                        // both have alarm
                        if (x.Alarm.Value < y.Alarm.Value)
                        {
                            return ascending ? -1 : 1;
                        }
                        else if (x.Alarm.Value > y.Alarm.Value)
                        {
                            return ascending ? 1 : -1;
                        }
                        else
                        {
                            return 0;
                        }
                    }
                    else if (x.Alarm.HasValue && !y.Alarm.HasValue)
                    {
                        // only x has alarm
                        return -1;
                    }
                    else if (!x.Alarm.HasValue && y.Alarm.HasValue)
                    {
                        // only y has alarm
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
                });

            case TaskOrdering.Context:
                return((x, y) =>
                {
                    if (x.Context != null && y.Context != null)
                    {
                        // both have context
                        return ascending ? x.Context.Name.CompareTo(y.Context.Name) : y.Context.Name.CompareTo(x.Context.Name);
                    }
                    else if (x.Context != null && y.Context == null)
                    {
                        // only x has context
                        return ascending ? -1 : 1;
                    }
                    else if (x.Context == null && y.Context != null)
                    {
                        // only y context
                        return ascending ? 1 : -1;
                    }
                    else
                    {
                        return 0;
                    }
                });

            case TaskOrdering.Folder:
                return((x, y) =>
                {
                    if (x.Folder.Name == null && y.Folder.Name != null)
                    {
                        return 1;
                    }
                    else if (x.Folder.Name != null && y.Folder.Name == null)
                    {
                        return -1;
                    }
                    else if (x.Folder.Name == null && y.Folder.Name == null)
                    {
                        return 0;
                    }
                    else
                    {
                        return ascending ? x.Folder.Name.CompareTo(y.Folder.Name) : y.Folder.Name.CompareTo(x.Folder.Name);
                    }
                });

            case TaskOrdering.Priority:
                return((x, y) =>
                {
                    return ascending ? x.Priority.CompareTo(y.Priority) : y.Priority.CompareTo(x.Priority);
                });

            case TaskOrdering.Alphabetical:
                return((x, y) =>
                {
                    if (x.Title == null && y.Title != null)
                    {
                        return 1;
                    }
                    else if (x.Title != null && y.Title == null)
                    {
                        return -1;
                    }
                    else if (x.Title == null && y.Title == null)
                    {
                        return 0;
                    }
                    else
                    {
                        return ascending ? x.Title.CompareTo(y.Title) : y.Title.CompareTo(x.Title);
                    }
                });

            default:
                throw new ArgumentOutOfRangeException("ordering");
            }
        }
Exemple #10
0
 public static string GetDescription(this TaskOrdering taskPriority)
 {
     return(descriptions[taskPriority]);
 }