package main import ( "testing" "time" ) func TestByte(t *testing.T) { table_int32 := map[int32][4]byte{ 0x12345678: {0x12, 0x34, 0x56, 0x78}, } for i32, b4 := range table_int32 { out := Int32toByteArray(i32) if out != b4 { t.Errorf("Expected %v, got %v\n", b4, out) } } table_int64 := map[int64][8]byte{ 0x0123456789123456: {0x01, 0x23, 0x45, 0x67, 0x89, 0x12, 0x34, 0x56}, } for i64, b8 := range table_int64 { out := Int64toByteArray(i64) if out != b8 { t.Errorf("Expected %v, got %v\n", b8, out) } } } func TestWord(t *testing.T) { table := map[string][][]int{ "this is a test": {{0, 4}, {5, 7}, {8, 9}, {10, 14}}, } for s, e := range table { out := find_words(s) if len(out) != len(e) { t.Errorf("Expected %d, got %d\n", len(e), len(out)) } else { for x := range e { ex := e[x] ox := out[x] if (ex[0] != ox[0]) || (ex[1] != ox[1]) { t.Errorf("Expected %v, got %v\n", ex, ox) } } } } } func TestFormat(t *testing.T) { dt := time.Date(2022, 11, 25, 4, 5, 6, 0, time.Local) table := map[string]string{ "2006-01-02": "2022-11-25", "January 2, 2006": "November 25, 2022", } for f, e := range table { out := FormatDate(dt.Unix(), f) if out != e { t.Errorf("Expected %s, got %s\n", e, out) } } } func TestAbs(t *testing.T) { var table = [][2]int{{-5, 5}, {-1, 1}, {5, 5}, {0, 0}, {-1000, 1000}} for _, i := range table { g := Abs(i[0]) if g != i[1] { t.Errorf("Abs expected %d, got %d\n", i[1], g) } } }