Skip to content

Instantly share code, notes, and snippets.

@genecyber
Created January 27, 2012 18:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save genecyber/1690209 to your computer and use it in GitHub Desktop.
Save genecyber/1690209 to your computer and use it in GitHub Desktop.
Baby Code With Test
package code.family.additions;
import java.util.Calendar;
import java.util.Date;
public class BabyCode extends Code {
public Date DueDate;
public BabyCode(Code mother, Code father) {
super();
Utility utils = new Utility();
_genes = utils.join(mother.GetReproductiveGenes(), father.GetReproductiveGenes());
CalculateDueDate(mother.GetOvulationDate());
}
protected void CalculateDueDate(Calendar date) {
date.add(Calendar.DAY_OF_WEEK,266);
DueDate = new Date(date.getTimeInMillis());
}
}
package code.family.additions;
import static org.junit.Assert.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.junit.Before;
import org.junit.Test;
public class BabyCodeTests {
private BabyCode newBaby;
private Code father;
private Code mother;
@Before
public void setup() {
father = new Code("Shannon Code");
mother = new Code("Dawn Code");
}
@Test
public void BabyIsNotNull() throws ParseException {
mother.SetOvulationDate(new SimpleDateFormat("MM/dd/yyyy").parse("11/14/2011"));
newBaby = new BabyCode(mother,father);
assertNotNull(newBaby.DueDate);
}
}
package code.family.additions;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
public class Code {
private String _name;
public Code() {}
public Code(String name) {_name = name;}
protected Date _ovulationDate;
protected String[] _genes;
public String[] GetReproductiveGenes() {
return new String[]{"A", "T", "G", "C"};
}
public void SetOvulationDate(Date date) throws ParseException {
_ovulationDate = date;
}
public Calendar GetOvulationDate() {
Calendar date = Calendar.getInstance();
date.set(Calendar.DAY_OF_MONTH, _ovulationDate.getDate());
date.set(Calendar.MONTH, _ovulationDate.getMonth());
date.set(Calendar.YEAR, _ovulationDate.getYear());
return date;
}
}
@ripper234
Copy link

Congratulations, even if overdue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment