Skip to content

Commit

Permalink
Verify result routes
Browse files Browse the repository at this point in the history
  • Loading branch information
aitorvs committed Mar 7, 2021
1 parent b8798df commit 917b8f5
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/main/kotlin/beeline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class BeelineCommand: CliktCommand(help = """

val routes = calculateSubnetRoutes(subnets)
val finalRoutes = mergeRoutes(subnets, routes)
// verifyRoutes(subnets, finalRoutes)
val gaps = if (showGaps) calculateGaps(finalRoutes) else listOf()

val beelines = finalRoutes.map { Beeline(it) }
Expand All @@ -65,16 +64,15 @@ class BeelineCommand: CliktCommand(help = """
val result = beelines.toMutableList().apply {
addAll(beelineGaps)
sortBy { it.route.info.lowAddress.normalizeAddress() }
}.toList()
}.toList().also { verifyRoutes(it) }

outputRoutes(result, format)
}

private fun verifyRoutes(subnets: List<Subnet>, routes: List<Subnet>) {
val subnetAddrCount = subnets.map { it.info.getAddressCountLong() }.sum()
val routeAddrCount = routes.map { it.info.getAddressCountLong() }.sum()
private fun verifyRoutes(routes: List<Beeline>) {
val routeAddrCount = routes.map { it.route.info.getAddressCountLong() }.sum()

assert((routeAddrCount + subnetAddrCount - UInt.MAX_VALUE.toLong() - 1) == 0L) { "Invalid routes" }
assert((routeAddrCount - UInt.MAX_VALUE.toLong() - 1) == 0L) { "Invalid routes" }
}


Expand Down

0 comments on commit 917b8f5

Please sign in to comment.