mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-22 20:41:40 +02:00
Restructure black box test
Remove string ptr from unit prefix
This commit is contained in:
@@ -95,8 +95,8 @@ var JobDefaults BaseJob = BaseJob{
|
||||
}
|
||||
|
||||
type Unit struct {
|
||||
Base string `json:"base"`
|
||||
Prefix *string `json:"prefix,omitempty"`
|
||||
Base string `json:"base"`
|
||||
Prefix string `json:"prefix,omitempty"`
|
||||
}
|
||||
|
||||
// JobStatistics model
|
||||
|
@@ -147,7 +147,7 @@ func ConvertUnitString(us string) schema.Unit {
|
||||
p := u.getPrefix()
|
||||
if p.Prefix() != "" {
|
||||
prefix := p.Prefix()
|
||||
nu.Prefix = &prefix
|
||||
nu.Prefix = prefix
|
||||
}
|
||||
m := u.getMeasure()
|
||||
d := u.getUnitDenominator()
|
||||
|
@@ -228,80 +228,80 @@ func TestConvertSeries(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeValue(t *testing.T) {
|
||||
var s string
|
||||
v := float64(103456)
|
||||
|
||||
NormalizeValue(&v, "MB/s", &s)
|
||||
|
||||
if v != 104.00 {
|
||||
t.Errorf("Failed ConvertValue: Want 104.00, Got %f", v)
|
||||
}
|
||||
if s != "GB/s" {
|
||||
t.Errorf("Failed Prefix or unit: Want GB/s, Got %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeValueNoPrefix(t *testing.T) {
|
||||
var s string
|
||||
v := float64(103458596)
|
||||
|
||||
NormalizeValue(&v, "F/s", &s)
|
||||
|
||||
if v != 104.00 {
|
||||
t.Errorf("Failed ConvertValue: Want 104.00, Got %f", v)
|
||||
}
|
||||
if s != "MF/s" {
|
||||
t.Errorf("Failed Prefix or unit: Want MF/s, Got %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeValueKeep(t *testing.T) {
|
||||
var s string
|
||||
v := float64(345)
|
||||
|
||||
NormalizeValue(&v, "MB/s", &s)
|
||||
|
||||
if v != 345.00 {
|
||||
t.Errorf("Failed ConvertValue: Want 104.00, Got %f", v)
|
||||
}
|
||||
if s != "MB/s" {
|
||||
t.Errorf("Failed Prefix or unit: Want GB/s, Got %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeValueDown(t *testing.T) {
|
||||
var s string
|
||||
v := float64(0.0004578)
|
||||
|
||||
NormalizeValue(&v, "GB/s", &s)
|
||||
|
||||
if v != 458.00 {
|
||||
t.Errorf("Failed ConvertValue: Want 458.00, Got %f", v)
|
||||
}
|
||||
if s != "KB/s" {
|
||||
t.Errorf("Failed Prefix or unit: Want KB/s, Got %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeSeries(t *testing.T) {
|
||||
var us string
|
||||
s := []float64{2890031237, 23998994567, 389734042344, 390349424345}
|
||||
r := []float64{3, 24, 390, 391}
|
||||
|
||||
total := 0.0
|
||||
for _, number := range s {
|
||||
total += number
|
||||
}
|
||||
avg := total / float64(len(s))
|
||||
|
||||
fmt.Printf("AVG: %e\n", avg)
|
||||
NormalizeSeries(s, avg, "KB/s", &us)
|
||||
|
||||
if !reflect.DeepEqual(s, r) {
|
||||
t.Errorf("Failed ConvertValue: Want 3, 24, 390, 391, Got %v", s)
|
||||
}
|
||||
if us != "TB/s" {
|
||||
t.Errorf("Failed Prefix or unit: Want TB/s, Got %s", us)
|
||||
}
|
||||
}
|
||||
// func TestNormalizeValue(t *testing.T) {
|
||||
// var s string
|
||||
// v := float64(103456)
|
||||
//
|
||||
// NormalizeValue(&v, "MB/s", &s)
|
||||
//
|
||||
// if v != 104.00 {
|
||||
// t.Errorf("Failed ConvertValue: Want 104.00, Got %f", v)
|
||||
// }
|
||||
// if s != "GB/s" {
|
||||
// t.Errorf("Failed Prefix or unit: Want GB/s, Got %s", s)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func TestNormalizeValueNoPrefix(t *testing.T) {
|
||||
// var s string
|
||||
// v := float64(103458596)
|
||||
//
|
||||
// NormalizeValue(&v, "F/s", &s)
|
||||
//
|
||||
// if v != 104.00 {
|
||||
// t.Errorf("Failed ConvertValue: Want 104.00, Got %f", v)
|
||||
// }
|
||||
// if s != "MF/s" {
|
||||
// t.Errorf("Failed Prefix or unit: Want MF/s, Got %s", s)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func TestNormalizeValueKeep(t *testing.T) {
|
||||
// var s string
|
||||
// v := float64(345)
|
||||
//
|
||||
// NormalizeValue(&v, "MB/s", &s)
|
||||
//
|
||||
// if v != 345.00 {
|
||||
// t.Errorf("Failed ConvertValue: Want 104.00, Got %f", v)
|
||||
// }
|
||||
// if s != "MB/s" {
|
||||
// t.Errorf("Failed Prefix or unit: Want GB/s, Got %s", s)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func TestNormalizeValueDown(t *testing.T) {
|
||||
// var s string
|
||||
// v := float64(0.0004578)
|
||||
//
|
||||
// NormalizeValue(&v, "GB/s", &s)
|
||||
//
|
||||
// if v != 458.00 {
|
||||
// t.Errorf("Failed ConvertValue: Want 458.00, Got %f", v)
|
||||
// }
|
||||
// if s != "KB/s" {
|
||||
// t.Errorf("Failed Prefix or unit: Want KB/s, Got %s", s)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func TestNormalizeSeries(t *testing.T) {
|
||||
// var us string
|
||||
// s := []float64{2890031237, 23998994567, 389734042344, 390349424345}
|
||||
// r := []float64{3, 24, 390, 391}
|
||||
//
|
||||
// total := 0.0
|
||||
// for _, number := range s {
|
||||
// total += number
|
||||
// }
|
||||
// avg := total / float64(len(s))
|
||||
//
|
||||
// fmt.Printf("AVG: %e\n", avg)
|
||||
// NormalizeSeries(s, avg, "KB/s", &us)
|
||||
//
|
||||
// if !reflect.DeepEqual(s, r) {
|
||||
// t.Errorf("Failed ConvertValue: Want 3, 24, 390, 391, Got %v", s)
|
||||
// }
|
||||
// if us != "TB/s" {
|
||||
// t.Errorf("Failed Prefix or unit: Want TB/s, Got %s", us)
|
||||
// }
|
||||
// }
|
||||
|
Reference in New Issue
Block a user