aboutsummaryrefslogtreecommitdiffstats
path: root/test/inet_set.lua
diff options
context:
space:
mode:
authorAsbjørn Sloth Tønnesen <ast@fiberby.net>2017-02-13 16:04:41 +0000
committerAsbjørn Sloth Tønnesen <ast@2e8.dk>2017-02-13 16:04:41 +0000
commit907f610040e3dfb54a83155c36527a65b7f08e78 (patch)
treefa85c2deeef755ffd4d8c123f9cb68bd5ab337e2 /test/inet_set.lua
parent1e3d5d977d2d647453c3d0b4e01cf6f375422d9c (diff)
downloadlua-inet-907f610040e3dfb54a83155c36527a65b7f08e78.tar.gz
lua-inet-907f610040e3dfb54a83155c36527a65b7f08e78.tar.xz
lua-inet-907f610040e3dfb54a83155c36527a65b7f08e78.zip
initial commit
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
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)