github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/tools/syz-testbed/table_test.go (about)

     1  // Copyright 2024 syzkaller project authors. All rights reserved.
     2  // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  package main
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/google/syzkaller/pkg/stats"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestRelativeValues(t *testing.T) {
    14  	table := NewTable("", "A", "B")
    15  	table.Set("row1", "A", NewValueCell(&stats.Sample{Xs: []float64{2, 2}}))
    16  	table.Set("row1", "B", NewValueCell(&stats.Sample{Xs: []float64{3, 3}}))
    17  	// Don't set row2/A.
    18  	table.Set("row2", "B", NewValueCell(&stats.Sample{Xs: []float64{1, 1}}))
    19  
    20  	err := table.SetRelativeValues("A")
    21  	assert.NoError(t, err)
    22  
    23  	assert.InDelta(t, 50.0, *table.Get("row1", "B").(*ValueCell).PercentChange, 0.1)
    24  	assert.Nil(t, table.Get("row1", "A").(*ValueCell).PercentChange)
    25  	assert.Nil(t, table.Get("row2", "A"))
    26  	assert.Nil(t, table.Get("row2", "B").(*ValueCell).PercentChange)
    27  }