// Path: src/test/java/com/github/phantomthief/failover/impl/PriorityGroupManagerTest.java
// static int[] countOfEachGroup(int groupCount, PriorityGroupManager<?> manager) {
//     Map<?, Integer> map = manager.getPriorityMap();
//     int[] result = new int[groupCount];
//     for (Map.Entry<?, Integer> en : map.entrySet()) {
//         result[en.getValue()]++;
//     }
//     return result;
// }
// 
// Path: src/main/java/com/github/phantomthief/failover/impl/PriorityFailoverBuilder.java
// public static final class ResConfig implements Cloneable {
//     private final int priority;
//     private final double maxWeight;
//     private final double minWeight;
//     private final double initWeight;
// 
//     public ResConfig() {
//         this(DEFAULT_MAX_WEIGHT);
//     }
// 
//     public ResConfig(double maxWeight) {
//         this(maxWeight, DEFAULT_MIN_WEIGHT);
//     }
// 
//     public ResConfig(double maxWeight, double minWeight) {
//         this(maxWeight, minWeight, DEFAULT_PRIORITY);
//     }
// 
//     public ResConfig(double maxWeight, double minWeight, int priority) {
//         this(maxWeight, minWeight, priority, maxWeight);
//     }
// 
//     public ResConfig(double maxWeight, double minWeight, int priority, double initWeight) {
//         this.maxWeight = maxWeight;
//         this.minWeight = minWeight;
//         this.priority = priority;
//         this.initWeight = initWeight;
//     }
// 
//     @Override
//     public ResConfig clone() {
//         try {
//             return (ResConfig) super.clone();
//         } catch (CloneNotSupportedException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public int getPriority() {
//         return priority;
//     }
// 
//     public double getMaxWeight() {
//         return maxWeight;
//     }
// 
//     public double getMinWeight() {
//         return minWeight;
//     }
// 
//     public double getInitWeight() {
//         return initWeight;
//     }
// }
// 
// Path: src/main/java/com/github/phantomthief/failover/impl/PriorityFailoverManager.java
// public static class UpdateResult<T> {
//     private Map<T, ResConfig> addedResources = new HashMap<>();
//     private Map<T, ResConfig> removedResources = new HashMap<>();
//     private Map<T, ResConfig> updatedResources = new HashMap<>();
// 
//     /**
//      * 本次添加的资源，Map的value是新的配置。
//      * @return 更新的资源
//      */
//     public Map<T, ResConfig> getAddedResources() {
//         return addedResources;
//     }
// 
//     /**
//      * 删除的资源，Map的value是旧的配置。
//      * @return 更新的资源
//      */
//     public Map<T, ResConfig> getRemovedResources() {
//         return removedResources;
//     }
// 
//     /**
//      * 本次更新的资源，Map的value是新的配置。
//      * @return 更新的资源
//      */
//     public Map<T, ResConfig> getUpdatedResources() {
//         return updatedResources;
//     }
// 
// }


