private static IDictionary<Course, List<Student>> ReadInputFile(string inputFile) { StreamReader reader = new StreamReader("../../" + inputFile); IDictionary<Course, List<Student>> courses = new SortedDictionary<Course, List<Student>>(); using (reader) { string line = reader.ReadLine(); while (line != null) { string[] lineElements = line.Split('|').Select(str => str.Trim()).ToArray(); Course course = new Course(lineElements[2]); Student st = new Student(lineElements[0], lineElements[1]); if (courses.ContainsKey(course)) { courses[course].Add(st); } else { courses.Add(course, new List<Student> { st }); } line = reader.ReadLine(); } return courses; } }
public void AddStudentToSchool(Student student) { if (!this.allStudents.Contains(student)) { this.allStudents.Add(student); } }
public void SchoolShouldThrowExceptionWhenAddingExistingStudent() { var school = new School("Telerik Academy"); var student = new Student("Daniel Popov", 10000); school.AddStudent(student); school.AddStudent(student); }
public void CourseShouldThrowExceptionWhenExistingStudentIsAdded() { var course = new Course("High Quality Code"); var student = new Student("Daniel Popov", 10000); course.AddStudent(student); course.AddStudent(student); }
public void TestStudentSchoolNumberIfIsInRange() { string name = "asen"; int studentNumber = 50000; Student asen = new Student(name, studentNumber); Assert.IsTrue(10000 <= studentNumber && studentNumber <= 99999); }
public void TestCourseAddingStudentWithSameNameToThrow() { Course course = new Course("JS"); Student asen = new Student("asen", 10000); course.AddStudent(asen); course.AddStudent(asen); }
public void SchoolShouldRemoveStudentCorrectly() { var school = new School("Telerik Academy"); var student = new Student("Daniel Popov", 10000); school.AddStudent(student); school.RemoveStudent(student); Assert.AreEqual(0, school.Students.Count); }
public void CourseShoudRemoveStudentCorrectly() { var course = new Course("High Quality Code"); var student = new Student("Daniel Popov", 10000); course.AddStudent(student); course.RemoveStudent(student); Assert.AreEqual(0, course.Students.Count); }
public void CourseShouldAddStudentCorrectly() { var course = new Course("High Quality Code"); var student = new Student("Daniel Popov", 10000); course.AddStudent(student); Assert.AreSame(student, course.Students.First()); }
public void AddStudentsShouldAddTheStudent() { string name = "Petur Petrov"; int uniqueNumber = 10002; Student student = new Student(name, uniqueNumber); List<Student> students = new List<Student>(); Course newCourse = new Course(students,"Math"); newCourse.AddStudent(student); }
public void AddStudentsShouldThrowErrorIfStudentsAreMoreThanMaxStudents() { List<Student> students = new List<Student>(); Course newCourse = new Course(students,"English"); for (int i = 0; i <35 ; i++) { Student student = new Student("Petur Iordanov", (10001+i)); newCourse.AddStudent(student); } }
public void RemoveStudentsShouldThrowErrorIfStudentDoesNotExist() { string name = "Petur Petrov"; int uniqueNumber = 10002; Student student2 = new Student("Goshko", uniqueNumber + 1); Student student = new Student(name, uniqueNumber); List<Student> students = new List<Student>(); Course newCourse = new Course(students, "Math"); newCourse.AddStudent(student); newCourse.RemoveStudents(student2); }
public void AddStudent(Student student) { if (this.Students.Count + 1 <= MaxStudentsCount) { this.Students.Add(student); } else { throw new ArgumentOutOfRangeException("The course is Full! Must have maximum 29 students!"); } }
private static void AddInfo(string courseName, string firstName, string lastName) { var course = new Course(courseName); var student = new Student(firstName, lastName); if (!Result.ContainsKey(course)) { Result[course] = new OrderedBag<Student>(); } Result[course].Add(student); }
public void TestAddOneCourseManyTimes() { Student nerd = new Student("Pavel Kolev", 11113); Course javaScript = new Course("JavaScript"); nerd.JointInCourse(javaScript); nerd.JointInCourse(javaScript); nerd.JointInCourse(javaScript); nerd.JointInCourse(javaScript); nerd.JointInCourse(javaScript); Assert.AreEqual(1, nerd.Courses.Count); }
public void RemoveStudent(Student student) { if (student == null) { throw new ArgumentNullException("Student cannot be null"); } if (!this.students.Contains(student)) { throw new InvalidOperationException("Student does not participate in the class"); } this.students.Remove(student); }
public void RemoveStudent(Student student) { if (student == null) { throw new ArgumentNullException("student", "Student cannot be null."); } if (!this.students.Contains(student)) { throw new InvalidOperationException("The student does not attend this class."); } this.students.Remove(student); }
public void RemoveStudent(Student student) { if (student == null) { throw new ArgumentNullException("Student cannot be null"); } if (!this.students.Contains(student)) { throw new ArgumentException("No such student"); } this.students.Remove(student); }
public void TestCheckCourses() { Student nerd = new Student("Pavel Kolev", 11111); Student nobbie = new Student("Goran Bognanov", 15151); Course cSharp = new Course("C#"); Course cPlusPlus = new Course("C++"); Course java = new Course("Java"); nerd.JointInCourse(cSharp); nerd.JointInCourse(cPlusPlus); nerd.JointInCourse(java); Assert.AreEqual(3, nerd.Courses.Count); Assert.AreEqual(0, nobbie.Courses.Count); }
public void RemoveStudents(Student student) { for (int i = 0; i < this.Students.Count; i++) { if (this.Students[i].UniqueNumber == student.UniqueNumber) { this.Students.RemoveAt(i); this.studentIsNotFound = false; break; } } if (this.studentIsNotFound) { throw new ArgumentException("The student is not found!"); } }
public void AddStudent(Student student) { if (student == null) { throw new ArgumentNullException("student", "Student cannot be null."); } if (this.Students.Count + 1 > Course.MaxStudentsCount) { throw new InvalidOperationException("Student list is full."); } if (this.students.Contains(student)) { throw new InvalidOperationException("This student already has joined the class."); } this.students.Add(student); }
public void AddStudent(Student student) { if (this.students.Contains(student)) { throw new ArgumentException("Student already exist"); } if (student == null) { throw new ArgumentNullException("Student cannot be null"); } if (this.students.Count > MaxStudentInCourse) { throw new ArgumentOutOfRangeException("Course is full"); } this.students.Add(student); }
public void AddStudent(Student student) { if (student == null) { throw new ArgumentNullException("Student cannot be null"); } if (this.students.Contains(student)) { throw new InvalidOperationException("The student has already been added to the class"); } if (this.Students.Count + 1 > StudentsMaxCount) { throw new InvalidOperationException("Student list is already full"); } this.students.Add(student); }
public void AddStudent(Student student) { if (student == null) { throw new ArgumentNullException("Student canno be null"); } if (this.students.Contains(student)) { throw new InvalidOperationException("The student has already been added"); } if (this.students.Any(st => st.Id == student.Id)) { throw new ArgumentException("There is already a student with the same id"); } this.students.Add(student); }
public void TestCoursesAndStudents() { School academy = new School(); string[] letters = new string[] { "s", "a", "e", "ela", "ina", "ka", "ona", }; for (int i = 0; i < 5; i++) { Course pesho = new Course("Course #" + i); for (int j = 0; j < 30; j++) { Student thisStudent = new Student("Ivan" + letters[i % letters.Length], (10344 * (i + 1)) + j); pesho.AddStudent(thisStudent); academy.AddStudentToSchool(thisStudent); } academy.AddCourseToSchool(pesho); } Assert.AreEqual(this.RetutnInfo(150, 5), academy.ShowInformationAboutSchool()); }
public void TestCheckToLeaveNonParticipatedCourseToNoThrow() { Student nerd = new Student("Pavel Kolev", 11112); Student nobbie = new Student("Goran Bognanov", 15152); Course cSharp = new Course("C#"); Course cPlusPlus = new Course("C++"); Course java = new Course("Java"); nerd.JointInCourse(cSharp); nerd.JointInCourse(cPlusPlus); nerd.JointInCourse(java); nerd.LeaveFromCourse(cPlusPlus); nerd.LeaveFromCourse(cSharp); nerd.LeaveFromCourse(java); nobbie.LeaveFromCourse(java); nobbie.LeaveFromCourse(cPlusPlus); Assert.AreEqual(0, nerd.Courses.Count); Assert.AreEqual(0, nobbie.Courses.Count); }
public void TestAddRemoveStudents() { Course normalCourse = new Course("C# OOP"); string[] letters = new string[] { "s", "a", "e", "ela", "ina", "ka", "ona", }; Student[] participants = new Student[30]; for (int i = 0; i < 30; i++) { participants[i] = new Student("Ivan" + letters[i % letters.Length], 10101 + i); normalCourse.AddStudent(participants[i]); } for (int i = 0; i < 30; i++) { normalCourse.RemoveStudent(participants[i]); } for (int i = 0; i < 5; i++) { normalCourse.AddStudent(new Student("Ivan" + letters[i % letters.Length], 20101 + i)); } Assert.AreEqual(5, normalCourse.Participants.Count); }
private static void ReadAndParseInput(SortedDictionary<string, OrderedBag<Student>> sortedDictionary) { using (StreamReader reader = new StreamReader("../../students.txt")) { while (!reader.EndOfStream) { string[] studentAndCourse = reader.ReadLine() .Split(new char[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); string firstName = studentAndCourse[0]; string lastName = studentAndCourse[1]; string course = studentAndCourse[2]; Student student = new Student(firstName, lastName); if (!sortedDictionary.ContainsKey(course)) { sortedDictionary.Add(course, new OrderedBag<Student>()); } sortedDictionary[course].Add(student); } } }
private static void ParallelForeach(string[] data, SortedDictionary<string, SortedSet<Student>> result) { Parallel.ForEach( data, line => { if (string.IsNullOrEmpty(line)) { return; } string[] splitInformation = line.Split('|'); string fname = splitInformation[0].Trim(); string lname = splitInformation[1].Trim(); string course = splitInformation[2].Trim(); Student next = new Student { FirstName = fname, LastName = lname, Course = course }; if (!result.ContainsKey(course)) { lock (result) { if (!result.ContainsKey(course)) { result[course] = new SortedSet<Student> { next }; } } } else { try { result[course].Add(next); } catch (KeyNotFoundException) { // Problem solved... } catch (NullReferenceException) { // Another solved problem... } } }); }
public void TestCourseRemovingStudentToBeValid() { Course course = new Course("financial"); Student ivan1 = new Student("ivan1", 10001); Student ivan2 = new Student("ivan2", 10002); course.AddStudent(ivan1); course.AddStudent(ivan2); course.RemoveStudent(ivan1); Assert.IsTrue(course.Students.Contains(ivan2)); Assert.AreEqual(1, course.Students.Count, "Incorrect student remove"); }