package converters

import (
	"math"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestBooleanToBit(t *testing.T) {
	assert.Equal(t, 1, BooleanToBit(true))
	assert.Equal(t, 0, BooleanToBit(false))
}

func TestFloat32ToString(t *testing.T) {
	type ioPair struct {
		input  float32
		output string
	}

	ioPairs := []ioPair{
		{123.456, "123.456"},
		{0.0, "0"},
		{-1.0, "-1"},
		{1.0, "1"},
		{340282350000000000000000000000000000000, "340282350000000000000000000000000000000"},
		{math.MaxFloat32, "340282350000000000000000000000000000000"},
		{0.000000000000000000000000000000000000000000001, "0.000000000000000000000000000000000000000000001"},
		{-340282350000000000000000000000000000000, "-340282350000000000000000000000000000000"},
		{1.401298464324817070923729583289916131280e-45, "0.000000000000000000000000000000000000000000001"},
		{1.17549435e-38, "0.000000000000000000000000000000000000011754944"},
		{-1.17549435e-38, "-0.000000000000000000000000000000000000011754944"},
		{2.71828, "2.71828"},
		{-2.71828, "-2.71828"},
		{3.14159, "3.14159"},
		{-3.14159, "-3.14159"},
	}

	for _, pair := range ioPairs {
		assert.Equal(t, pair.output, Float32ToString(pair.input), pair.input)
	}
}

func TestFloat64ToString(t *testing.T) {
	type ioPair struct {
		input  float64
		output string
	}

	ioPairs := []ioPair{
		{123.456, "123.456"},
		{0.0, "0"},
		{-1.0, "-1"},
		{1.0, "1"},
		{1.7976931348623157e+308, "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},
		{math.MaxFloat64, "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},
		{4.9406564584124654e-324, "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"},
		{-1.7976931348623157e+308, "-179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},
		{2.718281828459045, "2.718281828459045"},
		{-2.718281828459045, "-2.718281828459045"},
		{3.141592653589793, "3.141592653589793"},
		{-3.141592653589793, "-3.141592653589793"},
	}

	for _, pair := range ioPairs {
		assert.Equal(t, pair.output, Float64ToString(pair.input), pair.input)
	}
}
