package utils

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func Test_FnvHash8(t *testing.T) {
	raw := "How are you today?"
	hash := FnvHash8(raw)
	assert.Equal(t, 8, len(hash))
	raw = "How?"
	hash = FnvHash8(raw)
	assert.Equal(t, 8, len(hash))
	raw = "How?ewhjsdhsjhdfjkshdfkjshfdkshfdkshdfksdhfdkh"
	hash = FnvHash8(raw)
	assert.Equal(t, 8, len(hash))
}

func Test_UniqueIdentifierLte63(t *testing.T) {
	raw := "less than 64"
	id := UniqueIdentifierLte63(raw)
	assert.Equal(t, "less than 64-3fdafe07", id)

	raw = "longer than 641111111111111111111111111111111111111111111111111111111"
	id = UniqueIdentifierLte63(raw)
	assert.Equal(t, 63, len(id))
	assert.Equal(t, "longer than 641111111111111111111111111111111111111111-fd000f1a", id)
}

func Test_UniqueIdentifierLte63V2(t *testing.T) {
	raw := "less than 64"
	id := UniqueIdentifierLte63V2(raw)
	assert.Equal(t, raw, id)

	raw = "longer than 641111111111111111111111111111111111111111111111111111111"
	id = UniqueIdentifierLte63V2(raw)
	assert.Equal(t, 63, len(id))
	assert.Equal(t, "longer than 641111111111111111111111111111111111111111-fd000f1a", id)
}

func Test_UniqueIdentifierLte32(t *testing.T) {
	raw := "less than 32"
	id := UniqueIdentifierLte32(raw)
	assert.Equal(t, raw, id)

	raw = "longer than 32 1111111111111111111111111111111111111111111111111111111"
	id = UniqueIdentifierLte32(raw)
	assert.Equal(t, 32, len(id))
	assert.Equal(t, "longer than 32 11111111-ff145801", id)
}
