Пример #1
0
func TestBranchOrderNonZero(t *testing.T) {
	maxBranch := 5
	maxTail := 4
	// Test branch reordering for branch no. > 0. We test all branch values
	// within [1, 5] in a slice of up to 9 (maxBranch-1 + branch-pivot +
	// maxTail) keys. Hopefully that covers all combinations and edge-cases.
	// We test the case where branch no. is 0 elsewhere.
	for branch := 1; branch <= maxBranch; branch++ {
		for j := 0; j <= maxTail; j++ {
			first := createTestPubKeys(t, branch-1, 0)
			pivot := createTestPubKeys(t, 1, branch)
			last := createTestPubKeys(t, j, branch+1)

			inKeys := append(append(first, pivot...), last...)
			wantKeys := append(append(pivot, first...), last...)
			resKeys, err := vp.TstBranchOrder(inKeys, vp.Branch(branch))
			if err != nil {
				t.Fatalf("Error ordering keys: %v", err)
			}

			if len(resKeys) != len(inKeys) {
				t.Errorf("BranchOrder: wrong no. of keys. Got: %d, want %d",
					len(resKeys), len(inKeys))
			}

			for idx := 0; idx < len(inKeys); idx++ {
				if resKeys[idx] != wantKeys[idx] {
					o, w, g := branchErrorFormat(inKeys, wantKeys, resKeys)
					t.Errorf("Branch: %d\nOrig: %v\nGot: %v\nWant: %v", branch, o, g, w)
				}
			}
		}
	}
}
Пример #2
0
func TestBranchOrderZero(t *testing.T) {
	// test change address branch (0) for 0-10 keys
	for i := 0; i < 10; i++ {
		inKeys := createTestPubKeys(t, i, 0)
		wantKeys := reverse(inKeys)
		resKeys, err := vp.TstBranchOrder(inKeys, 0)
		if err != nil {
			t.Fatalf("Error ordering keys: %v", err)
		}

		if len(resKeys) != len(wantKeys) {
			t.Errorf("BranchOrder: wrong no. of keys. Got: %d, want %d",
				len(resKeys), len(inKeys))
			return
		}

		for keyIdx := 0; i < len(inKeys); i++ {
			if resKeys[keyIdx] != wantKeys[keyIdx] {
				t.Errorf("BranchOrder(keys, 0): got %v, want %v",
					resKeys[i], wantKeys[i])
			}
		}
	}
}
Пример #3
0
func TestBranchOrderInvalidBranch(t *testing.T) {
	_, err := vp.TstBranchOrder(createTestPubKeys(t, 3, 0), 4)

	vp.TstCheckError(t, "", err, vp.ErrInvalidBranch)
}
Пример #4
0
func TestBranchOrderNilKeys(t *testing.T) {
	_, err := vp.TstBranchOrder(nil, 1)

	vp.TstCheckError(t, "", err, vp.ErrInvalidValue)
}