Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dog class and its respective tests: DogTest #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/main/java/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class Dog implements Tradable, Domesticatable {

private int i1;
private String s1;

public Dog(String breed) {
this.s1 = breed;

if (breed.equals("Chihuahua")) {
this.i1 = 5;
} else if (breed.equals("Labrador")) {
this.i1 = 10;
} else if (breed.equals("Golden Retriever")) {
this.i1 = 15;
} else if (breed.equals("German Shepherd")) {
this.i1 = 20;
}
}

@Override
public String sound() {
return "Woof!";
}

@Override
public int getPrice() {
return this.i1;
}

public String getBreed() {
return this.s1;
}
}
4 changes: 3 additions & 1 deletion src/main/java/Trader.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ public static void main(String[] args) {
List<Tradable> all_items = Arrays.asList(
new Horse(),
new Horse(),
new Horse()
ashenafee marked this conversation as resolved.
Show resolved Hide resolved
new Horse(),
// TODO: Add Tradable objects here!
new Dog("Labrador"),
new Dog("German Shepherd")
);

/* Below, we've created two Traders. Their money, inventory, and
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/DogTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class DogTest {
Dog c;
Dog gs;

@Before
public void setUp() {
c = new Dog("Chihuahua");
gs = new Dog("German Shepherd");
}

@Test(timeout=50)
public void TestGetBreed() {
assertEquals("Chihuahua", c.getBreed());
assertEquals("German Shepherd", gs.getBreed());
}

@Test(timeout=50)
public void TestGetPrice() {
assertEquals(5, c.getPrice());
assertEquals(20, gs.getPrice());
}

@Test(timeout=50)
public void TestSound() {
assertEquals("Woof!", c.sound());
assertEquals("Woof!", gs.sound());
assertEquals(c.sound(), gs.sound());
}

}