// Path: src/main/java/com/github/phantomthief/failover/impl/PriorityGroupManager.java
// static <T> HashMap<T, int[]> buildResMap(List<T> coreResources, List<T> restResources,
//         int[] coreGroupSizes) {
//     final int totalGroupCount = coreGroupSizes.length + 1;
//     HashMap<T, int[]> map = new HashMap<>();
//     int logicIndex = 0;
//     int priority = 0;
//     int groupIndex = 0;
//     for (T res : coreResources) {
//         while (groupIndex >= coreGroupSizes[priority]) {
//             priority++;
//             groupIndex = 0;
//         }
//         map.put(res, new int[] {priority, logicIndex});
//         groupIndex++;
//         logicIndex++;
//     }
//     for (T res : restResources) {
//         map.put(res, new int[] {totalGroupCount - 1, logicIndex});
//         logicIndex++;
//     }
//     return map;
// }


import static com.github.phantomthief.failover.impl.PriorityGroupManager.buildResMap;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static java.util.Collections.singleton;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
package com.github.phantomthief.failover.impl;




/**
 * @author huangli
 * Created on 2020-02-06
 */
class PriorityGroupManagerTest {

    @Test
    public void testBuildResMap() {
        List<String> cores = asList("0", "1", "2");
        List<String> rests = asList("3", "4", "5");

// Path: src/main/java/com/github/phantomthief/failover/impl/PriorityGroupManager.java
// static <T> HashMap<T, int[]> buildResMap(List<T> coreResources, List<T> restResources,
//         int[] coreGroupSizes) {
//     final int totalGroupCount = coreGroupSizes.length + 1;
//     HashMap<T, int[]> map = new HashMap<>();
//     int logicIndex = 0;
//     int priority = 0;
//     int groupIndex = 0;
//     for (T res : coreResources) {
//         while (groupIndex >= coreGroupSizes[priority]) {
//             priority++;
//             groupIndex = 0;
//         }
//         map.put(res, new int[] {priority, logicIndex});
//         groupIndex++;
//         logicIndex++;
//     }
//     for (T res : restResources) {
//         map.put(res, new int[] {totalGroupCount - 1, logicIndex});
//         logicIndex++;
//     }
//     return map;
// }


// Path: src/test/java/com/github/phantomthief/failover/impl/PriorityGroupManagerTest.java
import static com.github.phantomthief.failover.impl.PriorityGroupManager.buildResMap;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static java.util.Collections.singleton;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

package com.github.phantomthief.failover.impl;




/**
 * @author huangli
 * Created on 2020-02-06
 */
class PriorityGroupManagerTest {

    @Test
    public void testBuildResMap() {
        List<String> cores = asList("0", "1", "2");
        List<String> rests = asList("3", "4", "5");

        HashMap<String, int[]> map = buildResMap(cores, rests, new int[] {1, 2});