diff --git a/src/main/java/br/masmangan/beecrowd/bee1011/Main.java b/src/main/java/br/masmangan/beecrowd/bee1011/Main.java new file mode 100644 index 0000000..5ef67b1 --- /dev/null +++ b/src/main/java/br/masmangan/beecrowd/bee1011/Main.java @@ -0,0 +1,33 @@ +package br.masmangan.beecrowd.bee1011; + + +import java.text.DecimalFormat; +import java.util.Scanner; + +import static java.lang.System.out; + +class Main { + + + private Main() { + + } + + + public static void main(String[] args) { + + final DecimalFormat df = new DecimalFormat("0.000"); + Scanner scanner = new Scanner(System.in); + + double value = scanner.nextDouble(); + + Sphere sphere = new Sphere(); + sphere.setRadius(value); + + double result = sphere.calculate(); + + out.println("VOLUME = " + df.format(result)); + + } + +} \ No newline at end of file diff --git a/src/main/java/br/masmangan/beecrowd/bee1011/Sphere.java b/src/main/java/br/masmangan/beecrowd/bee1011/Sphere.java new file mode 100644 index 0000000..f9bcb66 --- /dev/null +++ b/src/main/java/br/masmangan/beecrowd/bee1011/Sphere.java @@ -0,0 +1,26 @@ +package br.masmangan.beecrowd.bee1011; + +import java.text.DecimalFormat; + +public class Sphere { + + static double pi = 3.14159; + + private double radius; + private double volume; + private static final DecimalFormat df = new DecimalFormat("0.000"); + + public Sphere() { + } + + public void setRadius(double radius) { + this.radius = radius; + } + + public double calculate() { + + double result = (4/3.0)*pi*Math.pow(radius, 3); + this.volume = result; + return Double.parseDouble(df.format(result)); + } +} diff --git a/src/test/java/br/masmangan/beecrowd/bee1011/Bee1011Steps.java b/src/test/java/br/masmangan/beecrowd/bee1011/Bee1011Steps.java new file mode 100644 index 0000000..418a100 --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1011/Bee1011Steps.java @@ -0,0 +1,52 @@ +package br.masmangan.beecrowd.bee1011; + +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 Bee1011Steps { + + 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/bee1011/RunCucumberTest.java b/src/test/java/br/masmangan/beecrowd/bee1011/RunCucumberTest.java new file mode 100644 index 0000000..d34e9fd --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1011/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.bee1011; + +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/java/br/masmangan/beecrowd/bee1011/SphereSteps.java b/src/test/java/br/masmangan/beecrowd/bee1011/SphereSteps.java new file mode 100644 index 0000000..8209478 --- /dev/null +++ b/src/test/java/br/masmangan/beecrowd/bee1011/SphereSteps.java @@ -0,0 +1,26 @@ +package br.masmangan.beecrowd.bee1011; + +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 SphereSteps { + + private final Sphere sphere = new Sphere(); + private Double actual; + + @Given("radius is {double}") + public void radius_value_is(Double a) { + sphere.setRadius(a); + } + @When("volume is calculated") + public void volume_is_calculated() { + actual = sphere.calculate(); + } + @Then("result should be {double}") + public void result_should_be(Double expected) { + assertEquals(expected, actual); + } +} diff --git a/src/test/resources/br/masmangan/beecrowd/bee1011/Sphere.feature b/src/test/resources/br/masmangan/beecrowd/bee1011/Sphere.feature new file mode 100644 index 0000000..6366d81 --- /dev/null +++ b/src/test/resources/br/masmangan/beecrowd/bee1011/Sphere.feature @@ -0,0 +1,39 @@ +# +# 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: Sphere + +Narrative: + +In order to know the volume of a sphere +As a math novice +I want to be told the volume of a sphere giving only it's radius + +Scenario Outline: calculate volume of radius + +Given radius is +When volume is calculated +Then result should be + +Examples: +| radius | volume | +| 3.0 | 113.097 | +| 15.0 | 14137.155 | +| 1523.0 | 14797486501.627 | diff --git a/src/test/resources/br/masmangan/beecrowd/bee1011/bee1011.feature b/src/test/resources/br/masmangan/beecrowd/bee1011/bee1011.feature new file mode 100644 index 0000000..64bd10b --- /dev/null +++ b/src/test/resources/br/masmangan/beecrowd/bee1011/bee1011.feature @@ -0,0 +1,63 @@ +# +# 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. +@system +Feature: Bee1011 CLI + + Narrative + + In order to know the volume of a sphere + As a math novice + I want to be told the volume of a sphere giving only it's radius + + Scenario: Input 3 + Given input is +""" +3 +""" + When program runs + Then output should be +""" +VOLUME = 113.097 + +""" + + Scenario: Input 15 + Given input is +""" +15 +""" + When program runs + Then output should be +""" +VOLUME = 14137.155 + +""" + + Scenario: Input 1523 + Given input is +""" +1523 +""" + When program runs + Then output should be +""" +VOLUME = 14797486501.627 + +"""