main_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package yu_array
  2. import (
  3. "fmt"
  4. "testing"
  5. "unsafe"
  6. )
  7. func TestAppend(t *testing.T) {
  8. j_arr := []string{"ad", "da", "3", "2"}
  9. fmt.Println(unsafe.Pointer(&j_arr[0]), len(j_arr), cap(j_arr))
  10. j_arr = Append(j_arr, "da")
  11. fmt.Println(j_arr)
  12. fmt.Println(unsafe.Pointer(&j_arr[0]), len(j_arr), cap(j_arr))
  13. j_arr = Append(j_arr, "da")
  14. fmt.Println(j_arr)
  15. fmt.Println(unsafe.Pointer(&j_arr[0]), len(j_arr), cap(j_arr))
  16. }
  17. func TestInsert(t *testing.T) {
  18. j_arr := []string{"ad", "da", "3", "2"}
  19. // fmt.Println(unsafe.Pointer(&j_arr[0]), len(j_arr), cap(j_arr))
  20. // j_arr = Insert(j_arr, 1, "da")
  21. // fmt.Println(j_arr)
  22. // fmt.Println(unsafe.Pointer(&j_arr[0]), len(j_arr), cap(j_arr))
  23. // j_arr = Insert(j_arr, 1, "da")
  24. // fmt.Println(j_arr)
  25. // fmt.Println(unsafe.Pointer(&j_arr[0]), len(j_arr), cap(j_arr))
  26. j_arr = nil
  27. j_arr = Insert(j_arr, 0, "1")
  28. fmt.Println(j_arr)
  29. j_arr = Insert(j_arr, 1, "cccc")
  30. fmt.Println(j_arr)
  31. j_arr = Insert(j_arr, 1, "3")
  32. fmt.Println(j_arr)
  33. j_arr = Insert(j_arr, 0, "4")
  34. fmt.Println(j_arr)
  35. }
  36. func TestRemove(t *testing.T) {
  37. j_arr := []string{"ad", "da", "3", "2"}
  38. fmt.Println(unsafe.Pointer(&j_arr[0]), len(j_arr), cap(j_arr))
  39. j_arr = Remove(j_arr, 1, 4)
  40. fmt.Println(j_arr)
  41. fmt.Println(unsafe.Pointer(&j_arr[0]), len(j_arr), cap(j_arr))
  42. }
  43. func TestXor(t *testing.T) {
  44. j_arr := []byte("asdasdasd")
  45. j_key := []byte("12412214")
  46. Xor(j_arr, j_key)
  47. fmt.Println(j_arr)
  48. }
  49. func Test(t *testing.T) {
  50. j_arr := [4]byte{1, 2, 3, 4}
  51. fmt.Println(unsafe.Pointer(&j_arr[0]), unsafe.Pointer(&j_arr[:][0]))
  52. }