addrgen_test.go 434 B

12345678910111213141516171819202122232425
  1. package addrgen
  2. import (
  3. "strings"
  4. "testing"
  5. )
  6. func TestAddrGen1(t *testing.T) {
  7. g := must(ParseAddrSet("10.0.0.0/17,192.168.0.0..192.168.255.255:20000-50000"))
  8. var a, b int
  9. for i := 0; i < 100; i++ {
  10. s := g.Endpoint()
  11. switch {
  12. case strings.HasPrefix(s, "10.0."):
  13. a++
  14. case strings.HasPrefix(s, "192.168."):
  15. b++
  16. default:
  17. t.Errorf("unexpected value: %q", s)
  18. }
  19. }
  20. if a > b {
  21. t.Errorf("%d > %d", a, b)
  22. }
  23. }