{{if .IsG2 -}}
//go:build g2

{{end -}}
package {{.PackageName}}

import (
  {{- if .IsScalar}}
  {{- template "scalar_field_tests_imports" . -}}{{end}}
	"github.com/stretchr/testify/assert"
	"testing"
)

func Test{{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}FieldFromLimbs(t *testing.T) {
	emptyField := {{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field{}
	randLimbs := generateRandomLimb(int({{if .IsScalar}}SCALAR{{else}}{{if .IsG2}}G2_{{end}}BASE{{end}}_LIMBS))
	emptyField.FromLimbs(randLimbs[:])
	assert.ElementsMatch(t, randLimbs, emptyField.limbs, "Limbs do not match; there was an issue with setting the {{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field's limbs")
	randLimbs[0] = 100
	assert.NotEqual(t, randLimbs, emptyField.limbs)
}

func Test{{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}FieldGetLimbs(t *testing.T) {
	emptyField := {{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field{}
	randLimbs := generateRandomLimb(int({{if .IsScalar}}SCALAR{{else}}{{if .IsG2}}G2_{{end}}BASE{{end}}_LIMBS))
	emptyField.FromLimbs(randLimbs[:])

	assert.ElementsMatch(t, randLimbs, emptyField.GetLimbs(), "Limbs do not match; there was an issue with setting the {{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field's limbs")
}

func Test{{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}FieldOne(t *testing.T) {
	var emptyField {{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field
	emptyField.One()
	limbOne := generateLimbOne(int({{if .IsScalar}}SCALAR{{else}}{{if .IsG2}}G2_{{end}}BASE{{end}}_LIMBS))
	assert.ElementsMatch(t, emptyField.GetLimbs(), limbOne, "Empty field to field one did not work")

	randLimbs := generateRandomLimb(int({{if .IsScalar}}SCALAR{{else}}{{if .IsG2}}G2_{{end}}BASE{{end}}_LIMBS))
	emptyField.FromLimbs(randLimbs[:])

	emptyField.One()
	assert.ElementsMatch(t, emptyField.GetLimbs(), limbOne, "{{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field with limbs to field one did not work")
}

func Test{{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}FieldZero(t *testing.T) {
	var emptyField {{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field
	emptyField.Zero()
	limbsZero := make([]uint32, {{if .IsScalar}}SCALAR{{else}}{{if .IsG2}}G2_{{end}}BASE{{end}}_LIMBS)
	assert.ElementsMatch(t, emptyField.GetLimbs(), limbsZero, "Empty field to field zero failed")

	randLimbs := generateRandomLimb(int({{if .IsScalar}}SCALAR{{else}}{{if .IsG2}}G2_{{end}}BASE{{end}}_LIMBS))
	emptyField.FromLimbs(randLimbs[:])

	emptyField.Zero()
	assert.ElementsMatch(t, emptyField.GetLimbs(), limbsZero, "{{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field with limbs to field zero failed")
}

func Test{{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}FieldSize(t *testing.T) {
	var emptyField {{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field
	randLimbs := generateRandomLimb(int({{if .IsScalar}}SCALAR{{else}}{{if .IsG2}}G2_{{end}}BASE{{end}}_LIMBS))
	emptyField.FromLimbs(randLimbs[:])

	assert.Equal(t, len(randLimbs)*4, emptyField.Size(), "Size returned an incorrect value of bytes")
}

func Test{{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}FieldAsPointer(t *testing.T) {
	var emptyField {{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field
	randLimbs := generateRandomLimb(int({{if .IsScalar}}SCALAR{{else}}{{if .IsG2}}G2_{{end}}BASE{{end}}_LIMBS))
	emptyField.FromLimbs(randLimbs[:])

	assert.Equal(t, randLimbs[0], *emptyField.AsPointer(), "AsPointer returned pointer to incorrect value")
}

func Test{{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}FieldFromBytes(t *testing.T) {
	var emptyField {{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field
	bytes, expected := generateBytesArray(int({{if .IsScalar}}SCALAR{{else}}{{if .IsG2}}G2_{{end}}BASE{{end}}_LIMBS))

	emptyField.FromBytesLittleEndian(bytes)

	assert.ElementsMatch(t, emptyField.GetLimbs(), expected, "FromBytes returned incorrect values")
}

func Test{{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}FieldToBytes(t *testing.T) {
	var emptyField {{if .IsMock}}Mock{{else}}{{if .IsScalar}}Scalar{{else}}{{if .IsG2}}G2{{end}}Base{{end}}{{end}}Field
	expected, limbs := generateBytesArray(int({{if .IsScalar}}SCALAR{{else}}{{if .IsG2}}G2_{{end}}BASE{{end}}_LIMBS))
	emptyField.FromLimbs(limbs)

	assert.ElementsMatch(t, emptyField.ToBytesLittleEndian(), expected, "ToBytes returned incorrect values")
}
{{if .IsScalar}}
{{- template "scalar_field_tests" .}}
{{end}}