main_test.go 631 Bytes
Newer Older
Thomas Hoffmann's avatar
Thomas Hoffmann committed
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
package main

import (
	"crycomp/internal/blood"
	"fmt"
	"testing"
)

func TestProtocol(t *testing.T) {
	// Runs the protocol for all combinations of recipient and donor blood types.
	n := len(blood.Table)

	for x := 0; x < n; x++ {
		for y := 0; y < n; y++ {
			testName := fmt.Sprintf("(x=%s,y=%s)", blood.Names[x], blood.Names[y])
			t.Run(testName, func(t *testing.T) {
				z, err := RunProtocol(x, y, 0)
				if err != nil {
					t.Errorf("Protocol error: %s", err)
				} else if z != blood.Table[x][y] {
					t.Fatalf("Failed blood compatibility test for index [%d,%d]. Expected %t, got %t", x, y, !z, z)
				}
			})
		}
	}
}