beer-lover application aims to solve programmer’s problem with a drinks.
A programmer drinks exactly goalPints of beer every evening. One evening, the programmer opens his fridge and sees a number of smallBottles of beer (1 pint each) and a number of bigBottles of beer (3 pints each). The programmer needs to decide whether he can pick some bottles and start drinking, or has to run to the store to buy some more bottles. The programmer is "greedy" and never consumes a bottle partially.
Write a Java-method which returns true if it is possible to make the goal by choosing from the given (whole) bottles, or false otherwise. Note that it is not necessary to "take" all bottles — some may remain unused.
Method stub:
public boolean gotBeer(int goalPints, int smallBottles, int bigBottles) {
// TODO: implement me
}
Examples:
gotBeer(6, 3, 1) must return true
gotBeer(7, 3, 1) must return false
gotBeer(6, 3, 2) must return true
gotBeer(3, 0, 1) must return true
gotBeer(1, 0, 1) must return false
To be able to start the tests of beer-lover you should have installed next applications:
Here is a quick teaser of a complete beer-lover unit test:
package com.smartling;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import org.junit.Test;
public class ProgrammerTest {
@Test
public void gotBeerAcceptanceTest() {
// create a programmer
Programmer programmer = new Programmer();
boolean gotBeer;
// must return true
gotBeer = programmer.gotBeer(6, 3, 1);
assertThat(gotBeer, equalTo(true));
// must return false
gotBeer = programmer.gotBeer(7, 3, 1);
assertThat(gotBeer, equalTo(false));
// must return true
gotBeer = programmer.gotBeer(6, 3, 2);
assertThat(gotBeer, equalTo(true));
// must return true
gotBeer = programmer.gotBeer(3, 0, 1);
assertThat(gotBeer, equalTo(true));
// must return false
gotBeer = programmer.gotBeer(1, 0, 1);
assertThat(gotBeer, equalTo(false));
// must return true
gotBeer = programmer.gotBeer(0, 0, 1);
assertThat(gotBeer, equalTo(true));
}
}