Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
josdem committed Apr 11, 2024
2 parents 9564c6f + f5827b9 commit 72b7e8c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions big-o/src/main/java/com/josdem/algorithms/LinearTimeRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.josdem.algorithms;

import java.util.List;

/* Type: Linear Time Algorithms – O(n)
Description: Linear increment amount of time based on collection size
*/

public class LinearTimeRunner {
public List<Integer> getEvenNumbers(List<Integer> numbers) {
return numbers.stream().filter(it -> it % 2 == 0).toList();
}
}
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.Arrays;
import java.util.List;

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

class LinearTimeRunnerTest {

private final LinearTimeRunner linearTimeRunner = new LinearTimeRunner();

@Test
@DisplayName("showing linear time algorithm")
void returnEvenNumbers() {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
assertEquals(Arrays.asList(2, 4, 6, 8, 0), linearTimeRunner.getEvenNumbers(numbers), "should get even numbers from the array");
}
}

0 comments on commit 72b7e8c

Please sign in to comment.