public void Test_RegisterForCourse_StudentIsProfessor()
        {
            MockDatabase <CourseSchedule> mockDB = new MockDatabase <CourseSchedule>(c => c.CourseSchedules);
            RegistrationData data = new RegistrationData(mockDB.Context);

            Student student = new Student
            {
                StudentSchedules = new List <StudentSchedule>(),
                PersonId         = 5
            };

            CourseSchedule schedule = new CourseSchedule
            {
                Capacity         = 3,
                StudentSchedules = new List <StudentSchedule>
                {
                    new StudentSchedule(),
                    new StudentSchedule()
                },
                Schedule = new Schedule
                {
                    StartTime  = new TimeSpan(8, 0, 0),
                    TimeBlocks = 1
                },
                ProfessorId = 5
            };

            mockDB.AddDataEntry(schedule);
            data.RegisterForCourse(student, schedule);

            Assert.Equal(schedule.StudentSchedules.ToList().Count, 2);
            mockDB.MockContext.Verify(m => m.SaveChanges(), Times.Never());
        }
Exemplo n.º 2
0
        public void TestCanFinish()
        {
            //无环
            var arr = new int[, ]
            {
                { 1, 0 },
                { 2, 0 },
                { 3, 1 },
                { 5, 2 },
                { 4, 3 },
                { 3, 6 },
            };
            var r = CourseSchedule.CanFinish(7, arr);

            Assert.AreEqual(r, true);

            //有环
            arr = new int[, ]
            {
                { 1, 0 },
                { 2, 0 },
                { 3, 1 },
                { 5, 2 },
                { 4, 3 },
                { 3, 6 },
                { 6, 4 },
            };
            r = CourseSchedule.CanFinish(7, arr);
            Assert.AreEqual(r, false);
        }
        public void Test_GetNumberOfStudentsInCourse()
        {
            MockDatabase <CourseSchedule> mockDB = new MockDatabase <CourseSchedule>(c => c.CourseSchedules);
            RegistrationData data = new RegistrationData(mockDB.Context);

            CourseSchedule schedule = new CourseSchedule
            {
                Capacity         = 3,
                StudentSchedules = new List <StudentSchedule>
                {
                    new StudentSchedule {
                        Enrolled = true
                    },
                    new StudentSchedule {
                        Enrolled = false
                    },
                    new StudentSchedule {
                        Enrolled = true
                    }
                }
            };

            mockDB.AddDataEntry(schedule);

            int expected = 2;
            int actual   = data.GetNumberOfStudentsInCourse(schedule);

            Assert.Equal(expected, actual);
        }
        public void Test_ScheduleCourse_ProfessorIsTeachingCourseAtSameTime()
        {
            MockDatabase <CourseSchedule> mockDB = new MockDatabase <CourseSchedule>(c => c.CourseSchedules);
            RegistrationData data = new RegistrationData(mockDB.Context);

            CourseSchedule existingCourseSchedule = new CourseSchedule
            {
                Schedule = new Schedule {
                    StartTime = new TimeSpan(8, 0, 0), TimeBlocks = 2
                }
            };
            Person professor = new Person {
                PersonId = 5, CourseSchedules = new List <CourseSchedule> {
                    existingCourseSchedule
                }
            };
            Schedule schedule = new Schedule {
                StartTime = new TimeSpan(9, 30, 0), TimeBlocks = 1
            };
            Course course = new Course
            {
                CourseSchedules = new List <CourseSchedule>
                {
                    existingCourseSchedule
                }
            };

            data.ScheduleCourse(course, schedule, professor, 3);

            mockDB.MockSet.Verify(m => m.Add(It.IsAny <CourseSchedule>()), Times.Never());
            mockDB.MockContext.Verify(m => m.SaveChanges(), Times.Never());
        }
        public void Test_ModifyCourse()
        {
            MockDatabase <CourseSchedule> mockDB = new MockDatabase <CourseSchedule>(c => c.CourseSchedules);
            RegistrationData data = new RegistrationData(mockDB.Context);

            CourseSchedule existingCourseSchedule = new CourseSchedule
            {
                Schedule = new Schedule {
                    StartTime = new TimeSpan(8, 0, 0), TimeBlocks = 2
                },
                Capacity = 15
            };

            mockDB.AddDataEntry(existingCourseSchedule);

            Schedule schedule = new Schedule {
                StartTime = new TimeSpan(11, 0, 0), TimeBlocks = 1
            };
            short capacity = 30;

            data.ModifyCourse(existingCourseSchedule, schedule, capacity);

            Assert.Equal(schedule.StartTime, existingCourseSchedule.Schedule.StartTime);
            Assert.Equal(schedule.TimeBlocks, existingCourseSchedule.Schedule.TimeBlocks);
            Assert.Equal(capacity, existingCourseSchedule.Capacity);
            mockDB.MockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Exemplo n.º 6
0
        public ModelInvokeResult <CourseSchedulePK> Update(string strId, CourseSchedule courseSchedule)
        {
            ModelInvokeResult <CourseSchedulePK> result = new ModelInvokeResult <CourseSchedulePK> {
                Success = true
            };

            try
            {
                List <IBatisNetBatchStatement> statements = new List <IBatisNetBatchStatement>();
                int _Id = Convert.ToInt32(strId);
                /***********************begin 自定义代码*******************/
                courseSchedule.OperatedBy = NormalSession.UserId.ToGuid();
                courseSchedule.OperatedOn = DateTime.Now;
                courseSchedule.DataSource = GlobalManager.DIKey_00012_ManualEdit;
                /***********************end 自定义代码*********************/
                statements.Add(new IBatisNetBatchStatement {
                    StatementName = courseSchedule.GetUpdateMethodName(), ParameterObject = courseSchedule.ToStringObjectDictionary(false), Type = SqlExecuteType.UPDATE
                });
                /***********************begin 自定义代码*******************/
                /***********************此处添加自定义代码*****************/
                /***********************end 自定义代码*********************/
                BuilderFactory.DefaultBulder().ExecuteNativeSqlNoneQuery(statements);
                result.instance = new CourseSchedulePK {
                    Id = _Id
                };
            }
            catch (Exception ex)
            {
                result.Success      = false;
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }
Exemplo n.º 7
0
        public void DataDrivenTest(int testId, int numCourses, string prerequisites, bool expected)
        {
            var  sut    = new CourseSchedule();
            bool actual = MeasureAndExecute(testId, () => sut.CanFinish(numCourses, prerequisites.ToTwoDimentionArray()));

            actual.Should().Be(expected);
        }
Exemplo n.º 8
0
 private static bool courseScheduleTest2()
 {
     string[] solution = CourseSchedule.compute(new string[, ] {
         { "a", "b" }, { "b", "c" }, { "c", "d" }
     });
     return(solution.SequenceEqual(new string[] { "a", "b", "c", "d" }));
 }
Exemplo n.º 9
0
 private static void Refactor()
 {
     MinEditDistance.Init();     // Not Solved
     CourseSchedule.Init();      // Not solved - GRAPHS
     PossibleBiPartition.Init(); // Not solved - GRAPHS
     ImplementStrStrLc28.Init(); // KMP Algo for ImplementStrStrLc28
     NumberComplement.Init();    // Refactor existing implementation
 }
Exemplo n.º 10
0
        public ActionResult DeleteConfirmed(int id)
        {
            CourseSchedule courseSchedule = db.CourseSchedules.Find(id);

            db.CourseSchedules.Remove(courseSchedule);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public void TestCanFinish()
 {
     Assert.IsTrue(CourseSchedule.CanFinish(3, new int[, ] {
         { 1, 0 }, { 2, 0 }, { 2, 1 }
     }));
     Assert.IsFalse(CourseSchedule.CanFinish(3, new int[, ] {
         { 1, 0 }, { 0, 1 }
     }));
 }
Exemplo n.º 12
0
        public void FindOrderTest3()
        {
            CourseSchedule courseSchedule = new CourseSchedule();

            int[][] pre = new int[0][];
            //pre[0] = new int[0];
            int[] res = courseSchedule.FindOrder(1, pre);
            Assert.IsTrue(res[0] == 0);
        }
Exemplo n.º 13
0
        public void TestCase_1()
        {
            var prerequisits = new int[1][];

            prerequisits[0] = new[] { 1, 0 };

            var courseScheduler = new CourseSchedule();

            Assert.True(courseScheduler.CanFinish(2, prerequisits));
        }
Exemplo n.º 14
0
        public void FindOrderTest4()
        {
            CourseSchedule courseSchedule = new CourseSchedule();

            int[][] pre = new int[2][];
            pre[0] = new int[] { 0, 1 };
            pre[1] = new int[] { 1, 0 };
            int[] res = courseSchedule.FindOrder(2, pre);
            Assert.IsTrue(res.Length == 0);
        }
Exemplo n.º 15
0
        public void FindOrderTest()
        {
            CourseSchedule courseSchedule = new CourseSchedule();

            int[][] pre = new int[1][];
            pre[0] = new int[] { 1, 0 };
            int[] res = courseSchedule.FindOrder(2, pre);
            Assert.IsTrue(res[0] == 0);
            Assert.IsTrue(res[1] == 1);
        }
Exemplo n.º 16
0
        public void CanFinishTest()
        {
            CourseSchedule courseSchedule = new CourseSchedule();

            int[][] pre = new int[1][];
            pre[0] = new int[] { 0, 1 };
            bool res = courseSchedule.CanFinish(2, pre);

            Assert.IsTrue(res);
        }
Exemplo n.º 17
0
        public void TestCase_2()
        {
            var prerequisits = new int[2][];

            prerequisits[0] = new[] { 1, 0 };
            prerequisits[1] = new[] { 0, 1 };

            var courseScheduler = new CourseSchedule();

            Assert.False(courseScheduler.CanFinish(2, prerequisits));
        }
Exemplo n.º 18
0
        public void CanFinishTest6()
        {
            CourseSchedule courseSchedule = new CourseSchedule();

            int[][] pre = new int[2][];
            pre[0] = new int[] { 1, 0 };
            pre[1] = new int[] { 2, 1 };
            bool res = courseSchedule.CanFinish(3, pre);

            Assert.IsTrue(res);
        }
Exemplo n.º 19
0
        public void CanFinishTest2()
        {
            CourseSchedule courseSchedule = new CourseSchedule();

            int[][] pre = new int[2][];
            pre[0] = new int[] { 0, 1 };
            pre[1] = new int[] { 1, 0 };
            bool res = courseSchedule.CanFinish(2, pre);

            Assert.IsFalse(res);
        }
 public void TestFindOrder()
 {
     Assert.AreEqual(new int[] { 0, 1, 2, 3 }, CourseSchedule.FindOrder(4, new int[, ] {
         { 1, 0 }, { 2, 0 }, { 3, 1 }, { 3, 2 }
     }));                                                                                                                           // can have multiple solution
     Assert.AreEqual(new int[] { 0, 1, 2 }, CourseSchedule.FindOrder(3, new int[, ] {
         { 1, 0 }, { 2, 0 }, { 2, 1 }
     }));
     Assert.AreEqual(new int[] { }, CourseSchedule.FindOrder(3, new int[, ] {
         { 1, 0 }, { 0, 1 }
     }));
 }
Exemplo n.º 21
0
        public void TestOrder()
        {
            //无环
            var arr = new int[, ]
            {
                { 1, 0 },
                { 2, 0 },
                { 3, 1 },
                { 5, 2 },
                { 4, 3 },
                { 3, 6 },
            };
            var r = CourseSchedule.FindOrder(7, arr);
            //上面这图里按照我写的算法是分层次的 06最外层,12第二层,35第三层,4最后,同一层次里数组里先出现结果里也先出现
            var s = string.Join("", r);

            Assert.AreEqual(s.Substring(0, 2), "06");
            Assert.AreEqual(s.Substring(2, 2), "12");
            Assert.AreEqual(s.Substring(4, 2), "35");
            Assert.AreEqual(s.Substring(6, 1), "4");


            //无环
            arr = new int[, ]
            {
                { 1, 0 }, { 2, 0 }, { 3, 1 }, { 3, 2 }
            };
            r = CourseSchedule.FindOrder(4, arr);
            //上面这图里按照我写的算法是分层次的 06最外层,12第二层,35第三层,4最后,同一层次里数组里先出现结果里也先出现
            s = string.Join("", r);

            Assert.AreEqual(s.Substring(0, 1), "0");
            Assert.AreEqual(s.Substring(1, 2), "12");
            Assert.AreEqual(s.Substring(3, 1), "3");



            //有环
            arr = new int[, ]
            {
                { 1, 0 },
                { 2, 0 },
                { 3, 1 },
                { 5, 2 },
                { 4, 3 },
                { 3, 6 },
                { 6, 4 },
            };
            r = CourseSchedule.FindOrder(7, arr);
            Assert.AreEqual(r.Length, 0);
        }
        public void Test_CancelCourse()
        {
            MockDatabase <CourseSchedule> mockDB = new MockDatabase <CourseSchedule>(c => c.CourseSchedules);
            RegistrationData data = new RegistrationData(mockDB.Context);

            CourseSchedule existingCourseSchedule = new CourseSchedule();

            mockDB.AddDataEntry(existingCourseSchedule);

            data.CancelCourse(existingCourseSchedule);

            mockDB.MockSet.Verify(m => m.Remove(It.IsAny <CourseSchedule>()), Times.Once());
            mockDB.MockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Exemplo n.º 23
0
 public ActionResult Edit([Bind(Include = "Id,StartTime,FinishTime,DayOfWeekId,RoomId,TrainerId,CourseId,Description")] CourseSchedule courseSchedule)
 {
     if (ModelState.IsValid)
     {
         db.Entry(courseSchedule).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseId    = new SelectList(db.Courses, "Id", "Name", courseSchedule.CourseId);
     ViewBag.DayOfWeekId = new SelectList(db.DaysOfWeeks, "Id", "Name", courseSchedule.DayOfWeekId);
     ViewBag.RoomId      = new SelectList(db.Rooms, "Id", "Name", courseSchedule.RoomId);
     ViewBag.TrainerId   = new SelectList(db.Trainers, "Id", "Name", courseSchedule.TrainerId);
     return(View(courseSchedule));
 }
Exemplo n.º 24
0
        // GET: CourseSchedules/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CourseSchedule courseSchedule = db.CourseSchedules.Find(id);

            if (courseSchedule == null)
            {
                return(HttpNotFound());
            }
            return(View(courseSchedule));
        }
Exemplo n.º 25
0
        /// <summary>
        /// Convert CourseSchedule into CourseScheduleDAO.
        /// </summary>
        /// <param name="courseSchedule">The CourseSchedule to convert.</param>
        /// <returns>The CourseScheduleDAO.</returns>
        public static CourseScheduleDAO MapToCourseScheduleDAO(CourseSchedule courseSchedule)
        {
            RegistrationData data = new RegistrationData();

            return(new CourseScheduleDAO
            {
                Id = courseSchedule.CourseScheduleId,
                Professor = MapToPersonDAO(courseSchedule.Person),
                Capacity = courseSchedule.Capacity,
                Course = MapToCourseDAO(courseSchedule.Course),
                Schedule = MapToScheduleDAO(courseSchedule.Schedule),
                Enrolled = data.GetNumberOfStudentsInCourse(courseSchedule)
            });
        }
Exemplo n.º 26
0
        public List <CourseSchedule> GetCourseScheduleList(ref List <string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            var courseScheduleList = new List <CourseSchedule>();

            try
            {
                var adapter = new SqlDataAdapter(GetCourseScheduleProcedure, conn)
                {
                    SelectCommand =
                    {
                        CommandType = CommandType.StoredProcedure
                    }
                };

                var dataSet = new DataSet();
                adapter.Fill(dataSet);

                if (dataSet.Tables[0].Rows.Count == 0)
                {
                    return(null);
                }

                for (var i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                {
                    var courseSchedule = new CourseSchedule
                    {
                        ScheduleId        = (int)dataSet.Tables[0].Rows[i]["schedule_id"],
                        CourseId          = (int)dataSet.Tables[0].Rows[i]["course_id"],
                        Year              = (int)dataSet.Tables[0].Rows[i]["year"],
                        Quarter           = dataSet.Tables[0].Rows[i]["quarter"].ToString(),
                        Session           = dataSet.Tables[0].Rows[i]["session"].ToString(),
                        CourseTitle       = dataSet.Tables[0].Rows[i]["course_title"].ToString(),
                        CourseDescription = dataSet.Tables[0].Rows[i]["course_description"].ToString(),
                    };
                    courseScheduleList.Add(courseSchedule);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }

            return(courseScheduleList);
        }
Exemplo n.º 27
0
        public void FindOrderTest2()
        {
            CourseSchedule courseSchedule = new CourseSchedule();

            int[][] pre = new int[4][];
            pre[0] = new int[] { 1, 0 };
            pre[1] = new int[] { 2, 0 };
            pre[2] = new int[] { 3, 1 };
            pre[3] = new int[] { 3, 2 };
            int[] res = courseSchedule.FindOrder(4, pre);
            Assert.IsTrue(res[0] == 0);
            Assert.IsTrue(res[1] == 1 || res[1] == 2);
            Assert.IsTrue(res[2] == 1 || res[2] == 2);
            Assert.IsTrue(res[3] == 3);
        }
Exemplo n.º 28
0
        public void TestCase_3()
        {
            //3
            //[[0,1],[0,2],[1,2]]

            var prerequisits = new int[3][];

            prerequisits[0] = new[] { 0, 1 };
            prerequisits[1] = new[] { 0, 2 };
            prerequisits[2] = new[] { 1, 2 };

            var courseScheduler = new CourseSchedule();

            Assert.True(courseScheduler.CanFinish(3, prerequisits));
        }
        public void Test_GetCourse()
        {
            MockDatabase <CourseSchedule> mockDB = new MockDatabase <CourseSchedule>(c => c.CourseSchedules);
            RegistrationData data = new RegistrationData(mockDB.Context);

            CourseSchedule schedule = new CourseSchedule
            {
                CourseScheduleId = 3
            };

            mockDB.AddDataEntry(schedule);

            CourseSchedule foundSchedule = data.GetCourse(3);

            mockDB.MockSet.Verify(m => m.Find(It.IsAny <int>()), Times.Once());
        }
Exemplo n.º 30
0
        /// <summary>
        /// Convert CourseScheduleDAO into CourseSchedule.
        /// </summary>
        /// <param name="courseScheduleDAO">The CourseScheduleDAO to convert.</param>
        /// <returns>The CourseSchedule.</returns>
        public static CourseSchedule MapToCourseSchedule(CourseScheduleDAO courseScheduleDAO)
        {
            RegistrationData data = new RegistrationData();

            CourseSchedule courseSchedule = data.FindOrCreateCourseSchedule(courseScheduleDAO.Id);

            courseSchedule.CourseScheduleId = courseScheduleDAO.Id;
            courseSchedule.Person           = MapToPerson(courseScheduleDAO.Professor);
            courseSchedule.ProfessorId      = courseScheduleDAO.Professor.Id;
            courseSchedule.Capacity         = courseScheduleDAO.Capacity;
            courseSchedule.Course           = MapToCourse(courseScheduleDAO.Course);
            courseSchedule.CourseId         = courseScheduleDAO.Course.Id;
            courseSchedule.Schedule         = MapToSchedule(courseScheduleDAO.Schedule);
            courseSchedule.ScheduleId       = courseScheduleDAO.Schedule.Id;

            return(courseSchedule);
        }