TestSchedule.java


 import junit.framework.TestCase; import java.util.List; import java.util.Collection; public class TestSchedule extends TestCase {     public TestSchedule(String name) {         super(name);     }     public void testMinCredits() {         Schedule schedule = new Schedule("name");         Collection analysis = schedule.analysis();         assertEquals(1, analysis.size());         assertTrue(analysis.contains("Too few credits"));     }     public void testJustEnoughCredits() {         Course cs110 = new Course("CS110", 11);         Offering mwf10 = new Offering(1, cs110, "M10,W10,F10");         Schedule schedule = new Schedule("name");         schedule.add(mwf10);         List analysis = schedule.analysis();         assertEquals(1, analysis.size());         assertTrue(analysis.contains("Too few credits"));         schedule = new Schedule("name");         Course cs101 = new Course("CS101", 12);         Offering th11 = new Offering(1, cs101, "T11,H11");         schedule.add(th11);         analysis = schedule.analysis();         assertEquals(0, analysis.size());     }     public void testMaxCredits() {         Course cs110 = new Course("CS110", 20);         Offering mwf10 = new Offering(1, cs110, "M10,W10,F10");         Schedule schedule = new Schedule("name");         schedule.add(mwf10);         List analysis = schedule.analysis();         assertEquals(1, analysis.size());         assertTrue(analysis.contains("Too many credits"));         schedule.authorizeOverload(true);         analysis = schedule.analysis();         assertEquals(0, analysis.size());     }     public void testJustBelowMax() {         Course cs110 = new Course("CS110", 19);         Offering mwf10 = new Offering(1, cs110, "M10,W10,F10");         Schedule schedule = new Schedule("name");         schedule.add(mwf10);         List analysis = schedule.analysis();         assertEquals(1, analysis.size());         assertTrue(analysis.contains("Too many credits"));         schedule = new Schedule("name");         Course cs101 = new Course("CS101", 18);         Offering th11 = new Offering(1, cs101, "T11,H11");         schedule.add(th11);         analysis = schedule.analysis();         assertEquals(0, analysis.size());     }     public void testDupCourses() {         Course cs110 = new Course("CS110", 6);         Offering mwf10 = new Offering(1, cs110, "M10,W10,F10");         Offering th11 = new Offering(1, cs110, "T11,H11");         Schedule schedule = new Schedule("name");         schedule.add(mwf10);         schedule.add(th11);         List analysis = schedule.analysis();         assertEquals(1, analysis.size());         assertTrue(analysis.contains("Same course twice - CS110"));     }     public void testOverlap() {         Schedule schedule = new Schedule("name");         Course cs110 = new Course("CS110", 6);         Offering mwf10 = new Offering(1, cs110, "M10,W10,F10");         schedule.add(mwf10);         Course cs101 = new Course("CS101", 6);         Offering mixed = new Offering(1, cs101, "M10,W11,F11");         schedule.add(mixed);         List analysis = schedule.analysis();         assertEquals(1, analysis.size());         assertTrue(analysis.contains("Course overlap - M10"));         Course cs102 = new Course("CS102", 1);         Offering mixed2 = new Offering(1, cs102, "M9,W10,F11");         schedule.add(mixed2);         analysis = schedule.analysis();         assertEquals(3, analysis.size());         assertTrue(analysis.contains("Course overlap - M10"));         assertTrue(analysis.contains("Course overlap - W10"));         assertTrue(analysis.contains("Course overlap - F11"));     }     public void testCourseCreate() throws Exception {         Course c = Course.create("CS202", 1);         Course c2 = Course.find("CS202");         assertEquals("CS202", c2.getName());         Course c3 = Course.find("Nonexistent");         assertNull(c3);     }     public void testOfferingCreate() throws Exception {         Course c = Course.create("CS202", 2);         Offering offering = Offering.create(c, "M10");         assertNotNull(offering);     }     public void testPersistentSchedule() throws Exception {         Schedule s = Schedule.create("Bob");         assertNotNull(s);     }     public void testScheduleUpdate() throws Exception {         Course cs101 = Course.create("CS101", 3);         cs101.update();         Offering off1 = Offering.create(cs101, "M10");         off1.update();         Offering off2 = Offering.create(cs101, "T9");         off2.update();         Schedule s = Schedule.create("Bob");         s.add(off1);         s.add(off2);         s.update();         Schedule s2 = Schedule.create("Alice");         s2.add(off1);         s2.update();         Schedule s3 = Schedule.find("Bob");         assertEquals(2, s3.schedule.size());         Schedule s4 = Schedule.find("Alice");         assertEquals(1, s4.schedule.size());     } } 


Refactoring Workbook
Refactoring Workbook
ISBN: 0321109295
EAN: 2147483647
Year: 2003
Pages: 146

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net