コード例 #1
0
ファイル: randutil_test.go プロジェクト: jadengore/randutil
// TestWeightedChoice assembles a list of choices, weighted 0-9, and tests that
// over the course of 1,000,000 calls to WeightedChoice() each choice is
// returned more often than choices with a lower weight.
func TestWeightedChoice(t *testing.T) {
	// Make weighted choices
	var choices []Choice
	chosenCount := make(map[Choice]int)
	for i := 0; i < 10; i++ {
		c := Choice{
			Weight: i,
			Item:   i,
		}
		choices = append(choices, c)
		chosenCount[c] = 0
	}
	// Run WeightedChoice() a million times, and record how often it returns each
	// of the possible choices.
	for i := 0; i < 1000000; i++ {
		c, err := WeightedChoice(choices)
		if err != nil {
			t.Error(err)
		}
		chosenCount[c] += 1
	}
	// Test that higher weighted choices were chosen more often than their lower
	// weighted peers.
	for i, c := range choices[0 : len(choices)-1] {
		next := choices[i+1]
		expr := chosenCount[c] < chosenCount[next]
		assert.T(t, expr)
	}
}
コード例 #2
0
ファイル: node_index_test.go プロジェクト: jadengore/neoism
// 18.9.4. List node indexes
func TestListLegacyNodeIndexes(t *testing.T) {
	db := connectTest(t)
	name := rndStr(t)
	idx0, _ := db.CreateLegacyNodeIndex(name, "", "")
	defer idx0.Delete()
	indexes, err := db.LegacyNodeIndexes()
	if err != nil {
		t.Error(err)
	}
	valid := false
	for _, i := range indexes {
		if i.Name == name {
			valid = true
		}
	}
	assert.T(t, valid, "Newly created Index not found in listing of all Indexes.")
}
コード例 #3
0
ファイル: transaction_test.go プロジェクト: jadengore/neoism
func TestTxBadQuery(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	qs := []*CypherQuery{
		&CypherQuery{
			Statement: `CREATE (n:Person) RETURN n`,
		},
		&CypherQuery{
			Statement: `CREATE (n:Person) RETURN n`,
		},
		&CypherQuery{
			Statement: `foobar`,
		},
		&CypherQuery{
			Statement: `CREATE (n:Person) RETURN n`,
		},
	}
	tx, err := db.Begin(qs)
	tx.Rollback() // Else cleanup will hang til Tx times out
	assert.Equal(t, TxQueryError, err)
	numErr := len(tx.Errors)
	assert.T(t, numErr == 1, "Expected one tx error, got "+strconv.Itoa(numErr))
}