add some test code
authorSimon J Mudd <sjmudd@pobox.com>
Fri, 14 Nov 2014 22:48:03 +0000 (23:48 +0100)
committerSimon J Mudd <sjmudd@pobox.com>
Fri, 14 Nov 2014 22:53:13 +0000 (23:53 +0100)
lib/common_test.go [new file with mode: 0644]

diff --git a/lib/common_test.go b/lib/common_test.go
new file mode 100644 (file)
index 0000000..c5c37e8
--- /dev/null
@@ -0,0 +1,52 @@
+package lib
+
+import (
+       "testing"
+)
+
+func TestMyName(t *testing.T) {
+       if MyName() != "pstop" {
+               t.Errorf("MyName() expected to be %v but actually was %v", "pstop", MyName())
+       }
+}
+
+func Test_sec_to_time(t *testing.T) {
+       type stuff struct {
+               input  uint64
+               output string
+       }
+       test_data := []stuff{
+               {0, "00:00:00"},
+               {1, "00:00:01"},
+               {61, "00:01:01"},
+               {3601, "01:00:01"},
+               {7384, "02:03:04"},
+               // add more values here
+       }
+       for i := range test_data {
+               if sec_to_time(test_data[i].input) != test_data[i].output {
+                       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))
+               }
+       }
+}
+
+func TestFormatTime(t *testing.T) {
+       type stuff struct {
+               input  uint64
+               output string
+       }
+       test_data := []stuff{
+               {0, ""},
+               {1, "1 ps"},
+               {1000, "   1.00 ns"},
+               {1000000, "   1.00 us"},
+               {1000000000, "   1.00 ms"},
+               {1000000000000, "    1.00 s"},
+               // add more values here
+       }
+       for i := range test_data {
+               if FormatTime(test_data[i].input) != test_data[i].output {
+                       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))
+               }
+       }
+}