Debian Codegraph @

mosaic/mosaic_test.go

raw ◀ ▶
1 Debian patch touch this file
1 package mosaic
2
3 import (
4 "image"
5 "image/png"
6 "os"
7 "reflect"
8 "testing"
9 )
10
11 func TestRender(t *testing.T) {
•12 t.Skip("Skip failing test for now, the provided image seems to be corrupt.")
13 raw, err := loadImage("./fixtures/charm-wish.png")
14 if err != nil {
15 t.Errorf("unexpected error: %v", err)
16 os.Exit(1)
17 }
18
19 // Create options
20 mosaic := New().Width(80).Height(40)
21
22 result := mosaic.Render(raw)
23
24 // TODO: Use a smaller image, it is almost impossible seeing the diff by now
25 expected := `              ▄███▄                     
26               █████▀             ▄▄▄    
27               ▀████▀           ▄████▀   
28             ▄▄▄▄     ▄▄▄▄      ▀████▀   
29            ▄████▄  ▄███████▄▄   ▀▀▀▀▄▄▄▄
30         ▄▄▄██████▄███████████▄      ▀██▀
31       ▄███████████████████████▄         
32      ▄███████████████████████████████▄  
33     ▄██████████████████████████████████▄
34 ▄██████████████████████████████████████▄
35 ▀█████▀███████ ████████████████████████▀
36  ▀███▀▄███████ ███████████████████████▀ 
37   ▀███▄████████████████████████████▀▀   
38    ▀██████████████████████████████▀     
39     █████████████████████████████▀      
40     ████████████████████████████▀ ▄███▄ 
41     ████████████████████▀▀▀█▀▀▀   ▀███▀ 
42     ████████████████████           ▀▀▀  
43     █████▀▀    ▀▀███████                
44     ▀▀▀            ▀▀██▀                
45 `
46
47 if !reflect.DeepEqual(result, expected) {
48 a := os.WriteFile("/tmp/dat1", []byte(result), 0o644)
49 t.Log(a)
50 t.Errorf("Result and expected does not match = %v, want %v", result, expected)
51 }
52
53 // used for quick testing
54 // t.Log(result)
55 }
56
57 func loadImage(path string) (image.Image, error) {
58 f, err := os.Open(path)
59 if err != nil {
60 return nil, err
61 }
62 return png.Decode(f)
63 }