github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/math/range_test.go (about)

     1  package math_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/MontFerret/ferret/pkg/runtime/values"
     8  	"github.com/MontFerret/ferret/pkg/stdlib/math"
     9  
    10  	. "github.com/smartystreets/goconvey/convey"
    11  )
    12  
    13  func TestRange(t *testing.T) {
    14  	Convey("Should return range of numbers", t, func() {
    15  		out, err := math.Range(context.Background(), values.NewInt(1), values.NewInt(4))
    16  
    17  		So(err, ShouldBeNil)
    18  		So(out.String(), ShouldEqual, "[1,2,3,4]")
    19  
    20  		out, err = math.Range(context.Background(),
    21  			values.NewInt(1),
    22  			values.NewInt(4),
    23  			values.NewInt(2))
    24  
    25  		So(err, ShouldBeNil)
    26  		So(out.String(), ShouldEqual, "[1,3]")
    27  
    28  		out, err = math.Range(context.Background(),
    29  			values.NewInt(1),
    30  			values.NewInt(4),
    31  			values.NewInt(3),
    32  		)
    33  
    34  		So(err, ShouldBeNil)
    35  		So(out.String(), ShouldEqual, "[1,4]")
    36  
    37  		out, err = math.Range(context.Background(),
    38  			values.NewFloat(1.5),
    39  			values.NewFloat(2.5),
    40  		)
    41  
    42  		So(err, ShouldBeNil)
    43  		So(out.String(), ShouldEqual, "[1.5,2.5]")
    44  
    45  		out, err = math.Range(context.Background(),
    46  			values.NewFloat(1.5),
    47  			values.NewFloat(2.5),
    48  			values.NewFloat(0.5),
    49  		)
    50  
    51  		So(err, ShouldBeNil)
    52  		So(out.String(), ShouldEqual, "[1.5,2,2.5]")
    53  
    54  		out, err = math.Range(context.Background(),
    55  			values.NewFloat(-0.75),
    56  			values.NewFloat(1.1),
    57  			values.NewFloat(0.5),
    58  		)
    59  
    60  		So(err, ShouldBeNil)
    61  		So(out.String(), ShouldEqual, "[-0.75,-0.25,0.25,0.75]")
    62  	})
    63  }