Added tests for suggesting numerical values instead of string values in suggestion builder

This commit is contained in:
Searge 2018-05-02 14:44:53 +02:00 committed by Nathan Adams
parent 5c50fa7691
commit 19c991b8b2

View file

@ -5,6 +5,10 @@ import com.mojang.brigadier.context.StringRange;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
@ -58,4 +62,25 @@ public class SuggestionsBuilderTest {
assertThat(other.getStart(), is(builder.getStart()));
assertThat(other.getRemaining(), equalTo(builder.getRemaining()));
}
@Test
public void sort_alphabetical() {
Suggestions result = builder.suggest("2").suggest("4").suggest("6").suggest("8").suggest("30").suggest("32").build();
List<String> actual = result.getList().stream().map(Suggestion::getText).collect(Collectors.toList());
assertThat(actual, equalTo(Lists.newArrayList( "2", "30", "32", "4", "6", "8")));
}
@Test
public void sort_numerical() {
Suggestions result = builder.suggest(2).suggest(4).suggest(6).suggest(8).suggest(30).suggest(32).build();
List<String> actual = result.getList().stream().map(Suggestion::getText).collect(Collectors.toList());
assertThat(actual, equalTo(Lists.newArrayList( "2", "4", "6", "8", "30", "32")));
}
@Test
public void sort_mixed() {
Suggestions result = builder.suggest("11").suggest("22").suggest("33").suggest("a").suggest("b").suggest("c").suggest(2).suggest(4).suggest(6).suggest(8).suggest(30).suggest(32).suggest("3a").suggest("a3").build();
List<String> actual = result.getList().stream().map(Suggestion::getText).collect(Collectors.toList());
assertThat(actual, equalTo(Lists.newArrayList( "11", "2", "22", "33", "3a", "4", "6", "8", "30", "32", "a", "a3", "b", "c")));
}
}