Fix Emoji benchmark
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 1 Jul 2016 15:59:39 +0000 (17:59 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 1 Jul 2016 15:59:39 +0000 (17:59 +0200)
The Emoji implementations gives slightly different output. One of them pads with a space.

helpers/emoji_test.go

index c310e6d28a1c5136c58e912aa81e34e457ca9417..70c54cd55e63fb357c27c6a640fcf0f0adbee2e7 100644 (file)
@@ -13,6 +13,7 @@
 package helpers
 
 import (
+       "math"
        "reflect"
        "strings"
        "testing"
@@ -129,7 +130,10 @@ func doBenchmarkEmoji(b *testing.B, f func(in []byte) []byte) {
                        currIn := in[cnt]
                        cnt++
                        result := f(currIn.in)
-                       if len(result) != len(currIn.expect) {
+                       // The Emoji implementations gives slightly different output.
+                       diffLen := len(result) - len(currIn.expect)
+                       diffLen = int(math.Abs(float64(diffLen)))
+                       if diffLen > 30 {
                                b.Fatalf("[%d] emoji std, got \n%q but expected \n%q", j, result, currIn.expect)
                        }
                }