<commit_before>//   Copyright © 2015-2017 <NAME> (github.com/ivan-kostko; github.com/gopot)

//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at

//       http://www.apache.org/licenses/LICENSE-2.0

//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

package concurrentmap_test

import (
	"reflect"
	"testing"

	. "github.com/gopot/concurrent-map"
)

func TestNewItemsCycle(t *testing.T) {

	testCases := []struct {
		TestAlias     string
		InitCapacity  int
		ExpectedItems map[interface{}]interface{}
	}{
		{
			TestAlias:     "Converting simple map into a concurrent map",
			InitCapacity:  1,
			ExpectedItems: map[interface{}]interface{}{},
		},
	}

	for _, testCase := range testCases {
		testAlias := testCase.TestAlias
		initCapacity := testCase.InitCapacity
		expectedItems := testCase.ExpectedItems

		testFn := func(t *testing.T) {

			newCm := New(initCapacity)

			actualItems := newCm.Items()

			if !(reflect.DeepEqual(actualItems, expectedItems)) {
				t.Errorf("%s :: (New(%d)).Items() returned \r\n %v \r\n while expected \r\n %v ", testAlias, initCapacity, actualItems, expectedItems)
			}
		}
		t.Run(testAlias, testFn)
	}

}

func TestMakeConcurrentCopyItemsCycle(t *testing.T) {

	testCases := []struct {
		TestAlias     string
		OriginalMap   map[interface{}]interface{}
		ExpectedItems map[interface{}]interface{}
	}{
		{
			TestAlias:     "Converting simple map into a concurrent map",
			OriginalMap:   map[interface{}]interface{}{"key1": "stringValue", "key2": 123},
			ExpectedItems: map[interface{}]interface{}{"key1": "stringValue", "key2": 123},
		},
	}

	for _, testCase := range testCases {
		testAlias := testCase.TestAlias
		originalMap := testCase.OriginalMap
		expectedItems := testCase.ExpectedItems

		testFn := func(t *testing.T) {

			copyCm := MakeConcurrentCopy(originalMap)

			actualItems := copyCm.Items()

			if !(reflect.DeepEqual(actualItems, expectedItems)) {
				t.Errorf("%s :: (MakeConcurrentCopy(%#v)).Items() returned \r\n %v \r\n while expected \r\n %v ", testAlias, originalMap, actualItems, expectedItems)
			}
		}
		t.Run(testAlias, testFn)
	}

}

func TestMakeRecursivelyConcurrentCopyItemsCycle(t *testing.T) {

	testCases := []struct {
		TestAlias     string
		OriginalMap   map[interface{}]interface{}
		ExpectedItems map[interface{}]interface{}
	}{
		{
			TestAlias:     "Converting simple map into a concurrent map",
			OriginalMap:   map[interface{}]interface{}{"key1": "stringValue", "key2": 123},
			ExpectedItems: map[interface{}]interface{}{"key1": "stringValue", "key2": 123},
		},
		{
			TestAlias:     "Converting nested map into a concurrent map",
			OriginalMap:   map[interface{}]interface{}{"key1": "stringValue", "key2": 123, "Map": map[interface{}]interface{}{"key1": "stringValue", "key2": 123}},
			ExpectedItems: map[interface{}]interface{}{"key1": "stringValue", "key2": 123, "Map": MakeConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123})},
		},
	}

	for _, testCase := range testCases {
		testAlias := testCase.TestAlias
		originalMap := testCase.OriginalMap
		expectedItems := testCase.ExpectedItems

		testFn := func(t *testing.T) {

			copyCm := MakeRecursivelyConcurrentCopy(originalMap)

			actualItems := copyCm.Items()

			if !(reflect.DeepEqual(actualItems, expectedItems)) {
				t.Errorf("%s :: (MakeRecursivelyConcurrentCopy(%#v)).Items() returned \r\n %#v \r\n while expected \r\n %#v ", testAlias, originalMap, actualItems, expectedItems)
			}
		}
		t.Run(testAlias, testFn)
	}

}

