@Test public void shouldNotFindBiggestAndSmallestPrefixWhenDoesNotExist() { Ipv6Range range = Ipv6Range.from("::").to(BigInteger.valueOf(2).pow(128).subtract(BigInteger.valueOf(2))); assertFalse(findMinimumPrefixForPrefixLength(range, 0).isPresent()); assertFalse(findMaximumPrefixForPrefixLength(range, 0).isPresent()); }
@Test public void shouldFindBiggestAndSmallestPrefixWhenRangeIsNotValidPrefix() { Ipv6Range range = Ipv6Range.from("::1").to("::4"); assertEquals(Ipv6Range.parse("::2/127"), findMaximumPrefixForPrefixLength(range, 127).get()); assertEquals(Ipv6Range.parse("::2/127"), findMinimumPrefixForPrefixLength(range, 127).get()); assertEquals(Ipv6Range.parse("::2/127"), findMaximumPrefixForPrefixLength(range, 128).get()); assertEquals(Ipv6Range.parse("::1/128"), findMinimumPrefixForPrefixLength(range, 128).get()); Ipv6Range otherRange = Ipv6Range.from("::").to(BigInteger.valueOf(2).pow(128).subtract(BigInteger.valueOf(2))); assertEquals(Ipv6Range.parse("::/1"), findMaximumPrefixForPrefixLength(otherRange, 1).get()); assertEquals(Ipv6Range.parse("::/1"), findMinimumPrefixForPrefixLength(otherRange, 1).get()); assertEquals(Ipv6Range.parse("::/1"), findMaximumPrefixForPrefixLength(otherRange, 2).get()); assertEquals( Ipv6Range.parse("8000::/2"), findMinimumPrefixForPrefixLength(otherRange, 2).get()); assertEquals(Ipv6Range.parse("::/1"), findMaximumPrefixForPrefixLength(otherRange, 128).get()); assertEquals( Ipv6Range.parse("ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe/128"), findMinimumPrefixForPrefixLength(otherRange, 128).get()); }