commit
584ed77aa3
|
@ -1,12 +1,25 @@
|
||||||
package com.ossez.list.random;
|
package com.ossez.list.random;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.junit.Test;
|
import com.ossez.list.RemoveFirstElementTest;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.TestInstance;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for Random remove item in listing
|
||||||
|
*
|
||||||
|
* <p><a href="https://www.ossez.com/t/java-list/13934">https://www.ossez.com/t/java-list/13934</a></p>
|
||||||
|
*
|
||||||
|
* @author YuCheng
|
||||||
|
*/
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
public class RandomListElementUnitTest {
|
public class RandomListElementUnitTest {
|
||||||
|
private final static Logger logger = LoggerFactory.getLogger(RemoveFirstElementTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenList_whenRandomIndexChosen_shouldReturnARandomElementUsingRandom() {
|
public void givenList_whenRandomIndexChosen_shouldReturnARandomElementUsingRandom() {
|
||||||
|
@ -20,6 +33,7 @@ public class RandomListElementUnitTest {
|
||||||
public void givenList_whenRandomIndexChosen_shouldReturnARandomElementUsingMathRandom() {
|
public void givenList_whenRandomIndexChosen_shouldReturnARandomElementUsingMathRandom() {
|
||||||
List<Integer> givenList = Lists.newArrayList(1, 2, 3);
|
List<Integer> givenList = Lists.newArrayList(1, 2, 3);
|
||||||
|
|
||||||
|
System.out.println(Math.random());
|
||||||
givenList.get((int) (Math.random() * givenList.size()));
|
givenList.get((int) (Math.random() * givenList.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +67,7 @@ public class RandomListElementUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenList_whenSeriesLengthChosen_shouldReturnRandomSeries() {
|
public void givenList_whenSeriesLengthChosen_shouldReturnRandomSeries() {
|
||||||
List<Integer> givenList = Lists.newArrayList(1, 2, 3, 4, 5, 6);
|
List<Integer> givenList = Lists.newArrayList(1, 2, 3, 4, 5, 6);
|
||||||
|
|
||||||
Collections.shuffle(givenList);
|
Collections.shuffle(givenList);
|
||||||
|
|
||||||
int randomSeriesLength = 3;
|
int randomSeriesLength = 3;
|
||||||
|
|
Loading…
Reference in New Issue