title: Is it possible to dynamically assert if two values are equal or not equal when unit testing in Go?
body: <p>I've just started using Go. I'm writing unit tests and I'd like to be able to test using a table, where the result to be compared to the actual result sometimes should or should not be equal. </p>
  
  <p>For example, this is the code that I currently have: </p>
  
  <pre><code>package main
  
  import (
      "github.com/stretchr/testify/assert"
      "testing"
  )
  
  func TestFunc(t *testing.T) {
      tables := []struct {
          input               string
          comparisonResult    string
          shouldBeEqual       bool
      }{
          {
              "some irrelevant input",
              "some result",
              true,
          },
          {
              "some other irrelevant input",
              "some other result",
              false,
          },
      }
  
      for _, table := range tables {
          actualResult := sampleFunc(table.input)
          if table.shouldBeEqual {
              assert.Equal(t, table.expectedResult, actualResult)
          } else {
              assert.NotEqual(t, table.expectedResult, actualResult)
          }
      }
  }
  </code></pre>
  
  <p>Now, this isn't too bad, but it would be even better if the last bit could be changed to something cleaner like this for better readability:</p>
  
  <pre><code>for _, table := range tables {
      actualResult := sampleFunc(table.input)
      assert.EqualOrNotEqual(t, table.comparisonResult, actualResult, table.shouldBeEqual)
  }
  </code></pre>
  
  <p>So, the first test should pass if <code>table.comparisonResult</code> and <code>actualResult</code> are equal, and the second test should pass if the two <em>aren't</em> equal. </p>
  
  <p>I've looked through the <a href="https://godoc.org/github.com/stretchr/testify/assert" rel="nofollow noreferrer"><code>testify/assert</code> docs</a> and I don't think I found a function that is similar to the fake <code>EqualOrNotEqual</code> function that I made up above, but perhaps I accidentally skipped over something, or there is some kind of Go special syntax that I don't know about that might help me achieve this. </p>
  
  <p>Note: I am well aware that I can write my own function for this. My reason for asking was because if this is a well-established pattern, then packages/libraries often include it as a built-in function which may at times be undocumented/buried in the documentation. And if not, maybe there's a reason why I shouldn't do this, or maybe there's a better way of doing it. Starting to use a new language is very labour-intensive at first, not least because you have to learn all the new idioms and quirks and The Right Way to do things. </p>