package main

import (
	"strings"
	"testing"
)

// TestGabungKonsisten memastikan keempat versi menghasilkan teks sama.
func TestGabungKonsisten(t *testing.T) {
	potongan := buatPotongan()
	plus := gabungPlus(potongan)
	builder := gabungBuilder(potongan)
	grow := gabungBuilderGrow(potongan)
	join := strings.Join(potongan, "")
	if plus != builder || plus != grow || plus != join {
		t.Fatal("hasil keempat versi tidak identik")
	}
}

func BenchmarkGabungPlus(b *testing.B) {
	potongan := buatPotongan() // setup: tidak ikut diukur oleh for b.Loop()
	b.ReportAllocs()
	for b.Loop() {
		gabungPlus(potongan)
	}
}

func BenchmarkGabungBuilderGrow(b *testing.B) {
	potongan := buatPotongan() // setup: tidak ikut diukur oleh for b.Loop()
	b.ReportAllocs()
	for b.Loop() {
		gabungBuilderGrow(potongan)
	}
}
