From 89bcd4b4a2fe6a55461efb1f95f979cebffdf718 Mon Sep 17 00:00:00 2001 From: siyul-park Date: Tue, 26 May 2026 12:03:02 +0900 Subject: [PATCH] test(benchmarks): cover fib program execution --- benchmarks/go.mod | 4 ++++ benchmarks/go.sum | 2 ++ benchmarks/programs_test.go | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 benchmarks/programs_test.go diff --git a/benchmarks/go.mod b/benchmarks/go.mod index 0083a8f..e0e27dc 100644 --- a/benchmarks/go.mod +++ b/benchmarks/go.mod @@ -6,16 +6,20 @@ require ( github.com/d5/tengo/v2 v2.17.0 github.com/dop251/goja v0.0.0-20260311135729-065cd970411c github.com/siyul-park/minivm v0.0.0 + github.com/stretchr/testify v1.11.1 github.com/tetratelabs/wazero v1.11.0 github.com/yuin/gopher-lua v1.1.2 ) require ( + github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.11.4 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/sys v0.38.0 // indirect golang.org/x/text v0.3.8 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) replace github.com/siyul-park/minivm => ../ diff --git a/benchmarks/go.sum b/benchmarks/go.sum index fec80f6..1728153 100644 --- a/benchmarks/go.sum +++ b/benchmarks/go.sum @@ -24,6 +24,8 @@ golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/benchmarks/programs_test.go b/benchmarks/programs_test.go new file mode 100644 index 0000000..7dfeb15 --- /dev/null +++ b/benchmarks/programs_test.go @@ -0,0 +1,41 @@ +package bench + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/siyul-park/minivm/interp" + "github.com/siyul-park/minivm/types" +) + +func TestFib(t *testing.T) { + t.Run("base case returns input", func(t *testing.T) { + ctx := context.Background() + i := interp.New(Fib(1)) + defer i.Close() + + err := i.Run(ctx) + require.NoError(t, err) + + got, err := i.Pop() + require.NoError(t, err) + require.Equal(t, types.I32(1), got) + require.Equal(t, 0, i.Len()) + }) + + t.Run("recursive case returns fibonacci value", func(t *testing.T) { + ctx := context.Background() + i := interp.New(Fib(7)) + defer i.Close() + + err := i.Run(ctx) + require.NoError(t, err) + + got, err := i.Pop() + require.NoError(t, err) + require.Equal(t, types.I32(13), got) + require.Equal(t, 0, i.Len()) + }) +}