File: util_test.go

package info (click to toggle)
addchain 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,396 kB
  • sloc: sh: 428; makefile: 8
file content (44 lines) | stat: -rw-r--r-- 914 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package acc

import (
	"testing"

	"github.com/mmcloughlin/addchain"
	"github.com/mmcloughlin/addchain/alg/contfrac"
	"github.com/mmcloughlin/addchain/alg/dict"
	"github.com/mmcloughlin/addchain/internal/test"
	"github.com/mmcloughlin/addchain/rand"
)

// CheckRandom runs the check function against randomly generated chain programs.
func CheckRandom(t *testing.T, check func(t *testing.T, p addchain.Program)) {
	gs := []rand.Generator{
		rand.AddsGenerator{N: 10},
		rand.NewSolverGenerator(
			160,
			dict.NewAlgorithm(
				dict.SlidingWindow{K: 5},
				contfrac.NewAlgorithm(contfrac.DichotomicStrategy{}),
			),
		),
	}

	for _, g := range gs {
		g := g // scopelint
		t.Run(g.String(), test.Trials(func(t *testing.T) bool {
			c, err := g.GenerateChain()
			if err != nil {
				t.Fatal(err)
			}

			p, err := c.Program()
			if err != nil {
				t.Fatal(err)
			}

			check(t, p)

			return true
		}))
	}
}