public void TestSetAge() { var item = new Platypus(); item.Age = 5; Assert.Equal(5, item.Age); }
public void TestIncorrectSetAge() { var item = new Platypus(); item.Age = -5; Assert.Equal(0, item.Age); }
public void PlatypusIsASwimmingAnimal() { Platypus abomination = new Platypus(); Assert.Equal("I'm a platypus and I can swim!", abomination.Swim()); Assert.IsAssignableFrom <Animals>(abomination); }
public void PlatypusCanSpeakAndIsVenomous() { Platypus abomination = new Platypus(); Assert.Equal("Quack?", abomination.Speak()); Assert.True(abomination.IsVenomous); }
public void TestEmptyConstructor() { var item = new Platypus(); Assert.Equal(0, item.Age); Assert.Equal("Untitled", item.Name); Assert.True(item.IsMale); }
public void Interpret(Expr expr) { try { Console.WriteLine(Evaluate(expr)); } catch (RuntimeException ex) { Platypus.GenerateRuntimeException(ex); } }
public void PlatypusHasBill() { //Arrange Platypus p2 = new Platypus() { Name = "Shirley" }; //Assert Assert.Equal("duck bill", p2.billType); }
public void PlatypusCanLayEgg() { //Arrange Platypus p1 = new Platypus() { Name = "Silvia Plat" }; //Assert Assert.Equal("Plop goes the egg!", p1.LayEgg()); }
public void TestView() { var item = new Platypus(); var view = @" _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, ______,' -o :. _ . ; ,'`, `. ( -\.._,.;;'._ ,( } _`_-_,, `, `, ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' "; Assert.Equal(view, item.View()); }
private async void AddPet_OnClicked(object sender, EventArgs e) { var newPetName = PetNameEntry.Text; if (string.IsNullOrWhiteSpace(newPetName)) { SetInfoLabel("Name must not be empty."); return; } var ownerIndex = OwnerPicker.SelectedIndex; if (ownerIndex < 0) { SetInfoLabel("Select an owner."); return; } var owner = _people[ownerIndex]; Animal animal; if (AnimalKindPicker.SelectedIndex == 0) { animal = new Dog(); } else { animal = new Platypus(); } animal.Name = newPetName; animal.Owner = owner; using (var db = new PetsDbContext()) { db.People.Attach(owner); db.Set <Animal>().Add(animal); await db.SaveChangesAsync(); } LoadPets(); }
static void Main(string[] args) { // // OLD MACDONALD // Chicken chicken = new Chicken(); Cow cow = new Cow(); Duck duck = new Duck(); Velociraptor cicero = new Velociraptor(); Platypus occam = new Platypus(); // Show implicit casting (Chicken to Farm Animal) FarmAnimal console = duck; Console.WriteLine(console.NameOfAnimal); Console.WriteLine(console.MakeSoundOnce()); Console.WriteLine(console.MakeSoundTwice()); Console.WriteLine(); // Show explicit casting (FarmAnimal to Chicken) Duck myDuck = (Duck)console; Console.WriteLine(myDuck.NameOfAnimal); Console.WriteLine(myDuck.MakeSoundOnce()); Console.WriteLine(myDuck.MakeSoundTwice()); Console.WriteLine(); //Applying Polymorphism, we're allowed to work in terms of // generic types and not concrete classes. In this case // the list holds a collection of IFarmAnimal, meaning // any class that implements the IFarmAnimal interface is allowed // to be in the list. //Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh"); //Console.WriteLine("And on his farm there was a " + chicken.NameOfAnimal + " ee ay ee ay oh"); //Console.WriteLine("With a " + chicken.MakeSoundTwice() + " here and a " + chicken.MakeSoundTwice() + " there"); //Console.WriteLine("Here a " + chicken.MakeSoundOnce() + ", there a " + chicken.MakeSoundOnce() + " everywhere a " + chicken.MakeSoundTwice()); //Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh"); //Console.WriteLine(); //Console.WriteLine("And on his farm there was a " + cow.NameOfAnimal + " ee ay ee ay oh"); //Console.WriteLine("With a " + cow.MakeSoundTwice() + " here and a " + cow.MakeSoundTwice() + " there"); //Console.WriteLine("Here a " + cow.MakeSoundOnce() + ", there a " + cow.MakeSoundOnce() + " everywhere a " + cow.MakeSoundTwice()); //Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh"); //Console.WriteLine(); //Console.WriteLine("And on his farm there was a " + duck.NameOfAnimal + " ee ay ee ay oh"); //Console.WriteLine("With a " + duck.MakeSoundTwice() + " here and a " + duck.MakeSoundTwice() + " there"); //Console.WriteLine("Here a " + duck.MakeSoundOnce() + ", there a " + duck.MakeSoundOnce() + " everywhere a " + duck.MakeSoundTwice()); //Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh"); //Console.WriteLine(); // ----- THIS IS GETTING REPETITIVE! // We can do better // How can we use what we've learned about inheritance // to help us remove code duplication // // What if we create some sort of base class that all our animals have in common? List <FarmAnimal> animals = new List <FarmAnimal>(); animals.Add(chicken); animals.Add(cow); animals.Add(duck); Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh"); foreach (FarmAnimal animal in animals) { Console.WriteLine("And on his farm there was a " + animal.NameOfAnimal + " ee ay ee ay oh"); Console.WriteLine("With a " + animal.MakeSoundTwice() + " here and a " + animal.MakeSoundTwice() + " there"); Console.WriteLine("Here a " + animal.MakeSoundOnce() + ", there a " + animal.MakeSoundOnce() + " everywhere a " + animal.MakeSoundTwice()); Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh"); Console.WriteLine(); } // Interface List <IFarmAnimal> interfaceAnimals = new List <IFarmAnimal>(); interfaceAnimals.Add(cicero); interfaceAnimals.Add(occam); Console.WriteLine(); Console.WriteLine("Old MacDonald had a farm ee ay ee ay oh"); foreach (IFarmAnimal animal in interfaceAnimals) { Console.WriteLine("And on his farm there was a " + animal.NameOfAnimal + " ee ay ee ay oh"); Console.WriteLine("With a " + animal.MakeSoundTwice() + " here and a " + animal.MakeSoundTwice() + " there"); Console.WriteLine("Here a " + animal.MakeSoundOnce() + ", there a " + animal.MakeSoundOnce() + " everywhere a " + animal.MakeSoundTwice()); Console.WriteLine("Old Macdonald had a farm, ee ay ee ay oh"); Console.WriteLine(); } George friend = new George(); friend.Fly(); Console.WriteLine(friend.NameOfAnimal); Console.WriteLine(friend.MakeSoundOnce()); Console.WriteLine(friend.MakeSoundTwice()); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); int width = 25; Console.WriteLine(CreateRow("Employee", "Hours Worked", "Total Weekly Pay", width)); Console.WriteLine(); Console.WriteLine(CreateRow("Bob Mackey", "20", "200", width)); Console.WriteLine("{0, -20}{1, -20}{2, -20}", "Employee", "Hours Worked", "Total Weekly Pay"); Console.WriteLine(); Console.WriteLine("{0, -20}{1, -20}{2, -20}", "Bob Mackey", "20", "200"); Console.ReadKey(); }
/// <summary> /// Creates a new zoo. /// </summary> /// <returns> The created zoo.</returns> public static Zoo NewZoo() { Zoo zoo = new Zoo("Como Zoo", 1000, 4, 0.75m, 15.00m, 3640.25m, new Employee("Sam", 42), new Employee("Flora", 98), 3); // Add money to the animal snack machine. zoo.AnimalSnackMachine.AddMoney(42.75m); // Define an animal variable. Animal animal; // Create a new Dingo and add him to the list of animals. animal = new Dingo("Dolly", 4, 35.3); animal.MakePregnant(); zoo.AddAnimal(animal); // Create a new Dingo and add him to the list of animals. animal = new Dingo("Dixie", 3, 33.8); animal.MakePregnant(); zoo.AddAnimal(animal); // Create a new platypus and add him to the list of animals. animal = new Platypus("Patty", 2, 15.5); animal.MakePregnant(); zoo.AddAnimal(animal); // Create a new Hummingbird and add him to the list of animals. animal = new Hummingbird("Harold", 1, 0.5); zoo.AddAnimal(animal); // Create a new chimp and add him to the list of animals. animal = new Chimpanzee("Noah", 12, 500); zoo.AddAnimal(animal); // Create a new eagle and add him to the list of animals. animal = new Eagle("Tracy", 300, 10); zoo.AddAnimal(animal); // Create a new kangaroo and add him to the list of animals. animal = new Kangaroo("Jeff", 25, 30); zoo.AddAnimal(animal); // Create a new ostrich and add him to the list of animals. animal = new Ostrich("Jake", 40, 200); zoo.AddAnimal(animal); // Create a new shark and add him to the list of animals. animal = new Shark("Max", 23, 185); zoo.AddAnimal(animal); // Create a new squirrel and them to the list. animal = new Squirrel("Matt", 21, 200); zoo.AddAnimal(animal); // Create a guest. Guest guest = new Guest("Greg", 44, 150.35m, "Brown"); // Add the guest and sell the ticket to the guest. zoo.AddGuest(guest, zoo.SellTicket(guest)); // Create a guest. guest = new Guest("Darla", 11, 25.25m, "Salmon"); // Add the guest and sell the ticket to the guest. zoo.AddGuest(guest, zoo.SellTicket(guest)); return(zoo); }