account_load_factor_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //go:build unit
  2. package service
  3. import (
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func intPtrHelper(v int) *int { return &v }
  8. func TestEffectiveLoadFactor_NilAccount(t *testing.T) {
  9. var a *Account
  10. require.Equal(t, 1, a.EffectiveLoadFactor())
  11. }
  12. func TestEffectiveLoadFactor_NilLoadFactor_PositiveConcurrency(t *testing.T) {
  13. a := &Account{Concurrency: 5}
  14. require.Equal(t, 5, a.EffectiveLoadFactor())
  15. }
  16. func TestEffectiveLoadFactor_NilLoadFactor_ZeroConcurrency(t *testing.T) {
  17. a := &Account{Concurrency: 0}
  18. require.Equal(t, 1, a.EffectiveLoadFactor())
  19. }
  20. func TestEffectiveLoadFactor_PositiveLoadFactor(t *testing.T) {
  21. a := &Account{Concurrency: 5, LoadFactor: intPtrHelper(20)}
  22. require.Equal(t, 20, a.EffectiveLoadFactor())
  23. }
  24. func TestEffectiveLoadFactor_ZeroLoadFactor_FallbackToConcurrency(t *testing.T) {
  25. a := &Account{Concurrency: 5, LoadFactor: intPtrHelper(0)}
  26. require.Equal(t, 5, a.EffectiveLoadFactor())
  27. }
  28. func TestEffectiveLoadFactor_NegativeLoadFactor_FallbackToConcurrency(t *testing.T) {
  29. a := &Account{Concurrency: 3, LoadFactor: intPtrHelper(-1)}
  30. require.Equal(t, 3, a.EffectiveLoadFactor())
  31. }
  32. func TestEffectiveLoadFactor_ZeroLoadFactor_ZeroConcurrency(t *testing.T) {
  33. a := &Account{Concurrency: 0, LoadFactor: intPtrHelper(0)}
  34. require.Equal(t, 1, a.EffectiveLoadFactor())
  35. }