<commit_before>/**
 * Copyright (c) 2021, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.powsybl.iidm.network.tck.util;

import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import org.junit.After;
import org.junit.Test;

import java.util.*;

import static org.junit.Assert.*;

/**
 * @author <NAME> <geoffroy.jamgotchian at rte-france.com>
 */
public abstract class AbstractRemoveDanglingSwitchesTopologyTest {

    private final Set<String> removedObjects = new HashSet<>();

    @After
    public void tearDown() {
        removedObjects.clear();
    }

    private void addListener(Network network) {
        network.addListener(new DefaultNetworkListener() {
            @Override
            public void afterRemoval(String id) {
                removedObjects.add(id);
            }
        });
    }

    @Test
    public void testRemove() {
        Network network = FourSubstationsNodeBreakerFactory.create();
        addListener(network);
        Load ld1 = network.getLoad("LD1");
        ld1.remove();
        assertEquals(Set.of("LD1"), removedObjects);
    }

    @Test
    public void testRemoveAndClean() {
        Network network = FourSubstationsNodeBreakerFactory.create();
        addListener(network);
        Load ld1 = network.getLoad("LD1");
        ld1.remove(true);
        assertEquals(Set.of("S1VL1_LD1_BREAKER", "S1VL1_BBS_LD1_DISCONNECTOR", "LD1"), removedObjects);
    }

    /**
     *   G(2)    L(1)
     *   |       |
     *   B1      B2
     *   |       |
     *   ----3----
     *       |
     *       D
     *       |<commit_msg>Fix sketched diagram in unit test (#1952)<commit_after>/**
 * Copyright (c) 2021, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.powsybl.iidm.network.tck.util;

import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import org.junit.After;
import org.junit.Test;

import java.util.*;

import static org.junit.Assert.*;

/**
 * @author <NAME> <geoffroy.jamgotchian at rte-france.com>
 */
public abstract class AbstractRemoveDanglingSwitchesTopologyTest {

    private final Set<String> removedObjects = new HashSet<>();

    @After
    public void tearDown() {
        removedObjects.clear();
    }

    private void addListener(Network network) {
        network.addListener(new DefaultNetworkListener() {
            @Override
            public void afterRemoval(String id) {
                removedObjects.add(id);
            }
        });
    }

    @Test
    public void testRemove() {
        Network network = FourSubstationsNodeBreakerFactory.create();
        addListener(network);
        Load ld1 = network.getLoad("LD1");
        ld1.remove();
        assertEquals(Set.of("LD1"), removedObjects);
    }

    @Test
    public void testRemoveAndClean() {
        Network network = FourSubstationsNodeBreakerFactory.create();
        addListener(network);
        Load ld1 = network.getLoad("LD1");
        ld1.remove(true);
        assertEquals(Set.of("S1VL1_LD1_BREAKER", "S1VL1_BBS_LD1_DISCONNECTOR", "LD1"), removedObjects);
    }

    /**
     *   L(1)   G(2)
     *   |       |
     *   B1      B2
     *   |       |
     *   ----3----
     *       |
     *       D
     *       |
{'fraction_non_alphanumeric': 0.12272108843537415, 'fraction_numerical': 0.01578231292517007, 'mean_word_length': 2.3724770642201833, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4050577', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1143, 'n_words': 252}