Browse Source

Fixed half-step. Added bar test.

Steve Thielemann 3 years ago
parent
commit
18e254eb06
2 changed files with 79 additions and 1 deletions
  1. 1 1
      door/bar.go
  2. 78 0
      door/bar_test.go

+ 1 - 1
door/bar.go

@@ -103,7 +103,7 @@ func (bl *BarLine) Output() string {
 		} else {
 			output += strings.Repeat("\xdb", steps/2)
 		}
-		if steps%1 == 1 {
+		if steps%2 == 1 {
 			if Unicode {
 				output += "\u258c"
 			} else {

+ 78 - 0
door/bar_test.go

@@ -0,0 +1,78 @@
+package door
+
+import (
+	"testing"
+)
+
+func TestBarHalfStep(t *testing.T) {
+
+	// This is normally done by door init, but we're skipping that right now
+	Unicode = true
+	BOXES = BOXES_UNICODE
+
+	BarColor := ColorText("BLUE")
+
+	bar := BarLine{Line: Line{DefaultColor: BarColor}, Width: 10, Style: SOLID}
+	BarSolid := map[int]string{0: BarColor + "          ",
+		5:   BarColor + "          ",
+		10:  BarColor + "\u2588         ",
+		20:  BarColor + "\u2588\u2588        ",
+		25:  BarColor + "\u2588\u2588        ",
+		50:  BarColor + "\u2588\u2588\u2588\u2588\u2588     ",
+		75:  BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588   ",
+		100: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
+	}
+
+	for pct, text := range BarSolid {
+		bar.Percent = int64(pct * 100)
+		got := bar.Output()
+		if got != text {
+			t.Errorf("BarHalf: Expected %#v (%d%%), got %#v", text, pct, got)
+		}
+	}
+
+	BarColor = ColorText("BLA ON WHI")
+	bar = BarLine{Line: Line{DefaultColor: BarColor}, Width: 10, Style: HALF_STEP}
+	BarHalf := map[int]string{0: BarColor + "          ",
+		5:   BarColor + "\u258c         ",
+		6:   BarColor + "\u258c         ",
+		10:  BarColor + "\u2588         ",
+		20:  BarColor + "\u2588\u2588        ",
+		25:  BarColor + "\u2588\u2588\u258c       ",
+		26:  BarColor + "\u2588\u2588\u258c       ",
+		50:  BarColor + "\u2588\u2588\u2588\u2588\u2588     ",
+		75:  BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258c  ",
+		100: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
+	}
+
+	for pct, text := range BarHalf {
+		bar.Percent = int64(pct * 100)
+		got := bar.Output()
+		if got != text {
+			t.Errorf("BarHalf: Expected %#v (%d%%), got %#v", text, pct, got)
+		}
+	}
+
+	BarColor = ColorText("RED")
+	bar = BarLine{Line: Line{DefaultColor: BarColor}, Width: 10, Style: GRADIENT}
+	BarGrad := map[int]string{0: BarColor + "          ",
+		3:   BarColor + "\u2591         ",
+		5:   BarColor + "\u2592         ",
+		8:   BarColor + "\u2593         ",
+		10:  BarColor + "\u2588         ",
+		20:  BarColor + "\u2588\u2588        ",
+		25:  BarColor + "\u2588\u2588\u2592       ",
+		50:  BarColor + "\u2588\u2588\u2588\u2588\u2588     ",
+		75:  BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2592  ",
+		100: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
+	}
+
+	for pct, text := range BarGrad {
+		bar.Percent = int64(pct * 100)
+		got := bar.Output()
+		if got != text {
+			t.Errorf("BarGradient: Expected %#v (%d%%), got %#v", text, pct, got)
+		}
+	}
+
+}