logic_test.go 1.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package logic

import (
	"fmt"
	"os"
	"strings"
	"testing"
	"time"
)

func TestRegExt(t *testing.T) {
	test := " HCU Index: ['5','6']"
	if ReHCUIndex.MatchString(test) {
		t.Log("match")
		f := ReHCUIndex.FindStringSubmatch(test)
		t.Logf("%v", f[1])
	}
}

func TestParse(t *testing.T) {
	content, err := os.ReadFile("./hysmi-pid.log")
	if err != nil {
		t.Error(err)
	}
	s := parse_dcu_info(string(content))
	for _, v := range s {
		t.Logf("%s", v.String())
	}
}

func TestDCUInfo(t *testing.T) {
	s := DCUInfo()
	for _, v := range s {
		t.Logf("%s", v.String())
	}
}

func TestNVIDIAInfo(t *testing.T) {
	start := time.Now
	s := NVIDIAInfo()
	dd := time.Since(start())
	t.Logf("%d ms", dd.Milliseconds())
	for _, v := range s {
		t.Logf("%s", v.String())
	}
}

func formatStr(raw string, l int) string {
	lstr := len(raw)
	if l >= lstr {
		return fmt.Sprintf("%s%s", raw, strings.Repeat(" ", l-lstr))
	}
	return raw[:l]
}

func TestFormatStr(t *testing.T) {
	t.Logf("|%s|", formatStr("hello world", 2))
	t.Logf("|%s|", formatStr("hello world", 20))
}