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

	float64Array := []float64{}

	expected := float64(0)
	actual := stats.GetAverage(float64Array)
	assert.Equal(t, expected, actual)
}
Beispiel #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))
}
Beispiel #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)
	}
}
Beispiel #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))
}