package input

import (
	"strings"
	"testing"
)

func TestRandomCharFromWeights(t *testing.T) {
	weights := map[byte]int{
		'a': 1,
		'b': 99,
	}
	foo := randomCharFromWeights(weights)
	for {
		got := foo()
		if got == 'a' {
			break
		}
	}
}

func TestRandomCharFromWeightsReader(t *testing.T) {
	t.Run("json", func(t *testing.T) {
		b := `{"a": 1}`
		r := strings.NewReader(b)
		foo := randomCharFromWeightReader(r)
		for i := 0; i < 10; i++ {
			if got := foo(); got != 'a' {
				t.Errorf("%c", got)
			}
		}
	})
	t.Run("yaml", func(t *testing.T) {
		b := `
a: 2000
      `
		r := strings.NewReader(b)
		foo := randomCharFromWeightReader(r)
		for i := 0; i < 10; i++ {
			if got := foo(); got != 'a' {
				t.Errorf("%c", got)
			}
		}
	})
}
