Skip to content

Added a new example for Bee1017 #25

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

Open
wants to merge 2 commits into
base: main
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/br/masmangan/beecrowd/bee1017/FuelCalculator.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
27 changes: 27 additions & 0 deletions src/main/java/br/masmangan/beecrowd/bee1017/Main.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
52 changes: 52 additions & 0 deletions src/test/java/br/masmangan/beecrowd/bee1017/Bee1017Steps.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
31 changes: 31 additions & 0 deletions src/test/java/br/masmangan/beecrowd/bee1017/RunCucumberTest.java
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*
* 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 {

}
Original file line number Diff line number Diff line change
@@ -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 <a>
And the average speed during the trip <b>
And the car comsumption is 12.0
When fuel needed is calculated
Then result should be <fuelNeeded>

Examples:
| a | b | fuelNeeded |
| 10 | 85 | 70.833 |
| 2 | 92 | 15.333 |
| 22 | 67 | 122.833 |
50 changes: 50 additions & 0 deletions src/test/resources/br/masmangan/beecrowd/bee1017/bee1017.feature
Original file line number Diff line number Diff line change
@@ -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

"""