package main import ( "math/big" "testing" ) func TestIPtoInt(t *testing.T) { tests := map[string]*big.Int{ "192.168.0.1": big.NewInt(3232235521), "10.0.0.1": big.NewInt(167772161), } for test := range tests { r, err := IPtoInt(test) if err != nil { t.Errorf("failed to convert %s to an int: %s", test, err) } if r.Cmp(tests[test]) != 0 { t.Errorf("convert %s to int, got %d expected %d", test, r, tests[test]) } } if _, err := IPtoInt("10"); err == nil { t.Error("calling IPtoInt with invalid IP did not result in error") } } func TestIPtoN(t *testing.T) { tests := map[string]string{ "3232235521": "192.168.0.1", "167772161": "10.0.0.1", } for test := range tests { r, err := IPtoN(test) if err != nil { t.Errorf("failed to convert %s to an address: %s", test, err) } if r != tests[test] { t.Errorf("convert %s to address, got %s expected %s", test, r, tests[test]) } } }