예제 #1
0
func TestGetAverage_NOK_emptyArray(t *testing.T) {

	float64Array := []float64{}

	expected := float64(0)
	actual := stats.GetAverage(float64Array)
	assert.Equal(t, expected, actual)
}
예제 #2
0
func TestBuildCPUMultipleStat_OK(t *testing.T) {

	float64Array := []float64{11.904762, 27.5, 5, 2.5, 7.692308, 31.707317, 2.4390242, 7.317073}
	cpu := stats.BuildCPUMultipleStat(float64Array)

	assert := assert.New(t)
	assert.NotNil(cpu)
	assert.Equal(len(float64Array), cpu.NumberOfCores)
	assert.Equal(stats.GetAverage(float64Array), cpu.AverageUsagePercentage)
	assert.Equal(len(float64Array), len(cpu.UsagePercentagePerCore))
}
예제 #3
0
func TestGetAverage_OK(t *testing.T) {

	float64Array := []float64{11.904762, 27.5, 5, 2.5, 7.692308, 31.707317, 2.4390242, 7.317073}

	expected := float64(12.007560525)
	actual := stats.GetAverage(float64Array)
	difference := math.Abs(float64(expected - actual))

	if difference >= 1 {
		t.Error("Expected a difference less than 1, got: ", difference)
	}
}
예제 #4
0
func TestBuildCPUMultipleStat_NOK_emptyArray(t *testing.T) {

	float64Array := []float64{}
	cpu := stats.BuildCPUMultipleStat(float64Array)

	assert := assert.New(t)
	assert.NotNil(cpu)
	assert.Equal(len(float64Array), cpu.NumberOfCores)
	assert.Equal(stats.GetAverage(float64Array), cpu.AverageUsagePercentage)
	assert.Equal(float64(0), cpu.AverageUsagePercentage)
	assert.Equal(len(float64Array), len(cpu.UsagePercentagePerCore))
	assert.Equal(0, len(cpu.UsagePercentagePerCore))
}