aboutsummaryrefslogtreecommitdiffstats
path: root/test/inet_set.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/inet_set.lua')
-rw-r--r--test/inet_set.lua73
1 files changed, 73 insertions, 0 deletions
diff --git a/test/inet_set.lua b/test/inet_set.lua
new file mode 100644
index 0000000..044de09
--- /dev/null
+++ b/test/inet_set.lua
@@ -0,0 +1,73 @@
+local inet = require 'inet'
+local inet_set = require 'inet.set'
+local test = require 'test'
+local inspect = require 'inspect'
+
+function agg_set(a, b)
+ inet_set.aggregate(a)
+ assert(#a == #b, 'wrong set size')
+ for i=1,#a do
+ --print(a[i], b[i])
+ assert(a[i] == b[i], 'unexpected network')
+ end
+end
+
+
+return test.new(function()
+ local ip = inet('10.0.0.0/24')
+
+ agg_set({
+ inet('10.0.0.0/24'),
+ inet('10.0.1.0/24'),
+ }, {
+ inet('10.0.0.0/23'),
+ })
+
+ agg_set({
+ inet('10.0.1.0/24'),
+ inet('10.0.2.0/24'),
+ }, {
+ inet('10.0.1.0/24'),
+ inet('10.0.2.0/24'),
+ })
+
+ agg_set({
+ inet('10.0.1.0/24'),
+ inet('10.0.2.0/24'),
+ inet('10.0.3.0/24'),
+ inet('10.0.4.0/24'),
+ }, {
+ inet('10.0.1.0/24'),
+ inet('10.0.2.0/23'),
+ inet('10.0.4.0/24'),
+ })
+
+ agg_set({
+ inet('10.0.2.1/24'),
+ inet('10.0.4.0/24'),
+ inet('10.0.1.0/24'),
+ inet('10.0.3.0/24'),
+ }, {
+ inet('10.0.2.0/23'),
+ inet('10.0.4.0/24'),
+ inet('10.0.1.0/24'),
+ })
+
+ agg_set({
+ inet('10.0.1.1/24'),
+ inet('10.0.3.2/24'),
+ inet('10.0.2.3/24'),
+ inet('10.0.4.4/24'),
+ }, {
+ inet('10.0.1.0/24'),
+ inet('10.0.2.0/23'),
+ inet('10.0.4.0/24'),
+ })
+
+ agg_set({
+ inet('::/32'),
+ inet('0:1::/32'),
+ }, {
+ inet('::/31'),
+ })
+end)