main_test.go (1307B)
1 package main 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestParseColorTriplets(t *testing.T) { 9 var matrix = []struct { 10 input string 11 colors []RGBAColor 12 err bool 13 }{ 14 {"aa55aa55", []RGBAColor{{170, 85, 170, 255}}, false}, 15 {"aa55aa55,000000", []RGBAColor{{170, 85, 170, 255}, {0, 0, 0, 255}}, false}, 16 {"#aa55aa55,#000000", []RGBAColor{{170, 85, 170, 255}, {0, 0, 0, 255}}, false}, 17 {"#aa55aa55#000000", []RGBAColor{{170, 85, 170, 255}, {0, 0, 0, 255}}, false}, 18 {"aa55aa55,#000000#808080", []RGBAColor{{170, 85, 170, 255}, {0, 0, 0, 255}, {128, 128, 128, 255}}, false}, 19 {"nothex", []RGBAColor{}, true}, 20 } 21 22 for _, tt := range matrix { 23 c, err := ParseColorTriplets(tt.input) 24 if err != nil { 25 if tt.err { 26 continue 27 } 28 t.Errorf("unexpected error for %s: %s", tt.input, err) 29 continue 30 } 31 32 if !reflect.DeepEqual(c, tt.colors) { 33 t.Errorf("expected %v, got %v", tt.colors, c) 34 } 35 } 36 } 37 38 func TestFactorialCache(t *testing.T) { 39 var matrix = []struct { 40 input int 41 output float64 42 }{ 43 {0, 1}, 44 {1, 1}, 45 {2, 2}, 46 {3, 6}, 47 {4, 24}, 48 {18, 6402373705728000}, 49 {19, 121645100408832000}, 50 } 51 52 fc := NewFactorialCache() 53 54 for _, tt := range matrix { 55 result := fc.Fact(tt.input) 56 if result != tt.output { 57 t.Errorf("expected %0.0f, got %0.0f", tt.output, result) 58 } 59 } 60 }