// Test if all tallies have equal value and the value is lower than alpha.
// Snowball will never decide.
Test if all tallies have equal value and the value is lower than alpha.
Snowball will never decide.
// Test if all tallies have equal value and the value is lower than alpha . // Snowball will never decide .
func TestSnowball_EqualTally_LowerThanAlpha(t *testing.T) {
	snowballBeta := 10
	defaultBeta := conf.GetSnowballBeta()
	conf.Update(conf.WithSnowballBeta(snowballBeta))
	defer func() {
		conf.Update(conf.WithSnowballBeta(defaultBeta))
	}()
	snowballK := 10
	snowball := NewSnowball()
	var votes []Vote
	for i := 0; i < snowballK; i++ {
		votes = append(votes, newTestVote(i, 0.1, getRandomID(t), nil))
	}
	for i := 0; i < snowballBeta*2; i++ {
		assert.False(t, snowball.Decided())
		snowball.Tick(votes)
		assert.Nil(t, snowball.Preferred())
	}
	assert.False(t, snowball.Decided())
	assert.Nil(t, snowball.Preferred())
	snowball.Reset()
	last := votes[mrand.Intn(len(votes))].(*testVote)
	snowball.Prefer(last)
	for i := 0; i < snowballBeta*2; i++ {
		assert.False(t, snowball.Decided())
		snowball.Tick(votes)
		assert.Equal(t, *last, *snowball.Preferred().(*testVote))
	}
	assert.False(t, snowball.Decided())
	assert.Equal(t, *last, *snowball.Preferred().(*testVote))
}
func TestSnowball_EqualTally_LowerThanAlpha ( t * testing . T ) { snowballBeta := 10 defaultBeta := conf . GetSnowballBeta ( ) conf . Update ( conf . WithSnowballBeta ( snowballBeta ) ) defer func ( ) { conf . Update ( conf . WithSnowballBeta ( defaultBeta ) ) } ( ) snowballK := 10 snowball := NewSnowball ( ) var votes [ ] Vote for i := 0 ; i < snowballK ; i ++ { votes = append ( votes , newTestVote ( i , 0.1 , getRandomID ( t ) , nil ) ) } for i := 0 ; i < snowballBeta * 2 ; i ++ { assert . False ( t , snowball . Decided ( ) ) snowball . Tick ( votes ) assert . Nil ( t , snowball . Preferred ( ) ) } assert . False ( t , snowball . Decided ( ) ) assert . Nil ( t , snowball . Preferred ( ) ) snowball . Reset ( ) last := votes [ mrand . Intn ( len ( votes ) ) ] . ( * testVote ) snowball . Prefer ( last ) for i := 0 ; i < snowballBeta * 2 ; i ++ { assert . False ( t , snowball . Decided ( ) ) snowball . Tick ( votes ) assert . Equal ( t , * last , * snowball . Preferred ( ) . ( * testVote ) ) } assert . False ( t , snowball . Decided ( ) ) assert . Equal ( t , * last , * snowball . Preferred ( ) . ( * testVote ) ) }
Test if all tallies have equal value and the value is lower than alpha.
Test if all tallies have equal value and the value is lower than alpha .
// Case 1: the snowball does not have preferred. // Expected: The snowball will never have preferred. // Case 1: the snowball already has preferred. // Expected: The preferred will not change. // Prefer a random vote