Skip to content

Instantly share code, notes, and snippets.

@hamoungh
Last active August 29, 2015 14:10
Show Gist options
  • Save hamoungh/8b927f4aff4b54617eef to your computer and use it in GitHub Desktop.
Save hamoungh/8b927f4aff4b54617eef to your computer and use it in GitHub Desktop.

test case 1 (main assignment):

        typetest("school.University");
        typetest("school.Faculty");
        typetest("school.Department");
        typetest("school.Course");
        typetest("school.Student");

test case 2 (main assignment):

 new school.Student( "fname", "lastname" );

test case 3 (main assignment):

        Type type = Type.GetType("school.Student");
        MethodInfo enterGrade = type.GetMethod("enterGrade");
        Student st = new Student("Alan", "Turing");
        st.enterGrade.Invoke( new school.Course("c1"), 21 );
        st.enterGrade.Invoke( new school.Course("c2"), 22 );
        double result = st.calculateAverage();
        if (result != 21.5)
            throw new Exception("Average of 21 and 22 Should be 21.5");

Test case 4 (bonus mark):

       Faculty scienceFac = University.createFaculty("Science");
       Faculty engineeringFac = University.createFaculty("Engineering");
	if (University.numberOfFaculties()!=2) 
             throw new Exception( "I was expecting two faculties to be created ");  

Test case five (bonus mark):

             Faculty scienceFac = University.createFaculty("Science");
        Department compSciDept = scienceFac.openNewDepartment("Physics");
	 if(!Object.ReferenceEquals(
             scienceFac, physicsDept.Faculty))
             throw new Exception("Failed to set the field faculty"+
                         "in the Department object in the method openNewDepartment"); 

Test case six (bonus mark):

        Faculty scienceFac = University.createFaculty("Science");
        Department compSciDept = scienceFac.openNewDepartment("Computer Science");
        Student st1 = new Student("Alan", "Turing");
        compSciDept.addStudent(st1);
        if (!Object.ReferenceEquals(compSciDept, st1.Department))
                throw new Exception("Failed to set the field department" +
                        "in the Student object in the method Department.addStudent(...)");  
static void testFacultyCreation()
{
Faculty scienceFac = University.createFaculty("Science");
Faculty engineeringFac = University.createFaculty("Engineering");
if (University.numberOfFaculties()!=2)
throw new Exception( "I was expecting two faculties to be created ");
}
static void testDepartmentCreation()
{
Faculty scienceFac = University.createFaculty("Science");
Department compSciDept = scienceFac.openNewDepartment("Physics");
if(!Object.ReferenceEquals(
scienceFac, physicsDept.Faculty))
throw new Exception("Failed to set the field faculty"+
"in the Department object in the method openNewDepartment");
}
static void testStudentCreation()
{
Faculty scienceFac = University.createFaculty("Science");
Department compSciDept = scienceFac.openNewDepartment("Computer Science");
Student st1 = new Student("Alan", "Turing");
compSciDept.addStudent(st1);
if (!Object.ReferenceEquals(compSciDept, st1.Department))
throw new Exception("Failed to set the field department" +
"in the Student object in the method Department.addStudent(...)");
}
static void testAveraging()
{
Type type = Type.GetType("school.Student");
MethodInfo enterGrade = type.GetMethod("enterGrade");
Student st = new Student("Alan", "Turing");
st.enterGrade.Invoke( new school.Course("c1"), 21 );
st.enterGrade.Invoke( new school.Course("c2"), 22 );
double result = st.calculateAverage();
if (result != 21.5)
throw new Exception("Average of 21 and 22 Should be 21.5");
}
static void testFields()
{
fieldcheck("school.Student", "fname");
fieldcheck("school.Student", "lname");
fieldcheck("school.Department", "name");
fieldcheck("school.Faculty", "name");
fieldcheck("school.Course", "name");
}
static void testConstructors()
{
new school.Student( "fname", "lastname" );
static void testClassExistence()
{
typetest("school.University");
typetest("school.Faculty");
typetest("school.Department");
typetest("school.Course");
typetest("school.Student");
}
static void Main()
{
int choice = int.Parse(Console.ReadLine());
if (choice == 1) testClassExistence();
// else if (choice == 2) testFields();
else if (choice == 2) testConstructors();
else if (choice == 3) testAveraging();
else if (choice == 4) testFacultyCreation();
else if (choice == 5) testDepartmentCreation();
else if (choice == 6) testStudentCreation();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment