2

I'm writing tests for Go application, my tested function is like this:

func CalculateProblem(events []interface{}){}

I'm trying to create this parameter(events) but without success. Below is my function:

func TestCalculateProblem(t *testing.T) {

    events := [][4] uint64 {{1,1,1,1}, {1,1,1,1}, {1,1,1,1}}

    CalculateProblem(events)
}

I receive the following compile error: cannot use events (variable of type [][4]uint64) as []interface{} value in argument to CalculateProblem

s0xzwasd
  • 2,895
  • 3
  • 17
  • 26
Roman Kazmin
  • 931
  • 6
  • 18
  • 3
    https://stackoverflow.com/a/12754757/11032044 – Kamol Hasan Dec 15 '21 at 15:47
  • thats one thing I find so strange about go. An empty interface can be anything and yet its very strict sometimes. Makes is less powerful imo, since now you need to do some serialization and shaping and so on. – The Fool Dec 18 '21 at 09:28

1 Answers1

0

You can do something like this.

func TestCalculateProblem(t *testing.T) {
    eventA := [4]uint64{1, 1, 1, 1}
    eventB := [4]uint64{1, 1, 1, 1}    
    CalculateProblem([]interface{}{eventA, eventB})
}
Dean Karstle
  • 83
  • 1
  • 9