Bladeren bron

Don't call LineLength if we have UpdateF.

UpdateF already calls it.
Bugz 1 jaar geleden
bovenliggende
commit
119372e382
3 gewijzigde bestanden met toevoegingen van 31 en 14 verwijderingen
  1. 3 1
      door/line.go
  2. 9 3
      door/line_test.go
  3. 19 10
      door/nomoresecrets_test.go

+ 3 - 1
door/line.go

@@ -130,7 +130,9 @@ If there is no RenderF, we use the DefaultColor.  Otherwise we pass the text
 to RenderF and return what it returns.
 */
 func (l *Line) Output() string {
-	l.LineLength(&l.Text)
+	if l.UpdateF == nil {
+		l.LineLength(&l.Text)
+	}
 	if l.RenderF == nil {
 		return l.DefaultColor + l.Text
 	} else {

+ 9 - 3
door/line_test.go

@@ -2,6 +2,7 @@ package door
 
 import (
 	"fmt"
+	"strconv"
 	"strings"
 	"testing"
 	"unicode"
@@ -164,8 +165,12 @@ func BenchmarkLine(b *testing.B) {
 	for i := 0; i < b.N; i++ {
 		var up = 0
 		var updater = func() string {
+			output := strings.Builder{}
+			output.WriteString("The Value: ")
+			output.WriteString(strconv.Itoa(up))
 			up++
-			return fmt.Sprintf("The Value: %d", up)
+			return output.String()
+			// return fmt.Sprintf("The Value: %d", up)
 		}
 
 		var line Line = Line{Text: updater(),
@@ -174,8 +179,9 @@ func BenchmarkLine(b *testing.B) {
 			Width:   18}
 		line.Output()
 		for l := 0; l < 10; l++ {
-			line.Update()
-
+			if line.Update() {
+				line.Output()
+			}
 		}
 	}
 }

+ 19 - 10
door/nomoresecrets_test.go

@@ -23,17 +23,26 @@ func TestRandom(t *testing.T) {
 func TestNoMoreSecrets(t *testing.T) {
 
 }
+
+// Benchmark / profiling
+
+// TODO:  Update NoMoreSecrets so it can be benchmarked.
+// Currently, it needs a working door connection.
+
 func BenchmarkNoMoreSecrets(b *testing.B) {
-	Unicode = true
-	var d *Door = &Door{}
+	/*
+		Unicode = true
+		// We need a valid working Door{} object to run this.
+		var d *Door = &Door{}
 
-	for i := 0; i < b.N; i++ {
-		var output = Goto(5, 5) + ColorText("WHITE ON BLUE") + "Secret Text Revealed!"
-		var better NoMoreSecretsConfig = NoMoreSecretsDefault
-		better.Jumble_Loop_Speed = 75  // 35
-		better.Reveal_Loop_Speed = 100 // 50
-		better.Color = ColorText("BRI CYAN ON BLUE")
+		for i := 0; i < b.N; i++ {
+			var output = Goto(5, 5) + ColorText("WHITE ON BLUE") + "Secret Text Revealed!"
+			var better NoMoreSecretsConfig = NoMoreSecretsDefault
+			better.Jumble_Loop_Speed = 75  // 35
+			better.Reveal_Loop_Speed = 100 // 50
+			better.Color = ColorText("BRI CYAN ON BLUE")
 
-		NoMoreSecrets(output, d, &better)
-	}
+			NoMoreSecrets(output, d, &better)
+		}
+	*/
 }