MCPcopy
hub / github.com/shadow1ng/fscan / TestArrayCountValueTop

Function TestArrayCountValueTop

core/icmp_test.go:368–450  ·  view source on GitHub ↗

TestArrayCountValueTop 测试IP网段统计

(t *testing.T)

Source from the content-addressed store, hash-verified

366
367// TestArrayCountValueTop 测试IP网段统计
368func TestArrayCountValueTop(t *testing.T) {
369 t.Run("C段统计", func(t *testing.T) {
370 ips := []string{
371 "192.168.1.1",
372 "192.168.1.2",
373 "192.168.1.3",
374 "192.168.2.1",
375 "192.168.2.2",
376 "10.0.0.1",
377 }
378
379 arrTop, arrLen := ArrayCountValueTop(ips, 2, false)
380
381 if len(arrTop) != 2 {
382 t.Errorf("期望返回2个网段, 实际 %d", len(arrTop))
383 }
384
385 // 第一名应该是 192.168.1 (3个IP)
386 if arrTop[0] != "192.168.1" || arrLen[0] != 3 {
387 t.Errorf("第一名应为 192.168.1(3), 实际 %s(%d)", arrTop[0], arrLen[0])
388 }
389
390 // 第二名应该是 192.168.2 (2个IP)
391 if arrTop[1] != "192.168.2" || arrLen[1] != 2 {
392 t.Errorf("第二名应为 192.168.2(2), 实际 %s(%d)", arrTop[1], arrLen[1])
393 }
394 })
395
396 t.Run("B段统计", func(t *testing.T) {
397 ips := []string{
398 "192.168.1.1",
399 "192.168.2.1",
400 "192.168.3.1",
401 "10.0.1.1",
402 "10.0.2.1",
403 }
404
405 arrTop, arrLen := ArrayCountValueTop(ips, 2, true)
406
407 if len(arrTop) != 2 {
408 t.Errorf("期望返回2个B段, 实际 %d", len(arrTop))
409 }
410
411 // 第一名应该是 192.168 (3个IP)
412 if arrTop[0] != "192.168" || arrLen[0] != 3 {
413 t.Errorf("第一名应为 192.168(3), 实际 %s(%d)", arrTop[0], arrLen[0])
414 }
415 })
416
417 t.Run("空列表", func(t *testing.T) {
418 arrTop, arrLen := ArrayCountValueTop([]string{}, 5, false)
419
420 if len(arrTop) != 0 || len(arrLen) != 0 {
421 t.Error("空列表应返回空结果")
422 }
423 })
424
425 t.Run("请求数量超过实际网段数", func(t *testing.T) {

Callers

nothing calls this directly

Calls 3

ArrayCountValueTopFunction · 0.85
RunMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected