package ru.kirillius.pf.sdn.core.Util;

import org.junit.jupiter.api.Test;
import ru.kirillius.pf.sdn.core.Networking.IPv4Subnet;

import java.util.ArrayList;

import static org.assertj.core.api.Assertions.assertThat;

class IPv4UtilTest {

    @Test
    void summarySubnets() {
        var subnets = new ArrayList<IPv4Subnet>();


        for (var i = 0; i <= 254; i++) {
            subnets.add(new IPv4Subnet("192.168." + i + ".0", 24));
        }
        subnets.remove(0);
        for (var i = 1; i <= 255; i++) {
            subnets.add(new IPv4Subnet("192.168.255." + i, 32));
        }

        for (var i = 0; i <= 254/3; i++) {
            subnets.add(new IPv4Subnet("192.169." + i + ".0", 24));
        }

        subnets.add(new IPv4Subnet("1.1.1.1/32"));
        subnets.add(new IPv4Subnet("200.1.1.1/32"));



        //subnets.forEach(System.out::println);

        var merged = IPv4Util.summarySubnets(subnets, 51).getResult();

        merged.forEach(System.out::println);

        assertThat(merged).isNotNull();
    }

    @Test
    void summarySubnetsShishanyaCase() {
        var subnets = new ArrayList<IPv4Subnet>();





        subnets.add(new IPv4Subnet("8.6.112.0/32"));
        subnets.add(new IPv4Subnet("8.6.112.0/24"));


        //subnets.forEach(System.out::println);

        var merged = IPv4Util.summarySubnets(subnets, 51).getResult();

        merged.forEach(System.out::println);

        assertThat(merged).isNotNull();
    }
}