func TestGet(t *testing.T) {

	testCases := []struct {
		TestAlias     string
		Cm            *ConcurrentMap
		GetAKey       interface{}
		ExpectedValue interface{}
		ExpectedOk    bool
	}{
		{
			TestAlias:     "MakeConcurrentCopy and Get existing key",
			Cm:            MakeConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123}),
			GetAKey:       "key2",
			ExpectedValue: 123,
			ExpectedOk:    true,
		},
		{
			TestAlias:     "MakeConcurrentCopy and Get non-existing key",
			Cm:            MakeConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123}),
			GetAKey:       "key3",
			ExpectedValue: nil,
			ExpectedOk:    false,
		},
		{
			TestAlias:     "MakeRecursivelyConcurrentCopy and Get existing key",
			Cm:            MakeRecursivelyConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123}),
			GetAKey:       "key2",
			ExpectedValue: 123,
			ExpectedOk:    true,
		},
		{
			TestAlias:     "MakeRecursivelyConcurrentCopy and Get non-existing key",
			Cm:            MakeRecursivelyConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123}),
			GetAKey:       "key3",
			ExpectedValue: nil,
			ExpectedOk:    false,
		},
		{
			TestAlias:     "New(0) and Get non-existing key",
			Cm:            New(0),
			GetAKey:       "key3",
			ExpectedValue: nil,
			ExpectedOk:    false,
		},
		{
			TestAlias:     "new(ConcurrentMap) and Get non-existing key",
			Cm:            new(ConcurrentMap),
			GetAKey:       "key3",
			ExpectedValue: nil,
			ExpectedOk:    false,
		},
	}

	for _, testCase := range testCases {
		testAlias := testCase.TestAlias
		cm := testCase.Cm
		getAKey := testCase.GetAKey
		expectedValue := testCase.ExpectedValue
		expectedOk := testCase.ExpectedOk

		testFn := func(t *testing.T) {

			actualValue, actualOk := cm.Get(getAKey)

			if !(reflect.DeepEqual(actualValue, expectedValue)) {
				t.Errorf("%s :: cm.Get(%s) returned Value \r\n %#v \r\n while expected \r\n %#v ", testAlias, getAKey, actualValue, expectedValue)
			}
			if actualOk != expectedOk {
				t.Errorf("%s :: cm.Get(%s) returned error \r\n %#v \r\n while expected \r\n %#v ", testAlias, getAKey, actualOk, expectedOk)
			}
		}
		t.Run(testAlias, testFn)
	}

}

func TestSetGetCycle(t *testing.T) {

	testCases := []struct {
		TestAlias string
		Cm        *ConcurrentMap
		SetAKey   interface{}
		SetAValue interface{}
	}{
		{
			TestAlias: "MakeConcurrentCopy and Set existing key",
			Cm:        MakeConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123}),<commit_msg>Fix Test Error message error -> ok<commit_after>//   Copyright © 2015-2017 <NAME> (github.com/ivan-kostko; github.com/gopot)

//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at

//       http://www.apache.org/licenses/LICENSE-2.0

//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

package concurrentmap_test

import (
	"reflect"
	"testing"

	. "github.com/gopot/concurrent-map"
)

func TestNewItemsCycle(t *testing.T) {

	testCases := []struct {
		TestAlias     string
		InitCapacity  int
		ExpectedItems map[interface{}]interface{}
	}{
		{
			TestAlias:     "Converting simple map into a concurrent map",
			InitCapacity:  1,
			ExpectedItems: map[interface{}]interface{}{},
		},
	}

	for _, testCase := range testCases {
		testAlias := testCase.TestAlias
		initCapacity := testCase.InitCapacity
		expectedItems := testCase.ExpectedItems

		testFn := func(t *testing.T) {

			newCm := New(initCapacity)

			actualItems := newCm.Items()

			if !(reflect.DeepEqual(actualItems, expectedItems)) {
				t.Errorf("%s :: (New(%d)).Items() returned \r\n %v \r\n while expected \r\n %v ", testAlias, initCapacity, actualItems, expectedItems)
			}
		}
		t.Run(testAlias, testFn)
	}

}

func TestMakeConcurrentCopyItemsCycle(t *testing.T) {

	testCases := []struct {
		TestAlias     string
		OriginalMap   map[interface{}]interface{}
		ExpectedItems map[interface{}]interface{}
	}{
		{
			TestAlias:     "Converting simple map into a concurrent map",
			OriginalMap:   map[interface{}]interface{}{"key1": "stringValue", "key2": 123},
			ExpectedItems: map[interface{}]interface{}{"key1": "stringValue", "key2": 123},
		},
	}

	for _, testCase := range testCases {
		testAlias := testCase.TestAlias
		originalMap := testCase.OriginalMap
		expectedItems := testCase.ExpectedItems

		testFn := func(t *testing.T) {

			copyCm := MakeConcurrentCopy(originalMap)

			actualItems := copyCm.Items()

			if !(reflect.DeepEqual(actualItems, expectedItems)) {
				t.Errorf("%s :: (MakeConcurrentCopy(%#v)).Items() returned \r\n %v \r\n while expected \r\n %v ", testAlias, originalMap, actualItems, expectedItems)
			}
		}
		t.Run(testAlias, testFn)
	}

}

func TestMakeRecursivelyConcurrentCopyItemsCycle(t *testing.T) {

	testCases := []struct {
		TestAlias     string
		OriginalMap   map[interface{}]interface{}
		ExpectedItems map[interface{}]interface{}
	}{
		{
			TestAlias:     "Converting simple map into a concurrent map",
			OriginalMap:   map[interface{}]interface{}{"key1": "stringValue", "key2": 123},
			ExpectedItems: map[interface{}]interface{}{"key1": "stringValue", "key2": 123},
		},
		{
			TestAlias:     "Converting nested map into a concurrent map",
			OriginalMap:   map[interface{}]interface{}{"key1": "stringValue", "key2": 123, "Map": map[interface{}]interface{}{"key1": "stringValue", "key2": 123}},
			ExpectedItems: map[interface{}]interface{}{"key1": "stringValue", "key2": 123, "Map": MakeConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123})},
		},
	}

	for _, testCase := range testCases {
		testAlias := testCase.TestAlias
		originalMap := testCase.OriginalMap
		expectedItems := testCase.ExpectedItems

		testFn := func(t *testing.T) {

			copyCm := MakeRecursivelyConcurrentCopy(originalMap)

			actualItems := copyCm.Items()

			if !(reflect.DeepEqual(actualItems, expectedItems)) {
				t.Errorf("%s :: (MakeRecursivelyConcurrentCopy(%#v)).Items() returned \r\n %#v \r\n while expected \r\n %#v ", testAlias, originalMap, actualItems, expectedItems)
			}
		}
		t.Run(testAlias, testFn)
	}

}

