github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/json/ryu/floatconv_test.gno (about)

     1  package ryu
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  )
     7  
     8  func TestFormatFloat64(t *testing.T) {
     9  	tests := []struct {
    10  		name     string
    11  		value    float64
    12  		expected string
    13  	}{
    14  		{"positive infinity", math.Inf(1), "+Inf"},
    15  		{"negative infinity", math.Inf(-1), "-Inf"},
    16  		{"NaN", math.NaN(), "NaN"},
    17  		{"zero", 0.0, "0e+00"},
    18  		{"negative zero", -0.0, "0e+00"},
    19  		{"positive number", 3.14159, "3.14159e+00"},
    20  		{"negative number", -2.71828, "-2.71828e+00"},
    21  		{"very small number", 1.23e-20, "1.23e-20"},
    22  		{"very large number", 1.23e+20, "1.23e+20"},
    23  	}
    24  
    25  	for _, test := range tests {
    26  		t.Run(test.name, func(t *testing.T) {
    27  			result := FormatFloat64(test.value)
    28  			if result != test.expected {
    29  				t.Errorf("FormatFloat64(%v) = %q, expected %q", test.value, result, test.expected)
    30  			}
    31  		})
    32  	}
    33  }