File: program_test.go

package info (click to toggle)
addchain 0.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,396 kB
  • sloc: sh: 428; makefile: 10
file content (29 lines) | stat: -rw-r--r-- 501 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
package addchain

import (
	"testing"

	"github.com/mmcloughlin/addchain/internal/assert"
)

func TestProgramEvaluateDoublings(t *testing.T) {
	// Build a chain of doublings.
	p := Program{}
	n := 17
	for i := 0; i < n; i++ {
		_, err := p.Double(i)
		assert.NoError(t, err)
	}

	// Evaluate.
	c := p.Evaluate()
	for i, got := range c {
		if !got.IsUint64() {
			t.Fatal("expected to be representable as uint64")
		}
		expect := uint64(1) << uint(i)
		if got.Uint64() != expect {
			t.Fail()
		}
	}
}