<commit_before>package main

import (
	"reflect"
	"testing"

	sysl "github.com/anz-bank/sysl/src/proto"
	"github.com/stretchr/testify/assert"
)

func TestTransformBlackBoxes(t *testing.T) {
	type args struct {
		blackboxes []*sysl.Attribute
	}

	eltFirst := []*sysl.Attribute{
		{
			Attribute: &sysl.Attribute_S{
				S: "Value A",
			},
		},
		{
			Attribute: &sysl.Attribute_S{
				S: "Value B",
			},
		},
	}
	attrFirst := &sysl.Attribute{
		Attribute: &sysl.Attribute_A{
			A: &sysl.Attribute_Array{
				Elt: eltFirst,
			},
		},
	}
	eltSecond := []*sysl.Attribute{
		{
			Attribute: &sysl.Attribute_S{
				S: "Value C",
			},
		},
		{
			Attribute: &sysl.Attribute_S{
				S: "Value D",
			},
		},
	}
	attrSecond := &sysl.Attribute{
		Attribute: &sysl.Attribute_A{
			A: &sysl.Attribute_Array{
				Elt: eltSecond,
			},
		},
	}

	tests := []struct {
		name string
		args args
		want [][]string
	}{
		{
			name: "Case-Null",
			args: args{blackboxes: []*sysl.Attribute{}},
			want: [][]string{},
		},
		{
			name: "Case-ConvertSuccess",
			args: args{blackboxes: []*sysl.Attribute{attrFirst, attrSecond}},
			want: [][]string{{"Value A", "Value B"}, {"Value C", "Value D"}},
		},
	}
	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			if got := TransformBlackBoxes(tt.args.blackboxes); !reflect.DeepEqual(got, tt.want) {
				t.Errorf("TransformBlackBoxes() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestParseBlackBoxesFromArgument(t *testing.T) {
	type args struct {
		blackboxFlags map[string]string
	}
	tests := []struct {
		name string
		args args
		want [][]string
	}{
		{
			name: "Case-Null",
			args: args{map[string]string{}},
			want: [][]string{},
		},
		{
			name: "Case-ConvertSuccess",
			args: args{
				map[string]string{"Value A": "Value B",
					"Value C": "Value D"},
			},
			want: [][]string{{"Value A", "Value B"},
				{"Value C", "Value D"}},
		},
	}
	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			if got := ParseBlackBoxesFromArgument(tt.args.blackboxFlags); !reflect.DeepEqual(got, tt.want) {
				t.Errorf("ParseBlackBoxesFromArgument() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestMergeAttributes(t *testing.T) {
	type args struct {
		app   map[string]*sysl.Attribute
		edpnt map[string]*sysl.Attribute
	}

	appAttr := &sysl.Attribute{
		Attribute: &sysl.Attribute_S{
			S: "Value A",
		},
	}
	appMap := map[string]*sysl.Attribute{
		"app": appAttr,
	}
	epAttr := &sysl.Attribute{
		Attribute: &sysl.Attribute_S{
			S: "Value B",
		},
	}
	epMap := map[string]*sysl.Attribute{
		"ep": epAttr,<commit_msg>Sorted the slices in the test case.<commit_after>package main

import (
	"reflect"
	"sort"
	"testing"

	sysl "github.com/anz-bank/sysl/src/proto"
	"github.com/stretchr/testify/assert"
)

func TestTransformBlackBoxes(t *testing.T) {
	type args struct {
		blackboxes []*sysl.Attribute
	}

	eltFirst := []*sysl.Attribute{
		{
			Attribute: &sysl.Attribute_S{
				S: "Value A",
			},
		},
		{
			Attribute: &sysl.Attribute_S{
				S: "Value B",
			},
		},
	}
	attrFirst := &sysl.Attribute{
		Attribute: &sysl.Attribute_A{
			A: &sysl.Attribute_Array{
				Elt: eltFirst,
			},
		},
	}
	eltSecond := []*sysl.Attribute{
		{
			Attribute: &sysl.Attribute_S{
				S: "Value C",
			},
		},
		{
			Attribute: &sysl.Attribute_S{
				S: "Value D",
			},
		},
	}
	attrSecond := &sysl.Attribute{
		Attribute: &sysl.Attribute_A{
			A: &sysl.Attribute_Array{
				Elt: eltSecond,
			},
		},
	}

	tests := []struct {
		name string
		args args
		want [][]string
	}{
		{
			name: "Case-Null",
			args: args{blackboxes: []*sysl.Attribute{}},
			want: [][]string{},
		},
		{
			name: "Case-ConvertSuccess",
			args: args{blackboxes: []*sysl.Attribute{attrFirst, attrSecond}},
			want: [][]string{{"Value A", "Value B"}, {"Value C", "Value D"}},
		},
	}
	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			if got := TransformBlackBoxes(tt.args.blackboxes); !reflect.DeepEqual(got, tt.want) {
				t.Errorf("TransformBlackBoxes() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestParseBlackBoxesFromArgument(t *testing.T) {
	type args struct {
		blackboxFlags map[string]string
	}
	tests := []struct {
		name string
		args args
		want [][]string
	}{
		{
			name: "Case-Null",
			args: args{map[string]string{}},
			want: [][]string{},
		},
		{
			name: "Case-ConvertSuccess",
			args: args{
				map[string]string{"Value A": "Value B",
					"Value C": "Value D"},
			},
			want: [][]string{{"Value A", "Value B"},
				{"Value C", "Value D"}},
		},
	}
	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			// sorting to bring them in the same order, iteration order is random in go maps
			sort.Slice(tt.want, func(i, j int) bool { return tt.want[i][0] > tt.want[j][0] })
			got := ParseBlackBoxesFromArgument(tt.args.blackboxFlags)
			sort.Slice(got, func(i, j int) bool { return got[i][0] > got[j][0] })
			if !reflect.DeepEqual(got, tt.want) {
				t.Errorf("ParseBlackBoxesFromArgument() = %v, want %v", got, tt.want)
			}
		})
	}
}

func TestMergeAttributes(t *testing.T) {
	type args struct {
		app   map[string]*sysl.Attribute
		edpnt map[string]*sysl.Attribute
	}

	appAttr := &sysl.Attribute{
		Attribute: &sysl.Attribute_S{
			S: "Value A",
		},
	}
	appMap := map[string]*sysl.Attribute{
		"app": appAttr,
	}
	epAttr := &sysl.Attribute{
		Attribute: &sysl.Attribute_S{
			S: "Value B",
		},
	}
	epMap := map[string]*sysl.Attribute{
		"ep": epAttr,
{'fraction_non_alphanumeric': 0.1848617176128093, 'fraction_numerical': 0.000727802037845706, 'mean_word_length': 3.271173271173271, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7626217', 'n_tokens_mistral': 2454, 'n_tokens_neox': 2157, 'n_words': 439}