Last active
August 29, 2015 14:05
-
-
Save MinCha/78a62e7158ae5757bc1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testGetPrescription() throws Exception { | |
NewPrescription prescription = new NewPrescription(); | |
assertEquals("two pill a day", prescription.getPrescription(new SeriousPatientStatus(), new AdultPatientType())); | |
assertEquals("one pill a day", prescription.getPrescription(new MildPatientStatus(), new AdultPatientType())); | |
assertEquals("one pill a day", prescription.getPrescription(new SeriousPatientStatus(), new ChildPatientType())); | |
assertEquals("half pill a day", prescription.getPrescription(new MildPatientStatus(), new ChildPatientType())); | |
} | |
public interface PatientStatus { | |
String getPrescriptionWith(PatientType type); | |
double getMaxIngrestionPerDayWith(PatientType type); | |
} | |
public interface PatientType { | |
String getPrescriptionSerious(); | |
double getMaxIngrestionSerious(); | |
String getPrescriptionMild(); | |
double getMaxIngrestionMild(); | |
} | |
public class AdultPatientType implements PatientType { | |
@Override | |
public String getPrescriptionSerious() { | |
return "two pill a day"; | |
} | |
@Override | |
public double getMaxIngrestionSerious() { | |
return 2; | |
} | |
@Override | |
public String getPrescriptionMild() { | |
return "one pill a day"; | |
} | |
@Override | |
public double getMaxIngrestionMild() { | |
return 1; | |
} | |
} | |
public class ChildPatientType implements PatientType { | |
@Override | |
public String getPrescriptionSerious() { | |
return "one pill a day"; | |
} | |
@Override | |
public double getMaxIngrestionSerious() { | |
return 1; | |
} | |
@Override | |
public String getPrescriptionMild() { | |
return "half pill a day"; | |
} | |
@Override | |
public double getMaxIngrestionMild() { | |
return 0; | |
} | |
} | |
public class MildPatientStatus implements PatientStatus { | |
@Override | |
public String getPrescriptionWith(PatientType type) { | |
return type.getPrescriptionMild(); | |
} | |
@Override | |
public double getMaxIngrestionPerDayWith(PatientType type) { | |
return type.getMaxIngrestionMild(); | |
} | |
} | |
public class SeriousPatientStatus implements PatientStatus { | |
@Override | |
public String getPrescriptionWith(PatientType type) { | |
return type.getPrescriptionSerious(); | |
} | |
@Override | |
public double getMaxIngrestionPerDayWith(PatientType type) { | |
return type.getMaxIngrestionSerious(); | |
} | |
} | |
public class NewPrescription { | |
public String getPrescription(PatientStatus status, PatientType type) { | |
return status.getPrescriptionWith(type); | |
} | |
public double getMaxIngestionPerDay(PatientStatus status, PatientType type) { | |
return status.getMaxIngrestionPerDayWith(type); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment