diff --git a/README.md b/README.md index f7d7fd8..0796b20 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Solved problem statements can be found at: * https://www.beecrowd.com.br/judge/en/problems/view/1005 * https://www.beecrowd.com.br/judge/en/problems/view/1006 * https://www.beecrowd.com.br/judge/en/problems/view/1007 +* https://www.beecrowd.com.br/judge/en/problems/view/1017 ## Solutions diff --git a/src/main/java/br/masmangan/beecrowd/bee1017/FuelCalculator.java b/src/main/java/br/masmangan/beecrowd/bee1017/FuelCalculator.java new file mode 100644 index 0000000..916128d --- /dev/null +++ b/src/main/java/br/masmangan/beecrowd/bee1017/FuelCalculator.java @@ -0,0 +1,24 @@ +package br.masmangan.beecrowd.bee1017; + +public class FuelCalculator { + private int a; + private int b; + private double consumption = 12.0; + + public void setA(int a) { + this.a = a; + } + + public void setB(int b) { + this.b = b; + } + + public double getConsumption(){ return consumption; } + + public double calculateFuelNeeded() { + double c = a; + double d = b; + + return (c * d) / consumption; + } +} diff --git a/src/main/java/br/masmangan/beecrowd/bee1017/Main.java b/src/main/java/br/masmangan/beecrowd/bee1017/Main.java new file mode 100644 index 0000000..6b3e645 --- /dev/null +++ b/src/main/java/br/masmangan/beecrowd/bee1017/Main.java @@ -0,0 +1,27 @@ +package br.masmangan.beecrowd.bee1017; + +import java.util.Scanner; + +import static java.lang.System.out; + +public class Main { + + private Main() { + + } + + public static void main(String[] args) { + FuelCalculator division; + Scanner in; + + division = new FuelCalculator(); + in = new Scanner(System.in); + + division.setA(in.nextInt()); + division.setB(in.nextInt()); + + in.close(); + + out.printf("FUEL = %.3f%n", division.calculateFuelNeeded()); + } +} \ No newline at end of file diff --git a/src/test/java/br/masmangan/beecrowd/bee1017/Bee1017Steps.java b/src/test/java/br/masmangan/beecrowd/bee1017/Bee1017Steps.java new file mode 100644 index 0000000..19a0d03 --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1017/Bee1017Steps.java @@ -0,0 +1,52 @@ +package br.masmangan.beecrowd.bee1017; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +import java.io.*; +import java.nio.charset.StandardCharsets; + +import static org.junit.Assert.assertEquals; + +public class Bee1017Steps { + + private String input; + private String actual; + + @Given("input is") + public void input_is(String input) { + this.input = input; + } + + @When("program runs") + public void program_runs() throws IOException { + InputStream inputStream = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)); + + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + + PrintStream outputStream = new PrintStream(byteArrayOutputStream); + + PrintStream previousOut = System.out; + InputStream previousIn = System.in; + + System.setIn(inputStream); + System.setOut(outputStream); + + Main.main(null); + + actual = byteArrayOutputStream.toString(); + + inputStream.close(); + outputStream.close(); + + System.setOut(previousOut); + System.setIn(previousIn); + } + + @Then("output should be") + public void output_should_be(String expected) { + assertEquals(expected, actual); + } + +} diff --git a/src/test/java/br/masmangan/beecrowd/bee1017/FuelCalculatorSteps.java b/src/test/java/br/masmangan/beecrowd/bee1017/FuelCalculatorSteps.java new file mode 100644 index 0000000..33a6271 --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1017/FuelCalculatorSteps.java @@ -0,0 +1,34 @@ +package br.masmangan.beecrowd.bee1017; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +import static org.junit.Assert.assertEquals; + +public class FuelCalculatorSteps { + private final FuelCalculator fuelCalculator = new FuelCalculator(); + private double actual; + + @Given("the spent time in the trip {int}") + public void the_spent_time_in_the_trip(int a) { + fuelCalculator.setA(a); + } + @Given("the average speed during the trip {int}") + public void the_average_speed_during_the_trip(int b) { + fuelCalculator.setB(b); + } + @Given("the car comsumption is {double}") + public void the_car_comsumption_is(double consumption) { + assertEquals(consumption, fuelCalculator.getConsumption(), 0.1); + } + @When("fuel needed is calculated") + public void fuel_needed_is_calculated() { + actual = fuelCalculator.calculateFuelNeeded(); + } + @Then("result should be {double}") + public void result_should_be(double expected) { + assertEquals(expected, actual, 0.001); + } + +} diff --git a/src/test/java/br/masmangan/beecrowd/bee1017/RunCucumberTest.java b/src/test/java/br/masmangan/beecrowd/bee1017/RunCucumberTest.java new file mode 100644 index 0000000..626fad3 --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1017/RunCucumberTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021, Gherkin By Example and/or its contributors. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This software is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this code. If not, see . + * + * Please visit Gherkin By Example at https://github.com/gherkin-by-example + * if you need additional information or have any questions. + */ +package br.masmangan.beecrowd.bee1017; + +import io.cucumber.junit.Cucumber; +import io.cucumber.junit.CucumberOptions; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions(plugin = {"pretty"}) +public class RunCucumberTest { + +} diff --git a/src/test/resources/br/masmangan/beecrowd/bee1017/FuelCalculator.feature b/src/test/resources/br/masmangan/beecrowd/bee1017/FuelCalculator.feature new file mode 100644 index 0000000..2063339 --- /dev/null +++ b/src/test/resources/br/masmangan/beecrowd/bee1017/FuelCalculator.feature @@ -0,0 +1,22 @@ +@domain +Feature: FuelCalculator + +Narrative: + + In order to avoid running out of fuel + As a driver + I want to be told the how much fuel I will need for a trip + +Scenario Outline: calculate the fuel needed for a trip + + Given the spent time in the trip + And the average speed during the trip + And the car comsumption is 12.0 + When fuel needed is calculated + Then result should be + +Examples: +| a | b | fuelNeeded | +| 10 | 85 | 70.833 | +| 2 | 92 | 15.333 | +| 22 | 67 | 122.833 | \ No newline at end of file diff --git a/src/test/resources/br/masmangan/beecrowd/bee1017/bee1017.feature b/src/test/resources/br/masmangan/beecrowd/bee1017/bee1017.feature new file mode 100644 index 0000000..b21d7f6 --- /dev/null +++ b/src/test/resources/br/masmangan/beecrowd/bee1017/bee1017.feature @@ -0,0 +1,50 @@ +@system +Feature: Bee1017 CLI + + Narrative: + + In order to avoid running out of fuel + As a driver + I want to be told the how much fuel I will need for a trip + + Scenario: Run program with input + + Given input is +""" +10 +85 +""" + When program runs + Then output should be +""" +FUEL = 70.833 + +""" + + Scenario: Run program with input + + Given input is +""" +2 +92 +""" + When program runs + Then output should be +""" +FUEL = 15.333 + +""" + + Scenario: Run program with input + + Given input is +""" +22 +67 +""" + When program runs + Then output should be +""" +FUEL = 122.833 + +""" \ No newline at end of file