<commit_before>package utils

import (
	"github.com/stretchr/testify/assert"
	"gopkg.in/yaml.v2"
	"testing"
)

func TestGetBool(t *testing.T) {
	assert := assert.New(t)

	val, err := GetAsBool("false", true)
	assert.Equal(val, false)
	assert.Nil(t, err)

	val, err = GetAsBool("notabool", false)
	assert.Equal(val, false)
	assert.NotNil(t, err)

	val, err = GetAsBool(true, false)
	assert.Equal(val, true)
	assert.Nil(t, err)

	val, err = GetAsBool("True", false)
	assert.Equal(val, true)
	assert.Nil(t, err)
}

func TestGetInt(t *testing.T) {
	assert := assert.New(t)

	val, err := GetAsInt("10", 123)
	assert.Equal(val, 10)
	assert.Nil(t, err)

	val, err = GetAsInt("notanint", 123)
	assert.Equal(val, 123)
	assert.NotNil(t, err)

	val, err = GetAsInt(12.123, 123)
	assert.Equal(val, 12)
	assert.Nil(t, err)

	val, err = GetAsInt(12, 123)
	assert.Equal(val, 12)
	assert.Nil(t, err)
}

func TestGetFloat(t *testing.T) {
	assert := assert.New(t)

	val, err := GetAsFloat("10", 123)
	assert.Equal(val, 10.0)
	assert.Nil(t, err)

	val, err = GetAsFloat("10.21", 123)
	assert.Equal(val, 10.21)
	assert.Nil(t, err)

	val, err = GetAsFloat("notafloat", 123)
	assert.Equal(val, 123.0)
	assert.NotNil(t, err)

	val, err = GetAsFloat(12.123, 123)
	assert.Equal(val, 12.123)
	assert.Nil(t, err)
}

func TestGetString(t *testing.T) {
	assert := assert.New(t)

	val := GetAsString("10")
	assert.Equal(val, "10")

	val = GetAsString(10)
	assert.Equal(val, "10")

	val = GetAsString(10.123)
	assert.Equal(val, "10.123")
}

func TestGetAsMap(t *testing.T) {
	assert := assert.New(t)

	// Test if string can be converted to map[string]string
	stringToParse := "{\"foor\" : \"bar\", \"alice\":\"bob\"}"
	expectedValue := map[string]string{
		"runtimeenv": "dev",
		"region":     "uswest1-devc",
	}
	actualValue, err := GetAsMap(stringToParse)
	assert.Equal(actualValue, expectedValue)

	// Test if map[string]interface{} can be converted to map[string]string
	interfaceMapToParse := make(map[string]interface{})
	interfaceMapToParse["foo"] = "bar"
	interfaceMapToParse["alice"] = "bob"

	actualValue, err = GetAsMap(interfaceMapToParse)
	assert.Equal(actualValue, expectedValue)

	actualValue, err = GetAsMap(123)
	assert.NotNil(t, err)
}

func TestGetAsSlice(t *testing.T) {
	assert := assert.New(t)

	// Test if string array can be converted to []string
	stringToParse := "[\"baz\", \"bat\"]"
	expectedValue := []string{"baz", "bat"}
	actualValue, err := GetAsSlice(stringToParse)
	assert.Equal(actualValue, expectedValue)<commit_msg>Using another interface for asserrt<commit_after>package utils

import (
	"github.com/stretchr/testify/assert"
	"gopkg.in/yaml.v2"
	"testing"
)

func TestGetBool(t *testing.T) {
	val, err := GetAsBool("false", true)
	assert.Equal(t, val, false)
	assert.Nil(t, err)

	val, err = GetAsBool("notabool", false)
	assert.Equal(t, val, false)
	assert.NotNil(t, err)

	val, err = GetAsBool(true, false)
	assert.Equal(t, val, true)
	assert.Nil(t, err)

	val, err = GetAsBool("True", false)
	assert.Equal(t, val, true)
	assert.Nil(t, err)
}

func TestGetInt(t *testing.T) {
	val, err := GetAsInt("10", 123)
	assert.Equal(t, val, 10)
	assert.Nil(t, err)

	val, err = GetAsInt("notanint", 123)
	assert.Equal(t, val, 123)
	assert.NotNil(t, err)

	val, err = GetAsInt(12.123, 123)
	assert.Equal(t, val, 12)
	assert.Nil(t, err)

	val, err = GetAsInt(12, 123)
	assert.Equal(t, val, 12)
	assert.Nil(t, err)
}

func TestGetFloat(t *testing.T) {
	val, err := GetAsFloat("10", 123)
	assert.Equal(t, val, 10.0)
	assert.Nil(t, err)

	val, err = GetAsFloat("10.21", 123)
	assert.Equal(t, val, 10.21)
	assert.Nil(t, err)

	val, err = GetAsFloat("notafloat", 123)
	assert.Equal(t, val, 123.0)
	assert.NotNil(t, err)

	val, err = GetAsFloat(12.123, 123)
	assert.Equal(t, val, 12.123)
	assert.Nil(t, err)
}

func TestGetString(t *testing.T) {
	val := GetAsString("10")
	assert.Equal(t, val, "10")

	val = GetAsString(10)
	assert.Equal(t, val, "10")

	val = GetAsString(10.123)
	assert.Equal(t, val, "10.123")
}

func TestGetAsMap(t *testing.T) {
	// Test if string can be converted to map[string]string
	stringToParse := "{\"foor\" : \"bar\", \"alice\":\"bob\"}"
	expectedValue := map[string]string{
		"runtimeenv": "dev",
		"region":     "uswest1-devc",
	}
	actualValue, err := GetAsMap(stringToParse)
	assert.Equal(actualValue, expectedValue)

	// Test if map[string]interface{} can be converted to map[string]string
	interfaceMapToParse := make(map[string]interface{})
	interfaceMapToParse["foo"] = "bar"
	interfaceMapToParse["alice"] = "bob"

	actualValue, err = GetAsMap(interfaceMapToParse)
	assert.Equal(actualValue, expectedValue)

	actualValue, err = GetAsMap(123)
	assert.NotNil(t, err)
}

func TestGetAsSlice(t *testing.T) {
	// Test if string array can be converted to []string
	stringToParse := "[\"baz\", \"bat\"]"
	expectedValue := []string{"baz", "bat"}
	actualValue, err := GetAsSlice(stringToParse)
	assert.Equal(actualValue, expectedValue)
{'fraction_non_alphanumeric': 0.17430822056150272, 'fraction_numerical': 0.03716420925065643, 'mean_word_length': 4.691954022988506, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '5749907', 'n_tokens_mistral': 2135, 'n_tokens_neox': 1959, 'n_words': 428}