import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void basicTest() { assertEquals(10, Solution.lastPoint(52, 5, new int[] { 2, 5, 10, 15 } )); assertEquals(45, Solution.lastPoint(250, 5, new int[] { 10, 15, 30, 45 } )); assertEquals(-1, Solution.lastPoint(50, 25, new int[] { 10, 20, 30, 40, 50 } )); } @Test void moreBasicTest() { assertEquals(16, Solution.lastPoint(100, 2, new int[] { 4, 8, 12, 16 } )); assertEquals(20, Solution.lastPoint(130, 4, new int[] { 5, 15, 20, 50 } )); assertEquals(-1, Solution.lastPoint(200, 10, new int[] { 80, 85, 100} )); } @Test void rareTest() { assertEquals(-1, Solution.lastPoint(0, 2, new int[] { 40, 80, 120, 160 } )); assertEquals(160, Solution.lastPoint(100, 0, new int[] { 40, 80, 120, 160 } )); assertEquals(0, Solution.lastPoint(200, 5, new int[] { 0, 0, 0, 0 } )); assertEquals(5, Solution.lastPoint(200, 5, new int[] { 0, 0, 0, 5 } )); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void basicTest() {
- assertEquals(10, Solution.lastPoint(52, 5, new int[] { 2, 5, 10, 15 } ));
- assertEquals(45, Solution.lastPoint(250, 5, new int[] { 10, 15, 30, 45 } ));
- assertEquals(-1, Solution.lastPoint(50, 25, new int[] { 10, 20, 30, 40, 50 } ));
- }
- @Test
- void moreBasicTest() {
- assertEquals(16, Solution.lastPoint(100, 2, new int[] { 4, 8, 12, 16 } ));
- assertEquals(20, Solution.lastPoint(130, 4, new int[] { 5, 15, 20, 50 } ));
- assertEquals(-1, Solution.lastPoint(200, 10, new int[] { 80, 85, 100} ));
- }
@Test- @Test
- void rareTest() {
- assertEquals(-1, Solution.lastPoint(0, 2, new int[] { 40, 80, 120, 160 } ));
- assertEquals(160, Solution.lastPoint(100, 0, new int[] { 40, 80, 120, 160 } ));
- assertEquals(0, Solution.lastPoint(200, 5, new int[] { 0, 0, 0, 0 } ));
- assertEquals(5, Solution.lastPoint(200, 5, new int[] { 0, 0, 0, 5 } ));
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void basicTest() { assertEquals(10, Solution.lastPoint(52, 5, new int[] { 2, 5, 10, 15 } )); assertEquals(45, Solution.lastPoint(250, 5, new int[] { 10, 15, 30, 45 } )); assertEquals(-1, Solution.lastPoint(50, 25, new int[] { 10, 20, 30, 40, 50 } )); } @Test void moreBasicTest() { assertEquals(16, Solution.lastPoint(100, 2, new int[] { 4, 8, 12, 16 } )); assertEquals(20, Solution.lastPoint(130, 4, new int[] { 5, 15, 20, 50 } )); assertEquals(-1, Solution.lastPoint(200, 10, new int[] { 80, 85, 100} )); } @Test void rareTest() { assertEquals(-1, Solution.lastPoint(0, 2, new int[] { 40, 80, 120, 160 } )); assertEquals(160, Solution.lastPoint(100, 0, new int[] { 40, 80, 120, 160 } )); assertEquals(0, Solution.lastPoint(200, 5, new int[] { 0, 0, 0, 0 } )); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void basicTest() {
- assertEquals(10, Solution.lastPoint(52, 5, new int[] { 2, 5, 10, 15 } ));
- assertEquals(45, Solution.lastPoint(250, 5, new int[] { 10, 15, 30, 45 } ));
- assertEquals(-1, Solution.lastPoint(50, 25, new int[] { 10, 20, 30, 40, 50 } ));
- }
- @Test
- void moreBasicTest() {
- assertEquals(16, Solution.lastPoint(100, 2, new int[] { 4, 8, 12, 16 } ));
- assertEquals(20, Solution.lastPoint(130, 4, new int[] { 5, 15, 20, 50 } ));
- assertEquals(-1, Solution.lastPoint(200, 10, new int[] { 80, 85, 100} ));
- }
- @Test
- void rareTest() {
- assertEquals(-1, Solution.lastPoint(0, 2, new int[] { 40, 80, 120, 160 } ));
- assertEquals(160, Solution.lastPoint(100, 0, new int[] { 40, 80, 120, 160 } ));
assertEquals(160, Solution.lastPoint(100, 0, new int[] { 40, 80, 120, 160 } ));- assertEquals(0, Solution.lastPoint(200, 5, new int[] { 0, 0, 0, 0 } ));
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void basicTest() { assertEquals(10, Solution.lastPoint(52, 5, new int[] { 2, 5, 10, 15 } )); assertEquals(45, Solution.lastPoint(250, 5, new int[] { 10, 15, 30, 45 } )); assertEquals(-1, Solution.lastPoint(50, 25, new int[] { 10, 20, 30, 40, 50 } )); } @Test void moreBasicTest() { assertEquals(16, Solution.lastPoint(100, 2, new int[] { 4, 8, 12, 16 } )); assertEquals(20, Solution.lastPoint(130, 4, new int[] { 5, 15, 20, 50 } )); assertEquals(-1, Solution.lastPoint(200, 10, new int[] { 80, 85, 100} )); } @Test void rareTest() { assertEquals(-1, Solution.lastPoint(0, 2, new int[] { 40, 80, 120, 160 } )); assertEquals(160, Solution.lastPoint(100, 0, new int[] { 40, 80, 120, 160 } )); assertEquals(160, Solution.lastPoint(100, 0, new int[] { 40, 80, 120, 160 } )); assertEquals(0, Solution.lastPoint(200, 5, new int[] { 0, 0, 0, 0 } )); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void basicTest() {
- assertEquals(10, Solution.lastPoint(52, 5, new int[] { 2, 5, 10, 15 } ));
- assertEquals(45, Solution.lastPoint(250, 5, new int[] { 10, 15, 30, 45 } ));
- assertEquals(-1, Solution.lastPoint(50, 25, new int[] { 10, 20, 30, 40, 50 } ));
- }
- @Test
- void moreBasicTest() {
- assertEquals(16, Solution.lastPoint(100, 2, new int[] { 4, 8, 12, 16 } ));
- assertEquals(20, Solution.lastPoint(130, 4, new int[] { 5, 15, 20, 50 } ));
- assertEquals(-1, Solution.lastPoint(200, 10, new int[] { 80, 85, 100} ));
- }
- @Test
- void rareTest() {
- assertEquals(-1, Solution.lastPoint(0, 2, new int[] { 40, 80, 120, 160 } ));
- assertEquals(160, Solution.lastPoint(100, 0, new int[] { 40, 80, 120, 160 } ));
- assertEquals(160, Solution.lastPoint(100, 0, new int[] { 40, 80, 120, 160 } ));
- assertEquals(0, Solution.lastPoint(200, 5, new int[] { 0, 0, 0, 0 } ));
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void basicTest() { assertEquals(10, Solution.lastPoint(52, 5, new int[] { 2, 5, 10, 15 } )); assertEquals(45, Solution.lastPoint(250, 5, new int[] { 10, 15, 30, 45 } )); assertEquals(-1, Solution.lastPoint(50, 25, new int[] { 10, 20, 30, 40, 50 } )); } @Test void moreBasicTest() { assertEquals(16, Solution.lastPoint(100, 2, new int[] { 4, 8, 12, 16 } )); assertEquals(20, Solution.lastPoint(130, 4, new int[] { 5, 15, 20, 50 } )); assertEquals(-1, Solution.lastPoint(200, 10, new int[] { 80, 85, 100} )); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
- void basicTest() {
- assertEquals(10, Solution.lastPoint(52, 5, new int[] { 2, 5, 10, 15 } ));
- assertEquals(45, Solution.lastPoint(250, 5, new int[] { 10, 15, 30, 45 } ));
- assertEquals(-1, Solution.lastPoint(50, 25, new int[] { 10, 20, 30, 40, 50 } ));
- }
- @Test
- void moreBasicTest() {
- assertEquals(16, Solution.lastPoint(100, 2, new int[] { 4, 8, 12, 16 } ));
- assertEquals(20, Solution.lastPoint(130, 4, new int[] { 5, 15, 20, 50 } ));
- assertEquals(-1, Solution.lastPoint(200, 10, new int[] { 80, 85, 100} ));
- }
- }
We travel in a car with 'x' liters of fuel and a fuel consumption expressed in liters/kilometers (both paramaters are provided). In our trip we will pass through a series of gas stations at certain kilometric points (this route will be provided to us as array). The last gas station coincides with our destination.
Make a function that returns the kilometric point in which we must refuel in order not to run out of fuel.
Indications:
If the initial fuel is not enough to reach the first gas station it returns -1.
The values of the array will always be positive natural numbers in ascending order.
Note that the car will never go further than the last station.
class Solution{
public static int lastPoint (int fuel, int consumption, int[]stations){
//DO YOUR MAGIC!!
return -1;
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// TODO: Replace examples and use TDD by writing your own tests
class SolutionTest {
@Test
void testSomething() {
// assertEquals("expected", "actual");
}
}