File: number_test.go

package info (click to toggle)
golang-github-cloudflare-redoctober 0.0~git20161017.0.78e9720-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 584 kB
  • ctags: 560
  • sloc: sh: 65; makefile: 7
file content (50 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
package msp

import (
	"bytes"
	"crypto/rand"
	"testing"
)

func TestFieldElemMultiplicationOne(t *testing.T) {
	x := FieldElem(make([]byte, ModulusSize))
	rand.Read(x)

	xy, yx := x.Mul(One), One.Mul(x)

	if !One.IsOne() {
		t.Fatalf("One is not one?")
	}

	if bytes.Compare(xy, x) != 0 || bytes.Compare(yx, x) != 0 {
		t.Fatalf("Multiplication by 1 failed!\nx = %x\n1*x = %x\nx*1 = %x", x, yx, xy)
	}
}

func TestFieldElemMultiplicationZero(t *testing.T) {
	x := FieldElem(make([]byte, ModulusSize))
	rand.Read(x)

	xy, yx := x.Mul(Zero), Zero.Mul(x)

	if !Zero.IsZero() {
		t.Fatalf("Zero is not zero?")
	}

	if !xy.IsZero() || !yx.IsZero() {
		t.Fatalf("Multiplication by 0 failed!\nx = %x\n0*x = %x\nx*0 = %x", x, yx, xy)
	}
}

func TestFieldElemInvert(t *testing.T) {
	x := FieldElem(make([]byte, ModulusSize))
	rand.Read(x)

	xInv := x.Invert()

	xy, yx := x.Mul(xInv), xInv.Mul(x)

	if !xy.IsOne() || !yx.IsOne() {
		t.Fatalf("Multiplication by inverse failed!\nx = %x\nxInv = %x\nxInv*x = %x\nx*xInv = %x", x, xInv, yx, xy)
	}
}