tres: Add address helpers

This commit is contained in:
Eishun Kondoh 2018-10-09 10:57:30 +09:00
parent f7a21ae9b1
commit d0683cf721
5 changed files with 267 additions and 0 deletions

View file

@ -0,0 +1,17 @@
defmodule IPv4AddressTest do
use ExUnit.Case, async: false
describe "IPv4Address.parse/1" do
test "with host(/32) address string" do
expect = {{192, 168, 10, 1}, {255, 255, 255, 255}}
ipaddr = "192.168.10.1"
assert Tres.IPv4Address.parse(ipaddr) == expect
end
test "with network(/24) address string" do
expect = {{192, 168, 10, 0}, {255, 255, 255, 0}}
ipaddr = "192.168.10.0/24"
assert Tres.IPv4Address.parse(ipaddr) == expect
end
end
end

53
test/mac_address_test.exs Normal file
View file

@ -0,0 +1,53 @@
defmodule MacAddressTest do
use ExUnit.Case, async: false
describe "MacAddr.bin_to_str/1" do
test "with 48 bit binary" do
mac_bin = <<0x11, 0x22, 0x33, 0x44, 0x55, 0x66>>
assert Tres.MacAddress.bin_to_str(mac_bin) == "112233445566"
end
end
describe "MacAddr.to_a/1" do
test "with String" do
expect = [0x11, 0x22, 0x33, 0x44, 0x55, 0x66]
assert Tres.MacAddress.to_a("112233445566") == expect
end
end
describe "MacAddr.to_i/1" do
test "with String" do
expect = 0x112233445566
assert Tres.MacAddress.to_i("112233445566") == expect
end
end
describe "MacAddr.broadcast?/1" do
test "with unicast" do
mac = "0e2ecad87537"
refute Tres.MacAddress.is_broadcast?(mac)
end
test "with bcast" do
mac = "ffffffffffff"
assert Tres.MacAddress.is_broadcast?(mac)
end
end
describe "MacAddr.multicast?/1" do
test "with unicast" do
mac = "0e2ecad87537"
refute Tres.MacAddress.is_multicast?(mac)
end
test "with bcast" do
mac = "ffffffffffff"
assert Tres.MacAddress.is_multicast?(mac)
end
test "with mcast" do
mac = "ffffffffffff"
assert Tres.MacAddress.is_multicast?(mac)
end
end
end