@@ -204,23 +204,8 @@ func TestRandIPv4Private(t *testing.T) {
204204 t .Error ("Generated IP is not a valid IPv4 address: " + r .String ())
205205 }
206206
207- // Check if the IP is in one of the private ranges
208- isPrivate := false
209-
210- // 10.0.0.0/8 (10.0.0.0 - 10.255.255.255)
211- if r [0 ] == 10 {
212- isPrivate = true
213- }
214-
215- // 172.16.0.0/12 (172.16.0.0 - 172.31.255.255)
216- if r [0 ] == 172 && r [1 ] >= 16 && r [1 ] <= 31 {
217- isPrivate = true
218- }
219-
220- // 192.168.0.0/16 (192.168.0.0 - 192.168.255.255)
221- if r [0 ] == 192 && r [1 ] == 168 {
222- isPrivate = true
223- }
207+ // Check if the IP is private
208+ isPrivate := r .IsPrivate ()
224209
225210 if ! isPrivate {
226211 t .Error ("Generated IP is not in a private range: " + r .String ())
@@ -229,7 +214,7 @@ func TestRandIPv4Private(t *testing.T) {
229214}
230215
231216func TestRandIPv4Loopback (t * testing.T ) {
232- for range 100 {
217+ for range 5 {
233218 r := RandIPv4Loopback ()
234219 parsed := net .ParseIP (r .String ())
235220 if parsed == nil {
@@ -239,10 +224,11 @@ func TestRandIPv4Loopback(t *testing.T) {
239224 t .Error ("Generated IP is not a valid IPv4 address: " + r .String ())
240225 }
241226
242- // Check if it's exactly 127.0.0.1
243- expected := "127.0.0.1"
244- if r .String () != expected {
245- t .Error ("Generated IP is not the expected loopback address. Expected: " + expected + ", Got: " + r .String ())
227+ // Check if the IP is loopback
228+ isLoopback := r .IsLoopback ()
229+
230+ if ! isLoopback {
231+ t .Error ("Generated IP is not the expected loopback address:" + r .String ())
246232 }
247233 }
248234}
0 commit comments