// Code generated by azure-service-operator-codegen. DO NOT EDIT.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package storage

import (
	"encoding/json"
	"github.com/google/go-cmp/cmp"
	"github.com/google/go-cmp/cmp/cmpopts"
	"github.com/kr/pretty"
	"github.com/kylelemons/godebug/diff"
	"github.com/leanovate/gopter"
	"github.com/leanovate/gopter/gen"
	"github.com/leanovate/gopter/prop"
	"os"
	"reflect"
	"testing"
)

func Test_Policy_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 20
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of Policy via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPolicy, PolicyGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForPolicy runs a test to see if a specific instance of Policy round trips to JSON and back losslessly
func RunJSONSerializationTestForPolicy(subject Policy) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual Policy
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of Policy instances for property testing - lazily instantiated by PolicyGenerator()
var policyGenerator gopter.Gen

// PolicyGenerator returns a generator of Policy instances for property testing.
func PolicyGenerator() gopter.Gen {
	if policyGenerator != nil {
		return policyGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddRelatedPropertyGeneratorsForPolicy(generators)
	policyGenerator = gen.Struct(reflect.TypeOf(Policy{}), generators)

	return policyGenerator
}

// AddRelatedPropertyGeneratorsForPolicy is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForPolicy(gens map[string]gopter.Gen) {
	gens["Spec"] = Policy_SpecGenerator()
	gens["Status"] = Policy_STATUSGenerator()
}

func Test_PolicyOperatorSpec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 100
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of PolicyOperatorSpec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPolicyOperatorSpec, PolicyOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForPolicyOperatorSpec runs a test to see if a specific instance of PolicyOperatorSpec round trips to JSON and back losslessly
func RunJSONSerializationTestForPolicyOperatorSpec(subject PolicyOperatorSpec) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual PolicyOperatorSpec
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of PolicyOperatorSpec instances for property testing - lazily instantiated by PolicyOperatorSpecGenerator()
var policyOperatorSpecGenerator gopter.Gen

// PolicyOperatorSpecGenerator returns a generator of PolicyOperatorSpec instances for property testing.
func PolicyOperatorSpecGenerator() gopter.Gen {
	if policyOperatorSpecGenerator != nil {
		return policyOperatorSpecGenerator
	}

	generators := make(map[string]gopter.Gen)
	policyOperatorSpecGenerator = gen.Struct(reflect.TypeOf(PolicyOperatorSpec{}), generators)

	return policyOperatorSpecGenerator
}

func Test_Policy_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 80
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of Policy_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPolicy_STATUS, Policy_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForPolicy_STATUS runs a test to see if a specific instance of Policy_STATUS round trips to JSON and back losslessly
func RunJSONSerializationTestForPolicy_STATUS(subject Policy_STATUS) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual Policy_STATUS
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of Policy_STATUS instances for property testing - lazily instantiated by Policy_STATUSGenerator()
var policy_STATUSGenerator gopter.Gen

// Policy_STATUSGenerator returns a generator of Policy_STATUS instances for property testing.
func Policy_STATUSGenerator() gopter.Gen {
	if policy_STATUSGenerator != nil {
		return policy_STATUSGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPolicy_STATUS(generators)
	policy_STATUSGenerator = gen.Struct(reflect.TypeOf(Policy_STATUS{}), generators)

	return policy_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForPolicy_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPolicy_STATUS(gens map[string]gopter.Gen) {
	gens["Format"] = gen.PtrOf(gen.AlphaString())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
	gens["Value"] = gen.PtrOf(gen.AlphaString())
}

func Test_Policy_Spec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 80
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of Policy_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPolicy_Spec, Policy_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForPolicy_Spec runs a test to see if a specific instance of Policy_Spec round trips to JSON and back losslessly
func RunJSONSerializationTestForPolicy_Spec(subject Policy_Spec) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual Policy_Spec
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of Policy_Spec instances for property testing - lazily instantiated by Policy_SpecGenerator()
var policy_SpecGenerator gopter.Gen

// Policy_SpecGenerator returns a generator of Policy_Spec instances for property testing.
// We first initialize policy_SpecGenerator with a simplified generator based on the
// fields with primitive types then replacing it with a more complex one that also handles complex fields
// to ensure any cycles in the object graph properly terminate.
func Policy_SpecGenerator() gopter.Gen {
	if policy_SpecGenerator != nil {
		return policy_SpecGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPolicy_Spec(generators)
	policy_SpecGenerator = gen.Struct(reflect.TypeOf(Policy_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPolicy_Spec(generators)
	AddRelatedPropertyGeneratorsForPolicy_Spec(generators)
	policy_SpecGenerator = gen.Struct(reflect.TypeOf(Policy_Spec{}), generators)

	return policy_SpecGenerator
}

// AddIndependentPropertyGeneratorsForPolicy_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPolicy_Spec(gens map[string]gopter.Gen) {
	gens["Format"] = gen.PtrOf(gen.AlphaString())
	gens["OriginalVersion"] = gen.AlphaString()
	gens["Value"] = gen.PtrOf(gen.AlphaString())
}

// AddRelatedPropertyGeneratorsForPolicy_Spec is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForPolicy_Spec(gens map[string]gopter.Gen) {
	gens["OperatorSpec"] = gen.PtrOf(PolicyOperatorSpecGenerator())
}
