From: Simon J Mudd Date: Fri, 14 Nov 2014 22:48:03 +0000 (+0100) Subject: add some test code X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=d6faa487d92c62bb59349693234568f9a1453f38;p=pstop.git add some test code --- diff --git a/lib/common_test.go b/lib/common_test.go new file mode 100644 index 0000000..c5c37e8 --- /dev/null +++ b/lib/common_test.go @@ -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)) + } + } +}