feat: implemented aquiring characters of random order in CharacterConfig
This commit is contained in:
parent
e9640a9a8a
commit
29db6c018c
@ -4,8 +4,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.Tuple;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POJO describing the CharacterConfig as defined by the standard document.
|
* POJO describing the CharacterConfig as defined by the standard document.
|
||||||
@ -14,7 +17,7 @@ public class CharacterConfig {
|
|||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
@Valid
|
@Valid
|
||||||
@Size(min = 12, message = "has less than 12 characters")
|
@Size(min = 24, message = "has less than 24 characters")
|
||||||
public CharacterProperties[] characters;
|
public CharacterProperties[] characters;
|
||||||
|
|
||||||
@JsonIgnore private Map<String, CharacterProperties> propertyMap;
|
@JsonIgnore private Map<String, CharacterProperties> propertyMap;
|
||||||
@ -38,6 +41,18 @@ public class CharacterConfig {
|
|||||||
return unmodifiablePropertyMap;
|
return unmodifiablePropertyMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public Tuple<CharacterProperties[], CharacterProperties[]> getDisjointSetsOfPropertiesOfSize(int size) {
|
||||||
|
if ((size * 2) > characters.length) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
var characterList = Arrays.asList(this.characters);
|
||||||
|
Collections.shuffle(characterList);
|
||||||
|
return Tuple.of(characterList.subList(0, size).toArray(new CharacterProperties[0]),
|
||||||
|
characterList.subList(size, 2 * size).toArray(new CharacterProperties[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
@ -4,9 +4,12 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import net.jqwik.api.*;
|
import net.jqwik.api.*;
|
||||||
import net.jqwik.api.lifecycle.BeforeProperty;
|
import net.jqwik.api.lifecycle.BeforeProperty;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
|
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
|
||||||
import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties;
|
import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties;
|
||||||
|
import uulm.teamname.marvelous.gamelibrary.json.JSON;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
@ -260,6 +263,18 @@ class CharacterConfigJSONTest {
|
|||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void disjointSubsetGenerationWorks() {
|
||||||
|
var characterConfig = JSON.parseCharacterConfig(json);
|
||||||
|
System.out.println(characterConfig.get().characters.length);
|
||||||
|
var tuple = characterConfig.get().getDisjointSetsOfPropertiesOfSize(6);
|
||||||
|
assertThat(tuple.item1).doesNotHaveDuplicates().hasSize(6);
|
||||||
|
assertThat(tuple.item2).doesNotHaveDuplicates().hasSize(6);
|
||||||
|
assertThat(tuple.item1)
|
||||||
|
.doesNotContainAnyElementsOf(Arrays.asList(tuple.item2));
|
||||||
|
System.out.println(tuple);
|
||||||
|
}
|
||||||
|
|
||||||
ObjectMapper mapper;
|
ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeProperty
|
@BeforeProperty
|
||||||
|
Loading…
Reference in New Issue
Block a user