func TestGet(t *testing.T) {

	testCases := []struct {
		TestAlias     string
		Cm            *ConcurrentMap
		GetAKey       interface{}
		ExpectedValue interface{}
		ExpectedOk    bool
	}{
		{
			TestAlias:     "MakeConcurrentCopy and Get existing key",
			Cm:            MakeConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123}),
			GetAKey:       "key2",
			ExpectedValue: 123,
			ExpectedOk:    true,
		},
		{
			TestAlias:     "MakeConcurrentCopy and Get non-existing key",
			Cm:            MakeConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123}),
			GetAKey:       "key3",
			ExpectedValue: nil,
			ExpectedOk:    false,
		},
		{
			TestAlias:     "MakeRecursivelyConcurrentCopy and Get existing key",
			Cm:            MakeRecursivelyConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123}),
			GetAKey:       "key2",
			ExpectedValue: 123,
			ExpectedOk:    true,
		},
		{
			TestAlias:     "MakeRecursivelyConcurrentCopy and Get non-existing key",
			Cm:            MakeRecursivelyConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123}),
			GetAKey:       "key3",
			ExpectedValue: nil,
			ExpectedOk:    false,
		},
		{
			TestAlias:     "New(0) and Get non-existing key",
			Cm:            New(0),
			GetAKey:       "key3",
			ExpectedValue: nil,
			ExpectedOk:    false,
		},
		{
			TestAlias:     "new(ConcurrentMap) and Get non-existing key",
			Cm:            new(ConcurrentMap),
			GetAKey:       "key3",
			ExpectedValue: nil,
			ExpectedOk:    false,
		},
	}

	for _, testCase := range testCases {
		testAlias := testCase.TestAlias
		cm := testCase.Cm
		getAKey := testCase.GetAKey
		expectedValue := testCase.ExpectedValue
		expectedOk := testCase.ExpectedOk

		testFn := func(t *testing.T) {

			actualValue, actualOk := cm.Get(getAKey)

			if !(reflect.DeepEqual(actualValue, expectedValue)) {
				t.Errorf("%s :: cm.Get(%s) returned Value \r\n %#v \r\n while expected \r\n %#v ", testAlias, getAKey, actualValue, expectedValue)
			}
			if actualOk != expectedOk {
				t.Errorf("%s :: cm.Get(%s) returned ok as \r\n %#v \r\n while expected \r\n %#v ", testAlias, getAKey, actualOk, expectedOk)
			}
		}
		t.Run(testAlias, testFn)
	}

}

func TestSetGetCycle(t *testing.T) {

	testCases := []struct {
		TestAlias string
		Cm        *ConcurrentMap
		SetAKey   interface{}
		SetAValue interface{}
	}{
		{
			TestAlias: "MakeConcurrentCopy and Set existing key",
			Cm:        MakeConcurrentCopy(map[interface{}]interface{}{"key1": "stringValue", "key2": 123}),
{'fraction_non_alphanumeric': 0.14078674948240166, 'fraction_numerical': 0.014109347442680775, 'mean_word_length': 3.649554367201426, 'pattern_counts': {'":': 56, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4061910', 'n_tokens_mistral': 4806, 'n_tokens_neox': 4235, 'n_words': 1007}