You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
796 B

  1. package progressbar
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func TestProgressBar(t *testing.T) {
  8. zero := int64(0)
  9. hundred := int64(100)
  10. var bar Bar
  11. bar.NewOption(zero, hundred)
  12. require.Equal(t, zero, bar.start)
  13. require.Equal(t, zero, bar.cur)
  14. require.Equal(t, hundred, bar.total)
  15. require.Equal(t, zero, bar.percent)
  16. require.Equal(t, "█", bar.graph)
  17. require.Equal(t, "", bar.rate)
  18. defer bar.Finish()
  19. for i := zero; i <= hundred; i++ {
  20. time.Sleep(1 * time.Millisecond)
  21. bar.Play(i)
  22. }
  23. require.Equal(t, zero, bar.start)
  24. require.Equal(t, hundred, bar.cur)
  25. require.Equal(t, hundred, bar.total)
  26. require.Equal(t, hundred, bar.percent)
  27. var rate string
  28. for i := zero; i < hundred/2; i++ {
  29. rate += "█"
  30. }
  31. require.Equal(t, rate, bar.rate)
  32. }