package net.hivetechnology.o20010_06.vpn

import org.junit.Assert.assertEquals
import org.junit.Test

class RoutePlannerTest {
    @Test
    fun convertsContiguousMasks() {
        assertEquals(24, RoutePlanner.maskToPrefix("255.255.255.0"))
        assertEquals(20, RoutePlanner.maskToPrefix("255.255.240.0"))
        assertEquals(32, RoutePlanner.maskToPrefix("255.255.255.255"))
    }

    @Test
    fun rejectsNonContiguousMasks() {
        assertEquals(-1, RoutePlanner.maskToPrefix("255.0.255.0"))
    }

    @Test
    fun detectsOverlappingNetworksRegardlessOfPrefixSize() {
        assertEquals(true, RoutePlanner.networksOverlap("10.10.10.24", 24, "10.10.10.128", 25))
        assertEquals(true, RoutePlanner.networksOverlap("10.10.10.128", 25, "10.10.10.24", 24))
        assertEquals(false, RoutePlanner.networksOverlap("10.10.10.0", 24, "10.10.11.0", 24))
    }

    @Test
    fun rejectsHostnamesInsteadOfResolvingThemAsRoutes() {
        assertEquals(false, RoutePlanner.networksOverlap("runtime.invalid", 24, "10.10.10.0", 24))
    }
}
