# Path: capirca/lib/nacaddr.py
# def IP(ip, comment='', token='', strict=True):
# def _is_subnet_of(a, b):  # pylint: disable=invalid-name
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def AddComment(self, comment=''):
#   def supernet(self, prefixlen_diff=1):
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def supernet(self, prefixlen_diff=1):
#   def AddComment(self, comment=''):
# def _InNetList(adders, ip):
# def IsSuperNet(supernets, subnets):
# def CollapseAddrListPreserveTokens(addresses):
# def _SafeToMerge(address, merge_target, check_addresses):
# def _CollapseAddrListInternal(addresses, complements_by_network):
# def CollapseAddrList(addresses, complement_addresses=None):
# def SortAddrList(addresses):
# def RemoveAddressFromList(superset, exclude):
# def AddressListExclude(superset, excludes, collapse_addrs=True):
# class IPv4(ipaddress.IPv4Network):
# class IPv6(ipaddress.IPv6Network):
# class PrefixlenDiffInvalidError(ipaddress.NetmaskValueError):


from absl.testing import absltest
from capirca.lib import nacaddr
    # above but i think it's a little more readable
    expected_two = list(a1.address_exclude(b1))
    expected_two.extend(a2.address_exclude(b2))
    self.assertListEqual(nacaddr.AddressListExclude([a1, a2], [b1, b2, b3]),
                         sorted(expected_two))

  def testComplexAddressListExcludesion(self):
    # this is a big fugly test. there was a bug in AddressListExclude
    # which manifested itself when more than one member of the excludes
    # list was a part of the same superset token.
    #
    # for example, it used to be like so:
    #  excludes = ['1.1.1.1/32', '1.1.1.2/32']
    #  superset = ['1.1.1.0/30']
    #
    # '1.1.1.0/30'.AddressExclude('1.1.1.1/32') ->
    #    ['1.1.1.0/32', '1.1.1.2/32', '1.1.1.3/32']
    # '1.1.1.0/30'.AddressExclude('1.1.1.2/32') ->
    #    ['1.1.1.0/32', '1.1.1.1/32', '1.1.1.3/32']
    #
    # yet combining those two results gives you
    #   ['1.1.1.0/32', '1.1.1.1/32', '1.1.1.2/32' '1.1.1.3/32'], or
    #   '1.1.1.0/30', which clearly isn't right.

    excludes = [nacaddr.IPv4('10.0.0.0/23'), nacaddr.IPv4('10.1.0.0/16')]
    superset = [nacaddr.IPv4('0.0.0.0/0')]

    expected = [nacaddr.IPv4('0.0.0.0/5'), nacaddr.IPv4('8.0.0.0/7'),
                nacaddr.IPv4('10.0.2.0/23'), nacaddr.IPv4('10.0.4.0/22'),
                nacaddr.IPv4('10.0.8.0/21'), nacaddr.IPv4('10.0.16.0/20'),

# Path: capirca/lib/nacaddr.py
# def IP(ip, comment='', token='', strict=True):
# def _is_subnet_of(a, b):  # pylint: disable=invalid-name
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def AddComment(self, comment=''):
#   def supernet(self, prefixlen_diff=1):
#   def __init__(self, ip_string, comment='', token='', strict=True):
#   def subnet_of(self, other):
#   def supernet_of(self, other):
#   def __deepcopy__(self, memo):
#   def supernet(self, prefixlen_diff=1):
#   def AddComment(self, comment=''):
# def _InNetList(adders, ip):
# def IsSuperNet(supernets, subnets):
# def CollapseAddrListPreserveTokens(addresses):
# def _SafeToMerge(address, merge_target, check_addresses):
# def _CollapseAddrListInternal(addresses, complements_by_network):
# def CollapseAddrList(addresses, complement_addresses=None):
# def SortAddrList(addresses):
# def RemoveAddressFromList(superset, exclude):
# def AddressListExclude(superset, excludes, collapse_addrs=True):
# class IPv4(ipaddress.IPv4Network):
# class IPv6(ipaddress.IPv6Network):
# class PrefixlenDiffInvalidError(ipaddress.NetmaskValueError):


# Path: tests/lib/nacaddr_test.py
from absl.testing import absltest
from capirca.lib import nacaddr

    # above but i think it's a little more readable
    expected_two = list(a1.address_exclude(b1))
    expected_two.extend(a2.address_exclude(b2))
    self.assertListEqual(nacaddr.AddressListExclude([a1, a2], [b1, b2, b3]),
                         sorted(expected_two))

  def testComplexAddressListExcludesion(self):
    # this is a big fugly test. there was a bug in AddressListExclude
    # which manifested itself when more than one member of the excludes
    # list was a part of the same superset token.
    #
    # for example, it used to be like so:
    #  excludes = ['1.1.1.1/32', '1.1.1.2/32']
    #  superset = ['1.1.1.0/30']
    #
    # '1.1.1.0/30'.AddressExclude('1.1.1.1/32') ->
    #    ['1.1.1.0/32', '1.1.1.2/32', '1.1.1.3/32']
    # '1.1.1.0/30'.AddressExclude('1.1.1.2/32') ->
    #    ['1.1.1.0/32', '1.1.1.1/32', '1.1.1.3/32']
    #
    # yet combining those two results gives you
    #   ['1.1.1.0/32', '1.1.1.1/32', '1.1.1.2/32' '1.1.1.3/32'], or
    #   '1.1.1.0/30', which clearly isn't right.

    excludes = [nacaddr.IPv4('10.0.0.0/23'), nacaddr.IPv4('10.1.0.0/16')]
    superset = [nacaddr.IPv4('0.0.0.0/0')]

    expected = [nacaddr.IPv4('0.0.0.0/5'), nacaddr.IPv4('8.0.0.0/7'),
                nacaddr.IPv4('10.0.2.0/23'), nacaddr.IPv4('10.0.4.0/22'),
                nacaddr.IPv4('10.0.8.0/21'), nacaddr.IPv4('10.0.16.0/20'),

                nacaddr.IPv4('10.0.32.0/19'), nacaddr.IPv4('10.0.64.0/18'),