main_test.go 1.3 KB
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)
				}
			})
		}
	}
}
Thomas Hoffmann's avatar
Thomas Hoffmann committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

func TestProtocolInSeries(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++ {
			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)
			}
		}
	}
}

func TestProtocolFirst(t *testing.T) {
	z, err := RunProtocol(0, 0, 0)
	if err != nil {
		t.Errorf("Protocol error: %s", err)
	} else if z != blood.Table[0][0] {
		t.Fatalf("Failed blood compatibility test for index [0,0]. Expected %t, got %t", !z, z)
	}
}