bar_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package door
  2. import (
  3. "testing"
  4. )
  5. func TestBarHalfStep(t *testing.T) {
  6. // This is normally done by door init, but we're skipping that right now
  7. Unicode = true
  8. BOXES = BOXES_UNICODE
  9. BarColor := ColorText("BLUE")
  10. bar := BarLine{Line: Line{DefaultColor: BarColor}, Width: 10, Style: SOLID}
  11. BarSolid := map[int]string{0: BarColor + " ",
  12. 5: BarColor + " ",
  13. 10: BarColor + "\u2588 ",
  14. 20: BarColor + "\u2588\u2588 ",
  15. 25: BarColor + "\u2588\u2588 ",
  16. 50: BarColor + "\u2588\u2588\u2588\u2588\u2588 ",
  17. 75: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588 ",
  18. 100: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
  19. }
  20. for pct, text := range BarSolid {
  21. bar.Percent = int64(pct * 100)
  22. got := bar.Output()
  23. if got != text {
  24. t.Errorf("BarHalf: Expected %#v (%d%%), got %#v", text, pct, got)
  25. }
  26. }
  27. BarColor = ColorText("BLA ON WHI")
  28. bar = BarLine{Line: Line{DefaultColor: BarColor}, Width: 10, Style: HALF_STEP}
  29. BarHalf := map[int]string{0: BarColor + " ",
  30. 5: BarColor + "\u258c ",
  31. 6: BarColor + "\u258c ",
  32. 10: BarColor + "\u2588 ",
  33. 20: BarColor + "\u2588\u2588 ",
  34. 25: BarColor + "\u2588\u2588\u258c ",
  35. 26: BarColor + "\u2588\u2588\u258c ",
  36. 50: BarColor + "\u2588\u2588\u2588\u2588\u2588 ",
  37. 75: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258c ",
  38. 100: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
  39. }
  40. for pct, text := range BarHalf {
  41. bar.Percent = int64(pct * 100)
  42. got := bar.Output()
  43. if got != text {
  44. t.Errorf("BarHalf: Expected %#v (%d%%), got %#v", text, pct, got)
  45. }
  46. }
  47. BarColor = ColorText("RED")
  48. bar = BarLine{Line: Line{DefaultColor: BarColor}, Width: 10, Style: GRADIENT}
  49. BarGrad := map[int]string{0: BarColor + " ",
  50. 3: BarColor + "\u2591 ",
  51. 5: BarColor + "\u2592 ",
  52. 8: BarColor + "\u2593 ",
  53. 10: BarColor + "\u2588 ",
  54. 20: BarColor + "\u2588\u2588 ",
  55. 25: BarColor + "\u2588\u2588\u2592 ",
  56. 50: BarColor + "\u2588\u2588\u2588\u2588\u2588 ",
  57. 75: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2592 ",
  58. 100: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
  59. }
  60. for pct, text := range BarGrad {
  61. bar.Percent = int64(pct * 100)
  62. got := bar.Output()
  63. if got != text {
  64. t.Errorf("BarGradient: Expected %#v (%d%%), got %#v", text, pct, got)
  65. }
  66. }
  67. }