OrganismTester - Organism d= new Organism(0, 10,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import junit.framework.TestCase; /** * A JUnit test case class. * Every method starting iwht the word "test" will be called when running * the test with JUnit. */ public class OrganismTester extends TestCase { public void testOrganism(int lev) { Organism x= new Organism(0); assertEquals(0, x.getLevel()); assertEquals(0, x.getMercury()); assertEquals(null, x.getNickname()); assertEquals(true, x.isAlive()); assertEquals(0, x.getNumVictims()); } public void testGetters() { Organism a=new Organism(0, 0, null); assertEquals(0, a.getLevel()); assertEquals(0, a.getMercury()); assertEquals(null, a.getNickname()); assertEquals(true, a.isAlive()); assertEquals(null, a.wasEatenBy()); assertEquals(0, a.getNumVictims()); Organism b= new Organism(0, 0, "fish"); assertEquals(0, b.getLevel()); assertEquals(0, b.getMercury()); assertEquals("fish", b.getNickname()); Organism c= new Organism(0, 5, null); assertEquals(0, c.getLevel()); assertEquals(5, c.getMercury()); assertEquals(null, c.getNickname());
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Organism d= new Organism(0, 10, "fish"); assertEquals(0, d.getLevel()); assertEquals(10, d.getMercury()); assertEquals("fish", d.getNickname()); Organism e= new Organism(5, 20, "fish"); assertEquals(5, e.getLevel()); assertEquals(20, e.getMercury()); assertEquals("fish", e.getNickname()); } public void testSetters() { /**Set this Organism's nickname to nn. Precondition: nn is a String of length at least 1.*/ Organism f= new Organism(0, 0, null); f.setNickname("eel"); assertEquals("eel", f.getNickname()); /**Have this Organism eat victim. Precondition: victim is not null and is alive, and this Organism is alive and higher in the food chain than victim is.*/ Organism g= new Organism(0, 1, null);; assertEquals(false, f.isAlive()); assertEquals(1, g.getNumVictims()); assertEquals(1, g.getMercury()); assertEquals(g, f.wasEatenBy()); assertEquals(0, g.getLevel()); } }...
View Full Document

This note was uploaded on 11/23/2009 for the course CALS 2008 at Cornell University (Engineering School).

Page1 / 2

OrganismTester - Organism d= new Organism(0, 10,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online