github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/utils/binstat/binstat_test.go (about) 1 package binstat 2 3 import ( 4 "os" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 func init() { 12 os.Setenv("BINSTAT_ENABLE", "1") 13 os.Setenv("BINSTAT_VERBOSE", "1") 14 os.Setenv("BINSTAT_LEN_WHAT", "~f=99;~eg=99;~example=99") 15 16 global.enable = false 17 tick(100 * time.Millisecond) 18 enterGeneric("", false, 0, 0, false) 19 pointGeneric(nil, "", 0, 0, false) 20 debugGeneric(nil, "", false) 21 bs0 := Enter("~2egEnter") 22 DebugParams(bs0, "foo") 23 LeaveVal(bs0, 123) 24 enterVal("~2egEnterVal", 123) 25 } 26 27 func TestBinstatInternal(t *testing.T) { 28 bs1 := Enter("~2egEnter") 29 DebugParams(bs1, "foo") 30 LeaveVal(bs1, 123) 31 bs1.GetSizeRange() 32 bs1.GetTimeRange() 33 bs1.GetWhat() 34 35 bs2 := EnterTimeVal("~2egEnterTimeVal", 123) 36 Point(bs2, "myPoint") 37 LeaveVal(bs2, 123) 38 39 bs3 := enterTimeVal("~2egenterTimeValInternal", 123) 40 point(bs3, "myPoint") 41 leave(bs3) 42 43 var isIntIsFalse bool = false 44 45 require.Equal(t, "100.000000-199.999999", x_2_y(123.456789, isIntIsFalse)) 46 require.Equal(t, "10.000000-19.999999", x_2_y(12.345678, isIntIsFalse)) 47 require.Equal(t, "1.000000-1.999999", x_2_y(1.2345678, isIntIsFalse)) 48 require.Equal(t, "1.000000-1.999999", x_2_y(1.2345671, isIntIsFalse)) 49 require.Equal(t, "1.000000-1.999999", x_2_y(1.234567, isIntIsFalse)) 50 require.Equal(t, "0.100000-0.199999", x_2_y(0.123456, isIntIsFalse)) 51 require.Equal(t, "0.010000-0.019999", x_2_y(0.012345, isIntIsFalse)) 52 require.Equal(t, "0.001000-0.001999", x_2_y(0.001234, isIntIsFalse)) 53 require.Equal(t, "0.000100-0.000199", x_2_y(0.000123, isIntIsFalse)) 54 require.Equal(t, "0.000010-0.000019", x_2_y(0.000012, isIntIsFalse)) 55 require.Equal(t, "0.000001-0.000001", x_2_y(0.000001, isIntIsFalse)) 56 require.Equal(t, "0.000000-0.000000", x_2_y(0.000000, isIntIsFalse)) 57 58 require.Equal(t, "200.000000-299.999999", x_2_y(234.567890, isIntIsFalse)) 59 require.Equal(t, "20.000000-29.999999", x_2_y(23.456789, isIntIsFalse)) 60 require.Equal(t, "2.000000-2.999999", x_2_y(2.345678, isIntIsFalse)) 61 require.Equal(t, "0.200000-0.299999", x_2_y(0.234567, isIntIsFalse)) 62 require.Equal(t, "0.020000-0.029999", x_2_y(0.023456, isIntIsFalse)) 63 require.Equal(t, "0.002000-0.002999", x_2_y(0.002345, isIntIsFalse)) 64 require.Equal(t, "0.000200-0.000299", x_2_y(0.000234, isIntIsFalse)) 65 require.Equal(t, "0.000020-0.000029", x_2_y(0.000023, isIntIsFalse)) 66 require.Equal(t, "0.000002-0.000002", x_2_y(0.000002, isIntIsFalse)) 67 68 var isIntIsTrue bool = true 69 70 require.Equal(t, "100-199", x_2_y(123.456789, isIntIsTrue)) 71 require.Equal(t, "10-19", x_2_y(12.345678, isIntIsTrue)) 72 require.Equal(t, "1-1", x_2_y(1.234567, isIntIsTrue)) 73 require.Equal(t, "0-0", x_2_y(0.123456, isIntIsTrue)) 74 require.Equal(t, "0-0", x_2_y(0.012345, isIntIsTrue)) 75 require.Equal(t, "0-0", x_2_y(0.001234, isIntIsTrue)) 76 require.Equal(t, "0-0", x_2_y(0.000123, isIntIsTrue)) 77 require.Equal(t, "0-0", x_2_y(0.000012, isIntIsTrue)) 78 require.Equal(t, "0-0", x_2_y(0.000001, isIntIsTrue)) 79 require.Equal(t, "0-0", x_2_y(0.000000, isIntIsTrue)) 80 81 require.Equal(t, "200-299", x_2_y(234.567890, isIntIsTrue)) 82 require.Equal(t, "20-29", x_2_y(23.456789, isIntIsTrue)) 83 require.Equal(t, "2-2", x_2_y(2.345678, isIntIsTrue)) 84 require.Equal(t, "0-0", x_2_y(0.234567, isIntIsTrue)) 85 require.Equal(t, "0-0", x_2_y(0.023456, isIntIsTrue)) 86 require.Equal(t, "0-0", x_2_y(0.002345, isIntIsTrue)) 87 require.Equal(t, "0-0", x_2_y(0.000234, isIntIsTrue)) 88 require.Equal(t, "0-0", x_2_y(0.000023, isIntIsTrue)) 89 require.Equal(t, "0-0", x_2_y(0.000002, isIntIsTrue)) 90 91 // todo: add more tests? which tests? 92 }