Code Monkey home page Code Monkey logo

beer-lover's Introduction

beer-lover

beer-lover application aims to solve programmer’s problem with a drinks.

Requirements

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

Installation and Getting Started

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));
    }
}

beer-lover's People

Contributors

volkodava avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.