Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
josdem committed Apr 21, 2024
2 parents 05d88ce + f28d35e commit e45b874
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions big-o/src/main/java/com/josdem/algorithms/PlusTimeRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.josdem.algorithms;

import java.util.Arrays;
import java.util.List;

/* Type: Plus Time Algorithms – O(2a + b)
Description: Plus compute time algorithm
*/
public class PlusTimeRunner {

public List<Integer> createNewList(List<Integer> numbers) {
int min = numbers.stream().min(Integer::compare).orElseThrow(() -> new RuntimeException("No min value was found"));
int max = numbers.stream().max(Integer::compare).orElseThrow(() -> new RuntimeException("No max value was found"));
return Arrays.asList(new Integer[max - min + 1]);
}
}
22 changes: 22 additions & 0 deletions big-o/src/test/java/com/josdem/algorithms/PlusTimeRunnerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.josdem.algorithms;


import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

class PlusTimeRunnerTest {

private final PlusTimeRunner plusTimeRunner = new PlusTimeRunner();

@Test
@DisplayName("show plus time algorithm")
void shouldCreateCollectionWithFixedSize(){
List<Integer> numbers = List.of(3, 9, 15, 2, 11, 5, 19, 6, 4, 10);
int expectedSize = 18;
assertEquals(expectedSize, plusTimeRunner.createNewList(numbers).size(), "should have expected size");
}
}

0 comments on commit e45b874

Please sign in to comment.