File: matrix_test.go

package info (click to toggle)
golang-github-cloudflare-redoctober 0.0~git20161017.0.78e9720-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 636 kB
  • sloc: sh: 65; makefile: 7
file content (44 lines) | stat: -rw-r--r-- 759 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
package msp

import (
	"testing"
)

func TestRecovery(t *testing.T) {
	// Generate the matrix.
	height, width := 10, 10
	M := Matrix(make([]Row, height))

	for i := 0; i < height; i++ {
		M[i] = NewRow(width)

		for j := 0; j < width; j++ {
			M[i][j][0] = byte(i + 1)
			M[i][j] = M[i][j].Exp(j)
		}
	}

	// Find the recovery vector.
	r, ok := M.Recovery()
	if !ok {
		t.Fatalf("Failed to find the recovery vector!")
	}

	// Find the output vector.
	out := NewRow(width)

	for i := 0; i < height; i++ {
		out.AddM(M[i].Mul(r[i]))
	}

	// Check that it is the target vector.
	if !out[0].IsOne() {
		t.Fatalf("Output is not the target vector!")
	}

	for i := 1; i < width; i++ {
		if !out[i].IsZero() {
			t.Fatalf("Output is not the target vector!")
		}
	}
}