diff --git a/src/main/java/br/masmangan/beecrowd/bee1014/FuelConsumption.java b/src/main/java/br/masmangan/beecrowd/bee1014/FuelConsumption.java new file mode 100644 index 0000000..bb2f27d --- /dev/null +++ b/src/main/java/br/masmangan/beecrowd/bee1014/FuelConsumption.java @@ -0,0 +1,18 @@ +package br.masmangan.beecrowd.bee1014; + +public class FuelConsumption { + private double fuel; + private double distance; + + public void setFuel(double fuel){ + this.fuel = fuel; + } + + public void setDistance(double distance){ + this.distance = distance; + } + + public double getConsumption() { + return this.distance/this.fuel; + } +} diff --git a/src/main/java/br/masmangan/beecrowd/bee1014/Main.java b/src/main/java/br/masmangan/beecrowd/bee1014/Main.java new file mode 100644 index 0000000..10f844a --- /dev/null +++ b/src/main/java/br/masmangan/beecrowd/bee1014/Main.java @@ -0,0 +1,18 @@ +import java.util.Scanner; + + +public class Main { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + double x = sc.nextDouble(); + double y = sc.nextDouble(); + FuelConsumption fuelConsumption = new FuelConsumption(); + fuelConsumption.setDistance(x); + fuelConsumption.setFuel(y); + double k = fuelConsumption.getConsumption(); + System.out.println(String.format("%.3f km/l", k)); + + } + +} \ No newline at end of file diff --git a/src/test/java/br/masmangan/beecrowd/bee1014/Bee1014steps.java b/src/test/java/br/masmangan/beecrowd/bee1014/Bee1014steps.java new file mode 100644 index 0000000..50d7d91 --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1014/Bee1014steps.java @@ -0,0 +1,52 @@ +package br.masmangan.beecrowd.bee1014; + +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 Bee1014steps { + + 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/bee1014/FuelConsumptionSteps.java b/src/test/java/br/masmangan/beecrowd/bee1014/FuelConsumptionSteps.java new file mode 100644 index 0000000..2793d40 --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1014/FuelConsumptionSteps.java @@ -0,0 +1,31 @@ +package br.masmangan.beecrowd.bee1014; + +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 FuelConsumptionSteps { + + private final FuelConsumption product = new FuelConsumption(); + private double consumption; + + @Given("Distance is {double}") + public void first_number_is(double a) { + product.setDistance(a); + } + @Given("Fuel size is {double}") + public void second_number_is(double b) { + product.setFuel(b); + } + + @When("Consumption is calculated") + public void different_is_calculated() { + consumption = product.getConsumption(); + } + @Then("result should be {double}") + public void result_should_be(double expected) { + assertEquals(expected, consumption); + } +} diff --git a/src/test/java/br/masmangan/beecrowd/bee1014/RunCucumberTest.java b/src/test/java/br/masmangan/beecrowd/bee1014/RunCucumberTest.java new file mode 100644 index 0000000..a7ff255 --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1014/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.bee1014; + +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/bee1014/bee1014.feature b/src/test/resources/br/masmangan/beecrowd/bee1014/bee1014.feature new file mode 100644 index 0000000..21466ba --- /dev/null +++ b/src/test/resources/br/masmangan/beecrowd/bee1014/bee1014.feature @@ -0,0 +1,47 @@ +@system +Feature: Bee1014 CLI + +Narrative: + +In order to avoid run out of gas +As a begginer truck driver +I want to be told the consumption of my truck based on the kilometers it run nd the litters I filled it + +Scenario: Run program with input 500 and 35 (km,l) + +Given input is +""" +500 +35 +""" +When program runs +Then output should be +""" +X = 14.286 +""" + +Scenario: Run program with input 4554 and 464.4 (km,l) + +Given input is +""" +4554 +464.6 +""" +When program runs +Then output should be +""" +X = 9.802 +""" + +Scenario: Run program with input 500 and 45 (km,l) + +Given input is +""" +500 +45 +""" +When program runs +Then output should be +""" +X = 11.111 +""" \ No newline at end of file diff --git a/src/test/resources/br/masmangan/beecrowd/bee1014/consumption.feature b/src/test/resources/br/masmangan/beecrowd/bee1014/consumption.feature new file mode 100644 index 0000000..3f576c9 --- /dev/null +++ b/src/test/resources/br/masmangan/beecrowd/bee1014/consumption.feature @@ -0,0 +1,40 @@ +# +# 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. +@domain +Feature: Consumption + +Narrative: + +In order to know the consumption of a car +As a math novice +I want to be told the consumption based on fuel size and the distance reached + +Scenario Outline: calculate consumption based on fuel size and distance reached + +Given fuel size is +And distance is +When Consumption is calculated +Then result should be + +Examples: +| fuel | distance | consumption | +| 35 | 500 | 14.286 | +| 464.6 | 4554 | 9.802 | +| 45 | 500 | 11.111 | \ No newline at end of file