import static com.github.phantomthief.failover.impl.PriorityGroupManagerTest.countOfEachGroup;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.failover.impl.PriorityFailoverBuilder.ResConfig;
import com.github.phantomthief.failover.impl.PriorityFailoverManager.UpdateResult;

        manager.updateAll(singletonMap(o0, new ResConfig(100, 60, 0, 100)));
        assertEquals(60, manager.getFailover().getResourcesMap().get(o0).currentWeight);

        manager.updateAll(singletonMap(o0, new ResConfig(10, 0, 0, 100)));
        assertEquals(6, manager.getFailover().getResourcesMap().get(o0).currentWeight);

        manager.getFailover().success(manager.getFailover().getOneAvailable());

        manager.updateAll(singletonMap(o0, new ResConfig(100, 0, 0, 100)));
        assertEquals(100, manager.getFailover().getResourcesMap().get(o0).currentWeight);

        manager.updateAll(singletonMap(o0, new ResConfig(10, 0, 0, 100)));
        assertEquals(10, manager.getFailover().getResourcesMap().get(o0).currentWeight);
    }

    @Test
    public void testAutoPriority() {
        PriorityFailoverManager<Object> manager = PriorityFailover.newBuilder()
                .enableAutoPriority(1)
                .addResource(o0)
                .addResource(o1)
                .buildManager();
        int[] resCountOfGroup = countOfEachGroup(2, manager.getGroupManager());
        Assertions.assertEquals(1, resCountOfGroup[0]);
        Assertions.assertEquals(1, resCountOfGroup[1]);


        manager.update(singletonMap(o2, new ResConfig()), singleton(o0));

// Path: src/test/java/com/github/phantomthief/failover/impl/PriorityGroupManagerTest.java
// static int[] countOfEachGroup(int groupCount, PriorityGroupManager<?> manager) {
//     Map<?, Integer> map = manager.getPriorityMap();
//     int[] result = new int[groupCount];
//     for (Map.Entry<?, Integer> en : map.entrySet()) {
//         result[en.getValue()]++;
//     }
//     return result;
// }
// 
// Path: src/main/java/com/github/phantomthief/failover/impl/PriorityFailoverBuilder.java
// public static final class ResConfig implements Cloneable {
//     private final int priority;
//     private final double maxWeight;
//     private final double minWeight;
//     private final double initWeight;
// 
//     public ResConfig() {
//         this(DEFAULT_MAX_WEIGHT);
//     }
// 
//     public ResConfig(double maxWeight) {
//         this(maxWeight, DEFAULT_MIN_WEIGHT);
//     }
// 
//     public ResConfig(double maxWeight, double minWeight) {
//         this(maxWeight, minWeight, DEFAULT_PRIORITY);
//     }
// 
//     public ResConfig(double maxWeight, double minWeight, int priority) {
//         this(maxWeight, minWeight, priority, maxWeight);
//     }
// 
//     public ResConfig(double maxWeight, double minWeight, int priority, double initWeight) {
//         this.maxWeight = maxWeight;
//         this.minWeight = minWeight;
//         this.priority = priority;
//         this.initWeight = initWeight;
//     }
// 
//     @Override
//     public ResConfig clone() {
//         try {
//             return (ResConfig) super.clone();
//         } catch (CloneNotSupportedException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public int getPriority() {
//         return priority;
//     }
// 
//     public double getMaxWeight() {
//         return maxWeight;
//     }
// 
//     public double getMinWeight() {
//         return minWeight;
//     }
// 
//     public double getInitWeight() {
//         return initWeight;
//     }
// }
// 
// Path: src/main/java/com/github/phantomthief/failover/impl/PriorityFailoverManager.java
// public static class UpdateResult<T> {
//     private Map<T, ResConfig> addedResources = new HashMap<>();
//     private Map<T, ResConfig> removedResources = new HashMap<>();
//     private Map<T, ResConfig> updatedResources = new HashMap<>();
// 
//     /**
//      * 本次添加的资源，Map的value是新的配置。
//      * @return 更新的资源
//      */
//     public Map<T, ResConfig> getAddedResources() {
//         return addedResources;
//     }
// 
//     /**
//      * 删除的资源，Map的value是旧的配置。
//      * @return 更新的资源
//      */
//     public Map<T, ResConfig> getRemovedResources() {
//         return removedResources;
//     }
// 
//     /**
//      * 本次更新的资源，Map的value是新的配置。
//      * @return 更新的资源
//      */
//     public Map<T, ResConfig> getUpdatedResources() {
//         return updatedResources;
//     }
// 
// }


// Path: src/test/java/com/github/phantomthief/failover/impl/PriorityFailoverManagerTest.java
import static com.github.phantomthief.failover.impl.PriorityGroupManagerTest.countOfEachGroup;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.failover.impl.PriorityFailoverBuilder.ResConfig;
import com.github.phantomthief.failover.impl.PriorityFailoverManager.UpdateResult;


        manager.updateAll(singletonMap(o0, new ResConfig(100, 60, 0, 100)));
        assertEquals(60, manager.getFailover().getResourcesMap().get(o0).currentWeight);

        manager.updateAll(singletonMap(o0, new ResConfig(10, 0, 0, 100)));
        assertEquals(6, manager.getFailover().getResourcesMap().get(o0).currentWeight);

        manager.getFailover().success(manager.getFailover().getOneAvailable());

        manager.updateAll(singletonMap(o0, new ResConfig(100, 0, 0, 100)));
        assertEquals(100, manager.getFailover().getResourcesMap().get(o0).currentWeight);

        manager.updateAll(singletonMap(o0, new ResConfig(10, 0, 0, 100)));
        assertEquals(10, manager.getFailover().getResourcesMap().get(o0).currentWeight);
    }

    @Test
    public void testAutoPriority() {
        PriorityFailoverManager<Object> manager = PriorityFailover.newBuilder()
                .enableAutoPriority(1)
                .addResource(o0)
                .addResource(o1)
                .buildManager();
        int[] resCountOfGroup = countOfEachGroup(2, manager.getGroupManager());
        Assertions.assertEquals(1, resCountOfGroup[0]);
        Assertions.assertEquals(1, resCountOfGroup[1]);


        manager.update(singletonMap(o2, new ResConfig()), singleton(o0));

        resCountOfGroup = countOfEachGroup(2, manager.getGroupManager());