2024-04-11 23:04:30 +02:00
|
|
|
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
2023-04-28 08:49:58 +02:00
|
|
|
// All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package importer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2023-05-04 15:34:36 +02:00
|
|
|
ccunits "github.com/ClusterCockpit/cc-units"
|
2023-04-28 08:49:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNormalizeFactor(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)
|
|
|
|
f, e := getNormalizationFactor(avg)
|
|
|
|
|
|
|
|
fmt.Printf("Factor %e Count %d\n", f, e)
|
|
|
|
|
2023-05-04 15:34:36 +02:00
|
|
|
np := ccunits.NewPrefix("")
|
2023-04-28 08:49:58 +02:00
|
|
|
|
|
|
|
fmt.Printf("Prefix %e Short %s\n", float64(np), np.Prefix())
|
|
|
|
|
2023-05-04 16:27:30 +02:00
|
|
|
p := newPrefixFromFactor(np, e)
|
2023-04-28 08:49:58 +02:00
|
|
|
|
|
|
|
if p.Prefix() != "G" {
|
|
|
|
t.Errorf("Failed Prefix or unit: Want G, Got %s", p.Prefix())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNormalizeKeep(t *testing.T) {
|
|
|
|
s := []float64{3.0, 24.0, 390.0, 391.0}
|
|
|
|
|
|
|
|
total := 0.0
|
|
|
|
for _, number := range s {
|
|
|
|
total += number
|
|
|
|
}
|
|
|
|
avg := total / float64(len(s))
|
|
|
|
|
|
|
|
fmt.Printf("AVG: %e\n", avg)
|
|
|
|
f, e := getNormalizationFactor(avg)
|
|
|
|
|
|
|
|
fmt.Printf("Factor %e Count %d\n", f, e)
|
|
|
|
|
2023-05-04 15:34:36 +02:00
|
|
|
np := ccunits.NewPrefix("G")
|
2023-04-28 08:49:58 +02:00
|
|
|
|
|
|
|
fmt.Printf("Prefix %e Short %s\n", float64(np), np.Prefix())
|
|
|
|
|
2023-05-04 16:27:30 +02:00
|
|
|
p := newPrefixFromFactor(np, e)
|
2023-04-28 08:49:58 +02:00
|
|
|
|
|
|
|
if p.Prefix() != "G" {
|
|
|
|
t.Errorf("Failed Prefix or unit: Want G, Got %s", p.Prefix())
|
|
|
|
}
|
|
|
|
}
|