github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/internal/tests/integration/math_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestMath(t *testing.T) {
     8  	inOutTest(t, `{{ math.Add 1 2 3 4 }} {{ add -5 5 }}`, "10 0")
     9  	inOutTest(t, `{{ math.Sub 10 5 }} {{ sub -5 5 }}`, "5 -10")
    10  	inOutTest(t, `{{ math.Mul 1 2 3 4 }} {{ mul -5 5 }}`, "24 -25")
    11  	inOutTest(t, `{{ math.Div 5 2 }} {{ div -5 5 }}`, "2.5 -1")
    12  	inOutTest(t, `{{ math.Rem 5 3 }} {{ rem 2 2 }}`, "2 0")
    13  	inOutTest(t, `{{ math.Pow 8 4 }} {{ pow 2 2 }}`, "4096 4")
    14  	inOutTest(t, `{{ math.Seq 0 }}, {{ seq 0 3 }}, {{ seq -5 -10 2 }}`,
    15  		`[1 0], [0 1 2 3], [-5 -7 -9]`)
    16  	inOutTest(t, `{{ math.Round 0.99 }}, {{ math.Round "foo" }}, {{math.Round 3.5}}`,
    17  		`1, 0, 4`)
    18  	inOutTest(t, `{{ math.Max -0 "+Inf" "NaN" }}, {{ math.Max 3.4 3.401 3.399 }}`,
    19  		`+Inf, 3.401`)
    20  }