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

Code builds, tests pass. #7

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
96 changes: 96 additions & 0 deletions src/main/java/com/techreturners/cats/Cat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,101 @@
package com.techreturners.cats;

import java.util.Random;

interface Cat {

boolean isAsleep();
void goToSleep();
void wakeUp();
String getSetting();
int getAverageHeight();
String eat();

}

abstract class GenericCat implements Cat {
private boolean isAsleep = false; // awake by default
private int averageHeight = 0; // in cm

String setting = "domestic";

protected void setAverageHeight(int height) {
averageHeight = height;
}

protected void setConditioning(String wildOrDomestic) {
setting = wildOrDomestic;
}

@Override
public boolean isAsleep() {
return isAsleep;
}

@Override
public void goToSleep() {
isAsleep = true;
}

@Override
public void wakeUp() {
isAsleep = false;
}

@Override
public String getSetting() {
return setting;
}

@Override
public int getAverageHeight() {
return averageHeight;
}

abstract public String eat();
}


class DomesticCat extends GenericCat {

Random random = new Random();

DomesticCat() {
super.setAverageHeight(23);
super.setConditioning("domestic");

}

public String eat() {

int x = random.nextInt(10);
if (x < 3)
return ("It will do I suppose");
// else
return ("Purrrrrrr");
}

}

class LionCat extends GenericCat {

LionCat() {
super.setAverageHeight(1100);
super.setConditioning("wild");
}
public String eat() {
return ("Roar!!!!");
}

}

class CheetahCat extends GenericCat {
CheetahCat() {
super.setAverageHeight(12);
super.setConditioning("wild");
}
public
String eat() {
return ("Zzzzzzz");
}
}
11 changes: 7 additions & 4 deletions src/test/java/com/techreturners/cats/CatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Arrays;

public class CatTest {

@Test
public void checkCatIsAwake() {
Cat domesticCat = new DomesticCat();
assertFalse("Cat should be awake by default", domesticCat.isAsleep());
assertFalse(domesticCat.isAsleep(), "Cat should be awake by default");
}

@Test
public void checkCatCanGoToSleep() {
Cat domesticCat = new DomesticCat();
domesticCat.goToSleep();
assertTrue("Cat should be snoozing", domesticCat.isAsleep());
assertTrue(domesticCat.isAsleep(), "Cat should be snoozing");
}

@Test
public void checkCatCanWakep() {
Cat domesticCat = new DomesticCat();
domesticCat.goToSleep();
domesticCat.wakeUp();
assertFalse("Cat should be awake now", domesticCat.isAsleep());
assertFalse(domesticCat.isAsleep(), "Cat should be awake now" );
}

@Test
Expand Down Expand Up @@ -60,6 +61,8 @@ public void feedTheCheetah() {
@Test
public void feedTheCat() {
Cat domesticCat = new DomesticCat();
assertEquals("Purrrrrrr", domesticCat.eat());

assertTrue(Arrays.asList("Purrrrrrr", "It will do I suppose").contains(domesticCat.eat()));

}
}