### Question:
IPLookup { Optional<String> lookup(InetAddress lookup) { Map.Entry<InetAddress, Record> entry = m.floorEntry(lookup); if (entry != null) { InetAddress end = entry.getValue().getEnd(); if (InetAddressComparator.INSTANCE.compare(end, lookup) >= 0) { return Optional.of(entry.getValue().getCountry()); } } return Optional.empty(); } IPLookup(Supplier<NavigableMap<InetAddress, Record>> s);   }### Answer:
@Test public void testSomeLookups() throws IOException { IPLookup ipArt = new IPLookup(() -> new AdaptiveRadixTree<>(InetAddressBinaryComparable.INSTANCE)); IPLookup ipRbt = new IPLookup(() -> new TreeMap<>(InetAddressComparator.INSTANCE)); InetAddress inetAddress = InetAddress.getByName("61.11.0.1"); Optional<String> country = ipArt.lookup(inetAddress); assertTrue(country.isPresent()); assertEquals(country.get(), "India"); assertEquals(country, ipRbt.lookup(inetAddress)); inetAddress = InetAddress.getByName("61.11.127.255"); country = ipArt.lookup(inetAddress); assertTrue(country.isPresent()); assertEquals(country.get(), "India"); assertEquals(country, ipRbt.lookup(inetAddress)); inetAddress = InetAddress.getByName("61.11.0.0"); country = ipArt.lookup(inetAddress); assertTrue(country.isPresent()); assertEquals(country.get(), "India"); assertEquals(country, ipRbt.lookup(inetAddress)); inetAddress = InetAddress.getByName("0.0.0.0"); country = ipArt.lookup(inetAddress); assertFalse(country.isPresent()); assertEquals(country, ipRbt.lookup(inetAddress)); }
@Test @Disabled("too many permuations to go over") public void testLookup() throws IOException { IPLookup ipArt = new IPLookup(() -> new AdaptiveRadixTree<>(InetAddressBinaryComparable.INSTANCE)); IPLookup ipRbt = new IPLookup(() -> new TreeMap<>(InetAddressComparator.INSTANCE)); for (int i = 0; i < 256; i++) { String iaddress = i + "."; for (int j = 0; j < 256; j++) { String jaddress = iaddress + j + "."; for (int k = 0; k < 256; k++) { String kaddress = jaddress + k + "."; for (int l = 0; l < 256; l++) { InetAddress inetAddress = InetAddress.getByName(kaddress + l); assertEquals(ipArt.lookup(inetAddress), ipRbt.lookup(inetAddress)); } } } } }