lib_test.go 781 B

12345678910111213141516171819202122232425262728
  1. package global
  2. import "testing"
  3. // 测试用例
  4. func TestContainsAllOptimized(t *testing.T) {
  5. // 定义测试数据
  6. tests := []struct {
  7. a []int
  8. b []int
  9. result bool
  10. }{
  11. {[]int{1, 2, 3, 4, 5}, []int{1, 2, 3, 4, 5}, true},
  12. {[]int{1, 2, 3, 4, 5}, []int{2, 3, 5}, true},
  13. {[]int{1, 2, 3, 4, 5}, []int{6}, false},
  14. {[]int{1, 2, 3, 4, 5}, []int{1, 5}, true},
  15. {[]int{1, 2, 3, 4, 5}, []int{1, 2, 6}, false},
  16. {[]int{}, []int{1}, false}, // 边界条件,a为空
  17. {[]int{1, 2, 3}, []int{}, true}, // 边界条件,b为空
  18. }
  19. // 运行测试
  20. for _, test := range tests {
  21. if result := ContainsAllOptimized(test.a, test.b); result != test.result {
  22. t.Errorf("containsAllOptimized(%v, %v) = %v; want %v", test.a, test.b, result, test.result)
  23. }
  24. }
  25. }