[TestMethod]//TO DO: Test Person Functions public void TestPersonToString() { var gp = new GenotypeRepository(); var j = new Person("Jess Potts", Sex.Female, true, gp); string jess = j.ToString(); Assert.AreEqual("Jess Potts Female", jess); }
public void SetUp() { GeneticCounsellorDbContext context = null; using (context = new GeneticCounsellorDbContext("Jess1")) { var traitRepository = new TraitRepository(context); var personRepository = new PersonRepository(context); genotypeRepository = new GenotypeRepository(context); rng = new RealRandomNumberGenerator(); } }
private static void FamilyTreeScreen(PersonRepository personRepository, GenotypeRepository genotypeRepository)//Screen for user to interact with for family tree { StringBuilder sb = new StringBuilder(); ListAllPersonsScreen(sb, personRepository, genotypeRepository); string s = sb.ToString(); Console.Write(s); Person SelectedPerson = FindPersonByIndex(personRepository); Console.WriteLine("How many generations should this system display?"); int numberOfGenerations = Convert.ToInt32(Console.ReadLine()); DrawGeneration(SelectedPerson, numberOfGenerations); }
private static void ListAllPersonsChoice(PersonRepository personRepository, GenotypeRepository genotypeRepository) { StringBuilder sb = new StringBuilder(); ListAllPersonsScreen(sb, personRepository, genotypeRepository); string s = sb.ToString(); Console.Write(s); Console.WriteLine("____________________________________________________"); Console.WriteLine("-----------------------------------------------------"); Console.WriteLine("1) Select a Person"); Console.WriteLine("2) Delete a Person"); Console.WriteLine("3) Add a person"); Console.WriteLine("-----------------------------------------------------"); }
public void TestAddPerson() { var gp = new GenotypeRepository(); var j = new Person("Jess Potts", Sex.Female, true, gp); var e = new Person("Erica Korner", Sex.Female, true, gp); var p = new Person("paul Korner", Sex.Female, true, gp); var rep = new PersonRepository(); rep.AddPerson(j); rep.AddPerson(e); var result = rep.ListPersons(); Assert.IsTrue(result.Contains(j)); Assert.IsTrue(result.Contains(e)); Assert.IsFalse(result.Contains(p)); }
private static void AddPersonScreen(PersonRepository personRepository, GenotypeRepository genotypeRepository) { Console.Clear(); try { Console.WriteLine("Name (first and last): "); string inputName = Console.ReadLine(); if (inputName == null || inputName == " ") { throw new Exception(); } Console.WriteLine("Sex ( Male or Female ): "); string inputtedSex = Console.ReadLine(); if (inputtedSex == null) { throw new Exception(); } Sex inputSex = (Sex)Enum.Parse(typeof(Sex), inputtedSex, true); if (inputSex == Sex.Female || inputSex == Sex.Male || inputSex == Sex.Unknown) { Console.WriteLine("Living (true or false): "); string acceptableTrueString = "true"; string acceptableFalseString = "false"; string inputtedLiving = Console.ReadLine(); if (inputtedLiving == acceptableTrueString || inputtedLiving == acceptableFalseString) { bool inputLiving = (bool)Convert.ToBoolean(inputtedLiving); personRepository.AddPerson(inputName, inputSex, inputLiving, "unaffected"); } else { throw new Exception(); } } else { throw new Exception(); } } catch (Exception) { Console.WriteLine("Input was not valid, press any button to try again."); Console.ReadLine(); AddPersonScreen(personRepository, genotypeRepository); } }
private static void GeneticCounsellor() //Reads in all database information into Repositoriesand context { GeneticCounsellorDbContext context = null; using (context = new GeneticCounsellorDbContext("Jess1")) { var traitRepository = new TraitRepository(context); var personRepository = new PersonRepository(context); var genotypeRepository = new GenotypeRepository(context); var rng = new RealRandomNumberGenerator(); string personFilename = @"C:\Users\potts\Desktop\PersonsSeedData.txt"; string traitFilename = @"C:\Users\potts\Desktop\TraitSeedData.txt"; geneticCounsellorScreen(genotypeRepository, traitRepository, personRepository, personFilename, traitFilename, rng, context); } }
public void TestLoadFile() { var rng = new PredictableRandomNumberGenerator(); var gp = new GenotypeRepository(); var g = new Genotype('A', Dominance.Dominant, Dominance.Recessive, rng); var myPersonRepository = new PersonRepository(); string[] records = new string[1000]; myPersonRepository.LoadFile("PersonsSeedData.txt"); var ListofPersons = new List <Person>(); ListofPersons = myPersonRepository.ListPersons(); var TestPerson = new Person("Abigail Adams", Sex.Female, true, gp); Assert.AreEqual("Abigail Adams Female A a", ListofPersons[5].ToString()); }
private static void DeletePerson(PersonRepository personRepository, GenotypeRepository genotypeRepository) { Console.WriteLine("Are you sure you wish to delete this person? Yes/No"); string answer = Console.ReadLine(); if (answer == "Yes" || answer == "yes") { Person selectedPersonToDelete = FindPersonByIndex(personRepository); //DELETES A PERSON personRepository.DeletePerson(selectedPersonToDelete); Console.WriteLine("#########################"); Console.WriteLine("Person has been deleted."); Console.WriteLine("#########################"); } else { ListAllPersonsChoice(personRepository, genotypeRepository); } }
public void TestReturnPerson() { var gp = new GenotypeRepository(); var j = new Person("Jess Potts", Sex.Female, true, gp); var e = new Person("Erica Korner", Sex.Female, true, gp); var p = new Person("Paul Korner", Sex.Female, true, gp); var rep = new PersonRepository(); rep.AddPerson(j); rep.AddPerson(e); var testList = new List <Person>(); testList.Add(j); testList.Add(e); var result = rep.ListPersons(); CollectionAssert.AreEqual(testList, result); }
private static void ChangeSex(TraitRepository traitRepository, Person SelectedPerson, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Console.WriteLine("Please input a new sex (Male, Female or Unknown)"); string inputtedSex = Console.ReadLine(); Sex newSex = (Sex)Enum.Parse(typeof(Sex), inputtedSex, true); SelectedPerson.Sex = newSex; context.SaveChanges(); PersonScreen(traitRepository, SelectedPerson, personRepository, genotypeRepository, rng, context); //returns user to last menu }
private static void AddExsistingGenotype(TraitRepository traitRepository, Person SelectedPerson, GenotypeRepository genotypeRepository, PersonRepository personRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Console.Clear(); Console.WriteLine("Already exsisting Genotypes:"); int num = 0; foreach (var g in genotypeRepository.ListGenotypes()) { Console.WriteLine(num + ") " + g); num++; } Console.WriteLine("Select a genotype from list:"); int genotypeIndex = Convert.ToInt32(Console.ReadLine()); var Allgenotypes = genotypeRepository.ListGenotypes(); SelectedPerson.AddGenotypeToPerson(Allgenotypes[genotypeIndex]); context.SaveChanges(); PersonScreen(traitRepository, SelectedPerson, personRepository, genotypeRepository, rng, context); //returns user to last menu }
private static void changeLiving(TraitRepository traitRepository, Person SelectedPerson, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Console.WriteLine("Please input a new Living status (True, False)"); string acceptableTrueString = "true"; string acceptableFalseString = "False"; string inputtedLiving = Console.ReadLine(); if (inputtedLiving == acceptableTrueString || inputtedLiving == acceptableFalseString) { bool inputLiving = (bool)Convert.ToBoolean(inputtedLiving); SelectedPerson.Living = inputLiving; } context.SaveChanges(); PersonScreen(traitRepository, SelectedPerson, personRepository, genotypeRepository, rng, context); //returns user to last menu }
private static void AddFather(TraitRepository traitRepository, Person selectedPerson, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { StringBuilder sb = new StringBuilder(); ListAllPersonsScreen(sb, personRepository, genotypeRepository); string s = sb.ToString(); Console.Write(s); Person personToBeFather = FindPersonByIndex(personRepository); bool can = selectedPerson.CanAddFather(personToBeFather); if (can) { selectedPerson.AddFatherToPerson(personToBeFather); context.SaveChanges(); PersonScreen(traitRepository, selectedPerson, personRepository, genotypeRepository, rng, context); } else { Console.WriteLine("Only biological males can be entered as biological fathers."); Console.ReadLine(); } }
private static void DeleteGenotype(Person SelectedPerson, TraitRepository traitRepository, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Genotype genotypeToBeDeleted = GetSelectedPersonsGenotype(SelectedPerson, traitRepository, personRepository, genotypeRepository, rng, context); SelectedPerson.Phenotype.TraitGenotypes.Remove(genotypeToBeDeleted); context.SaveChanges(); // context.Genotypes.Remove(); HOW TO REMOVE FROM THE DATABASE }
private static void geneticCounsellorScreen(GenotypeRepository genotypeRepository, TraitRepository traitRepository, PersonRepository personRepository, string personFilename, string traitFilename, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Console.Clear(); Console.WriteLine("____________________________________________________"); Console.WriteLine("1) Add Person"); Console.WriteLine("2) List all Persons"); Console.WriteLine("3) Create trait"); Console.WriteLine("4) List all traits"); Console.WriteLine("5) Create family tree"); Console.WriteLine("____________________________________________________"); int geneticCounsellorMenuOption = MenuUserInputInt(5); switch (geneticCounsellorMenuOption)//Allows user to navigate menu using integer keyboard inputs { case 0: Console.Clear(); MainMenuScreen(); break; case 1: AddPersonScreen(personRepository, genotypeRepository); geneticCounsellorScreen(genotypeRepository, traitRepository, personRepository, personFilename, traitFilename, rng, context); break; case 2: ListAllPersonsChoice(personRepository, genotypeRepository); int ListAllPersonsScreenOption = MenuUserInputInt(3); switch (ListAllPersonsScreenOption) { case 0: geneticCounsellorScreen(genotypeRepository, traitRepository, personRepository, personFilename, traitFilename, rng, context); break; case 1: Person selectedPerson = FindPersonByIndex(personRepository); PersonScreen(traitRepository, selectedPerson, personRepository, genotypeRepository, rng, context); //SELECTS A PERSON break; case 2: DeletePerson(personRepository, genotypeRepository); break; case 3: AddPersonScreen(personRepository, genotypeRepository); geneticCounsellorScreen(genotypeRepository, traitRepository, personRepository, personFilename, traitFilename, rng, context); break; default: throw new Exception("Invalid Menu input"); } break; case 3: CreateTraitScreen(traitRepository); break; case 4: ListAllTraitsChoice(traitRepository); int ListAllTraitsScreenOption = MenuUserInputInt(2); switch (ListAllTraitsScreenOption) { case 0: geneticCounsellorScreen(genotypeRepository, traitRepository, personRepository, personFilename, traitFilename, rng, context); break; case 1: CreateTraitScreen(traitRepository); break; case 2: Trait selectedTraitToDelete = FindTraitByIndex(traitRepository); //DELETES A TRAIT traitRepository.DeleteTrait(selectedTraitToDelete); Console.WriteLine("#######################"); Console.WriteLine("Trait has been deleted."); Console.WriteLine("#######################"); break; } break; case 5: FamilyTreeScreen(personRepository, genotypeRepository); break; default: throw new Exception("Invalid Menu input"); } }
private static void AddExsistingTrait(Person selectedPerson, TraitRepository traitRepository, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Console.Clear(); Console.WriteLine("Already exsisting Traits:"); int num = 0; foreach (var t in traitRepository.ListTraits()) { Console.WriteLine(num + ") " + t); num++; } Console.WriteLine("Select a trait from the list:"); int traitIndex = Convert.ToInt32(Console.ReadLine()); var allTraits = traitRepository.ListTraits(); Trait chosenTrait = allTraits[traitIndex]; selectedPerson.AddTraitToPerson(chosenTrait); Console.WriteLine("Select which genotype to add to person:"); chosenTrait.GenerateGenotypesForATrait(genotypeRepository); AddExsistingGenotype(traitRepository, selectedPerson, genotypeRepository, personRepository, rng, context); context.SaveChanges(); PersonScreen(traitRepository, selectedPerson, personRepository, genotypeRepository, rng, context); }
private static void DeleteTrait(Person selectedPerson, TraitRepository traitRepository, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Trait traitToBeDeleted = GetSelectedPersonsTrait(selectedPerson, traitRepository, personRepository, genotypeRepository, rng, context); selectedPerson.Phenotype.Traits.Remove(traitToBeDeleted); context.SaveChanges(); }
private static Trait GetSelectedPersonsTrait(Person selectedPerson, TraitRepository traitRepository, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { var listOfSelectedPersonTraits = selectedPerson.Phenotype.Traits; if (selectedPerson.Phenotype.Traits.Count == 0) { Console.Clear(); Console.WriteLine("This person does not have any Traits"); PersonScreen(traitRepository, selectedPerson, personRepository, genotypeRepository, rng, context); PersonScreenMenu(traitRepository, personRepository, selectedPerson, genotypeRepository, rng, context); } int number = 1; foreach (var trait in selectedPerson.Phenotype.Traits) { Console.WriteLine(number + ") " + trait.ToString()); number = number + 1; } try { Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++"); Console.WriteLine("Please input the index of trait you want to select: "); int index = Convert.ToInt32(Console.ReadLine()); Trait selectedPersonTrait = listOfSelectedPersonTraits[index - 1]; return(selectedPersonTrait); } catch (Exception) { Console.WriteLine("There is no Trait located at that index. Please try again"); return(GetSelectedPersonsTrait(selectedPerson, traitRepository, personRepository, genotypeRepository, rng, context)); } }
private static void ListAllPersonsScreen(StringBuilder sb, PersonRepository personRepository, GenotypeRepository genotypeRepository) { Console.Clear(); var ListOfPersons = personRepository.ListPersons(); int i = 0; if (ListOfPersons.Count == 0) { sb.AppendLine("There are no Persons in this system, please add one."); Console.ReadLine(); } else { Console.WriteLine("____________________________________________________"); foreach (var person in ListOfPersons) { i++; sb.AppendLine(i + " " + person.ToString()); } } }
private static void ChangeName(TraitRepository traitRepository, Person SelectedPerson, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Console.WriteLine("Please input a new full name"); string newName = Console.ReadLine(); if (newName == "") { Console.WriteLine("It is against the Geneva convention for a person to be denied a name"); } SelectedPerson.Name = newName; context.SaveChanges(); PersonScreen(traitRepository, SelectedPerson, personRepository, genotypeRepository, rng, context);//returns user to last menu }
private static void CalculateParentalGenotypes(Person selectedPerson, TraitRepository traitRepository, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Genotype genotypeToTrace = GetSelectedPersonsGenotype(selectedPerson, traitRepository, personRepository, genotypeRepository, rng, context); List <Genotype> parentalGenotypes = genotypeToTrace.CalculateParentalGenotypes(genotypeRepository, rng); Console.WriteLine("Here are the potential parental genotypes:"); Console.WriteLine("===================================================="); foreach (var genotype in parentalGenotypes) { Console.WriteLine(genotype); } }
private static void PersonScreen(TraitRepository traitRepository, Person SelectedPerson, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Console.Clear(); Console.WriteLine("Name: " + SelectedPerson.Name); Console.WriteLine("Sex: " + SelectedPerson.Sex); Console.WriteLine("Living Status:" + SelectedPerson.Living); string traitOutput = ""; foreach (var traits in SelectedPerson.Phenotype.Traits) { traitOutput = traitOutput + traits.ToString() + ","; } Console.WriteLine("Traits: " + traitOutput); string outputGenotypes = ""; foreach (var genotype in SelectedPerson.Phenotype.TraitGenotypes) { outputGenotypes = outputGenotypes + genotype.ToString() + ','; } Console.WriteLine("Genotypes: " + outputGenotypes); try { UpdatePhenotype(SelectedPerson); } catch (Exception) { Console.WriteLine("Phenotype: N/A"); } try { Console.WriteLine("Mother: " + SelectedPerson.Mother.Name); //recursive viewing of the whole family Console.WriteLine("Father: " + SelectedPerson.Father.Name); } catch (Exception) { Console.WriteLine("Incomplete parents inputted."); } PersonScreenMenu(traitRepository, personRepository, SelectedPerson, genotypeRepository, rng, context); }
private static void PersonScreenMenu(TraitRepository traitRepository, PersonRepository personRepository, Person selectedPerson, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Console.WriteLine("----------------------------------------------------------------------------------------------------------"); Console.WriteLine("1) Edit Person"); Console.WriteLine("2) Combine Genotype with other person"); Console.WriteLine("3) Update Phenotype"); Console.WriteLine("4) Calculate Parental Genotypes"); Console.WriteLine("----------------------------------------------------------------------------------------------------------"); int PersonMenuChoice = MenuUserInputInt(4); switch (PersonMenuChoice) { case 0: Console.Clear(); StringBuilder sb = new StringBuilder(); //return to last menu ListAllPersonsScreen(sb, personRepository, genotypeRepository); break; case 1: //Edit Person EditPersonScreen(traitRepository, personRepository, selectedPerson, genotypeRepository, rng, context); break; case 2: //Combine Genotypes CombineGenotypesScreen(selectedPerson, personRepository, genotypeRepository, rng, traitRepository, context); break; case 3: //update Phenotype UpdatePhenotype(selectedPerson); break; case 4: CalculateParentalGenotypes(selectedPerson, traitRepository, personRepository, genotypeRepository, rng, context); break; default: throw new Exception("Invalid Menu input"); } }
private static void CombineGenotypesScreen(Person selectedPerson, PersonRepository personRepository, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, TraitRepository traitRepository, GeneticCounsellorDbContext context)//TO DO: Change Seed Data to be compatible with added Genotypes { Console.Clear(); Genotype firstSelectedPerson = GetSelectedPersonsGenotype(selectedPerson, traitRepository, personRepository, genotypeRepository, rng, context); //Selected Genotypes //Ensure only males and females are compatible StringBuilder sb = new StringBuilder(); ListAllPersonsScreen(sb, personRepository, genotypeRepository); string s = sb.ToString(); Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++"); Console.WriteLine("Please select a person to combine genotypes with:"); Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++"); Console.Write(s); Person otherPerson = FindPersonByIndex(personRepository); Genotype otherSelectedPerson = GetSelectedPersonsGenotype(otherPerson, traitRepository, personRepository, genotypeRepository, rng, context); Genotype resultingGenotype = firstSelectedPerson.MostLikelyGenotype(otherSelectedPerson, genotypeRepository, rng); Console.WriteLine("______________________________________________________________________________________________________________"); Console.WriteLine(resultingGenotype.ToString() + " is the most likely genotype combination in offspring between these two persons"); Console.WriteLine("______________________________________________________________________________________________________________"); }
private static void EditPersonScreen(TraitRepository traitRepository, PersonRepository personRepository, Person selectedPerson, GenotypeRepository genotypeRepository, RealRandomNumberGenerator rng, GeneticCounsellorDbContext context) { Console.WriteLine("1) Change Name"); Console.WriteLine("2) Change Sex"); Console.WriteLine("3) Change Living"); Console.WriteLine("4) Add an exsisting Genotype from database"); Console.WriteLine("5) Delete a Genotype from Person "); Console.WriteLine("6) Add an exsisting Trait from database"); Console.WriteLine("7) Delete a Trait from person"); Console.WriteLine("8) Add Mother from exsisting list of Persons"); Console.WriteLine("9) Add Father from exsisting list of Persons"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); int EditPersonMenuChoice = MenuUserInputInt(9); switch (EditPersonMenuChoice) { case 0: PersonScreenMenu(traitRepository, personRepository, selectedPerson, genotypeRepository, rng, context); break; case 1: ChangeName(traitRepository, selectedPerson, personRepository, genotypeRepository, rng, context); break; case 2: ChangeSex(traitRepository, selectedPerson, personRepository, genotypeRepository, rng, context); break; case 3: changeLiving(traitRepository, selectedPerson, personRepository, genotypeRepository, rng, context); break; case 4: StringBuilder sb = new StringBuilder(); ListAllPersonsScreen(sb, personRepository, genotypeRepository); string s = sb.ToString(); Console.Write(s); AddExsistingGenotype(traitRepository, selectedPerson, genotypeRepository, personRepository, rng, context); break; case 5: DeleteGenotype(selectedPerson, traitRepository, personRepository, genotypeRepository, rng, context); break; case 6: AddExsistingTrait(selectedPerson, traitRepository, personRepository, genotypeRepository, rng, context); break; case 7: DeleteTrait(selectedPerson, traitRepository, personRepository, genotypeRepository, rng, context); break; case 8: AddMother(traitRepository, selectedPerson, personRepository, genotypeRepository, rng, context); break; case 9: AddFather(traitRepository, selectedPerson, personRepository, genotypeRepository, rng, context); break; } }