Exemple #1
0
 public async Task ThrowsArgumentExceptionOnCrossTeamDuplicateWish()
 {
     var dc     = new Daycare();
     var rc     = new RotationCalculator();
     var wishes = new List <Wish>()
     {
         new Wish(dc.Employees.Find(e => e.Id == 2), 10, 1),
         new Wish(dc.Employees.Find(e => e.Id == 10), 10, 1)
     };
     await rc.DaycareShiftsOfThreeWeeks(dc, 0, wishes, 0);
 }
Exemple #2
0
 public async Task ThrowsExceptionOnSimilarWishesWithinTeam()
 {
     var dc     = new Daycare();
     var rc     = new RotationCalculator();
     var wishes = new List <Wish>()
     {
         new Wish(dc.Employees.Find(e => e.Id == 2), 10, 1),
         new Wish(dc.Employees.Find(e => e.Id == 1), 11, 1)
     };
     await rc.DaycareShiftsOfThreeWeeks(dc, 0, wishes, 0);
 }
Exemple #3
0
        public void CalculatesCorrectShiftsForSmallDaycare()
        {
            var teams = new List <Team>()
            {
                new Team(0, 1),
                new Team(1, 2)
            };
            var dc     = new Daycare(teams);
            var rc     = new RotationCalculator();
            var wishes = new List <Wish>();

            rc.DaycareShiftsOfThreeWeeks(dc, 0, wishes, 1);
            var emp0Shifts = dc.Teams[0].TeamEmp[0].Shifts;
            var emp1Shifts = dc.Teams[0].TeamEmp[1].Shifts;
            var emp2Shifts = dc.Teams[0].TeamEmp[2].Shifts;
            var emp3Shifts = dc.Teams[1].TeamEmp[0].Shifts;
            var emp4Shifts = dc.Teams[1].TeamEmp[1].Shifts;
            var emp5Shifts = dc.Teams[1].TeamEmp[2].Shifts;

            var expShifts1 = new List <WorkShift>()
            {
                new WorkShift(0),
                new WorkShift(2),
                new WorkShift(4),
                new WorkShift(1, true),
                new WorkShift(2),

                new WorkShift(5),
                new WorkShift(1),
                new WorkShift(3),
                new WorkShift(4, true),
                new WorkShift(0),

                new WorkShift(2),
                new WorkShift(4),
                new WorkShift(0),
                new WorkShift(2),
                new WorkShift(5)
            };

            CollectionAssert.AreEqual(expShifts1, emp1Shifts);
        }
Exemple #4
0
        public void SwitchWorksCorrectly()
        {
            var dc     = new Daycare();
            var rc     = new RotationCalculator();
            var wishes = new List <Wish>()
            {
                new Wish(dc.Employees.Find(e => e.Id == 1), 1, 1),
                new Wish(dc.Employees.Find(e => e.Id == 9), 10, 1)
            };

            rc.DaycareShiftsOfThreeWeeks(dc, 0, wishes, 1);
            var actual = dc.Employees.Select(e => (int)e.Shifts[1].Shift).ToList();

            var expected = new List <int>()
            {
                8, 4, 1, 0, 5, 9, 2, 6, 11, 3, 10, 7
            };

            CollectionAssert.AreEqual(expected, actual);
        }
        public async Task <Shifts> GetDCShifts(int id, int group, string creator, string set, int up)
        {
            try
            {
                var dc        = _context.Daycares[id];
                var dtoWishes = await _mongo.GetWishes(set, creator);

                var wishes = ConvertDTOToWish(dtoWishes, dc);

                await _calc.DaycareShiftsOfThreeWeeks(dc, group, wishes, up);

                var dcShifts = new Shifts();
                foreach (var team in dc.Teams)
                {
                    List <Employee> sorted = team.TeamEmp.OrderBy(e => e.Id).ToList();
                    foreach (var emp in sorted)
                    {
                        var shifts = emp.Status == StatusEnum.Nurse ?
                                     $"{emp.Id} {emp.Status}:   " :
                                     $"{emp.Id} {emp.Status}: ";

                        foreach (var shift in emp.Shifts)
                        {
                            var num = Convert.ToInt32(shift.Shift) + 1;
                            shifts += num + ((num > 9) ? " " : "  ");
                        }
                        dcShifts.Add(shifts.Trim());
                    }
                }
                return(dcShifts);
            }
            catch (Exception ex)
            {
                var fail = new Shifts();
                fail.AllShifts.Add(ex.Message);
                return(fail);
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            var dc = new Daycare();

            var calc = new RotationCalculator();

            try
            {
                var wishes = new List <Wish>()
                {
                    new Wish(dc.Employees.Find(e => e.Id == 1), 10, 4),
                    //new Wish(dc.Employees.Find(e => e.Id == 6), 10, 4),
                    new Wish(dc.Employees.Find(e => e.Id == 10), 6, 1)
                };
                calc.DaycareShiftsOfThreeWeeks(dc, 0, wishes, 0);

                foreach (var team in dc.Teams)
                {
                    foreach (var emp in team.TeamEmp)
                    {
                        var shifts = emp.Id.ToString() + " " + emp.Status.ToString() + ": ";
                        foreach (var shift in emp.Shifts)
                        {
                            var num = Convert.ToInt32(shift.Shift);
                            shifts += num + ((num > 9) ? " " : "  ");
                        }
                        Console.WriteLine(shifts);
                    }
                    Console.WriteLine("\n");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }