Fix markup
[pstop.git] / lib / common_test.go
1 package lib
2
3 import (
4         "testing"
5 )
6
7 func TestMyName(t *testing.T) {
8         if MyName() != "pstop" {
9                 t.Errorf("MyName() expected to be %v but actually was %v", "pstop", MyName())
10         }
11 }
12
13 func Test_sec_to_time(t *testing.T) {
14         type stuff struct {
15                 input  uint64
16                 output string
17         }
18         test_data := []stuff{
19                 {0, "00:00:00"},
20                 {1, "00:00:01"},
21                 {61, "00:01:01"},
22                 {3601, "01:00:01"},
23                 {7384, "02:03:04"},
24                 // add more values here
25         }
26         for i := range test_data {
27                 if sec_to_time(test_data[i].input) != test_data[i].output {
28                         t.Errorf("sec_to_time(%v) expected to be %v but actually was %v", test_data[i].input, test_data[i].output, sec_to_time(test_data[i].input))
29                 }
30         }
31 }
32
33 func TestFormatTime(t *testing.T) {
34         type stuff struct {
35                 input  uint64
36                 output string
37         }
38         test_data := []stuff{
39                 {0, ""},
40                 {1, "1 ps"},
41                 {1000, "   1.00 ns"},
42                 {1000000, "   1.00 us"},
43                 {1000000000, "   1.00 ms"},
44                 {1000000000000, "    1.00 s"},
45                 // add more values here
46         }
47         for i := range test_data {
48                 if FormatTime(test_data[i].input) != test_data[i].output {
49                         t.Errorf("FormatTime(%v) expected to be %v but actually was %v", test_data[i].input, test_data[i].output, FormatTime(test_data[i].input))
50                 }
51         }
52 }