| 1 | package png2svgscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/ |
| 2 | |
| 3 | import ( |
| 4 | "reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.25.1 testing/" |
| 6 | ) |
| 7 | |
| 8 | func TestShortenColorscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/TestShortenColor().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) { |
| 9 | tests := []struct { |
| 10 | name string |
| 11 | hexColorBytes []byte |
| 12 | colorOptimize bool |
| 13 | expectedOutput []byte |
| 14 | }{ |
| 15 | { |
| 16 | name: "No shorten #0c0000 with colorOptimize false", |
| 17 | hexColorBytes: []byte("#0c0000"), |
| 18 | colorOptimize: false, |
| 19 | expectedOutput: []byte("#0c0000"), |
| 20 | }, |
| 21 | { |
| 22 | name: "Lossy shorten #0c0000 with colorOptimize true", |
| 23 | hexColorBytes: []byte("#0c0000"), |
| 24 | colorOptimize: true, |
| 25 | expectedOutput: []byte("#000"), // Rounded to nearest single hex digit equivalent |
| 26 | }, |
| 27 | { |
| 28 | name: "Lossless shorten #ffffff with colorOptimize true", |
| 29 | hexColorBytes: []byte("#ffffff"), |
| 30 | colorOptimize: true, |
| 31 | expectedOutput: []byte("#fff"), // Lossless compression as each pair is identical |
| 32 | }, |
| 33 | { |
| 34 | name: "No shorten #ffffff with colorOptimize false", |
| 35 | hexColorBytes: []byte("#ffffff"), |
| 36 | colorOptimize: false, |
| 37 | expectedOutput: []byte("#fff"), // Should still shorten losslessly |
| 38 | }, |
| 39 | { |
| 40 | name: "Lossy shorten #112233 with colorOptimize true", |
| 41 | hexColorBytes: []byte("#112233"), |
| 42 | colorOptimize: true, |
| 43 | expectedOutput: []byte("#123"), // Each pair different, so simplified to nearest single hex equivalent |
| 44 | }, |
| 45 | { |
| 46 | name: "No shorten #123456 with colorOptimize false", |
| 47 | hexColorBytes: []byte("#123456"), |
| 48 | colorOptimize: false, |
| 49 | expectedOutput: []byte("#123456"), // No simplification as no pairs are identical |
| 50 | }, |
| 51 | } |
| 52 | |
| 53 | for _, tt := range tests { |
| 54 | t.Runscip-go gomod github.com/golang/go/src go1.25.1 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) { |
| 55 | var result []byte |
| 56 | if tt.colorOptimize { |
| 57 | result = shortenColorLossyscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/shortenColorLossy().(tt.hexColorBytes) |
| 58 | } else { |
| 59 | result = shortenColorLosslessscip-go gomod github.com/xyproto/png2svg . `github.com/xyproto/png2svg`/shortenColorLossless().(tt.hexColorBytes) |
| 60 | } |
| 61 | if !reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(result, tt.expectedOutput) { |
| 62 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("shortenColor(%s, %v) = %s, want %s", tt.hexColorBytes, tt.colorOptimize, result, tt.expectedOutput) |
| 63 | } |
| 64 | }) |
| 65 | } |
| 66 | } |