Debian Codegraph @

mosaic/mosaic_test.go

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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 raw, err := loadImage("./fixtures/charm-wish.png")
13 if err != nil {
14 t.Errorf("unexpected error: %v", err)
15 os.Exit(1)
16 }
17
18 // Create options
19 mosaic := New().Width(80).Height(40)
20
21 result := mosaic.Render(raw)
22
23 // TODO: Use a smaller image, it is almost impossible seeing the diff by now
24 expected := `              ▄███▄                     
25               █████▀             ▄▄▄    
26               ▀████▀           ▄████▀   
27             ▄▄▄▄     ▄▄▄▄      ▀████▀   
28            ▄████▄  ▄███████▄▄   ▀▀▀▀▄▄▄▄
29         ▄▄▄██████▄███████████▄      ▀██▀
30       ▄███████████████████████▄         
31      ▄███████████████████████████████▄  
32     ▄██████████████████████████████████▄
33 ▄██████████████████████████████████████▄
34 ▀█████▀███████ ████████████████████████▀
35  ▀███▀▄███████ ███████████████████████▀ 
36   ▀███▄████████████████████████████▀▀   
37    ▀██████████████████████████████▀     
38     █████████████████████████████▀      
39     ████████████████████████████▀ ▄███▄ 
40     ████████████████████▀▀▀█▀▀▀   ▀███▀ 
41     ████████████████████           ▀▀▀  
42     █████▀▀    ▀▀███████                
43     ▀▀▀            ▀▀██▀                
44 `
45
46 if !reflect.DeepEqual(result, expected) {
47 a := os.WriteFile("/tmp/dat1", []byte(result), 0o644)
48 t.Log(a)
49 t.Errorf("Result and expected does not match = %v, want %v", result, expected)
50 }
51
52 // used for quick testing
53 // t.Log(result)
54 }
55
56 func loadImage(path string) (image.Image, error) {
57 f, err := os.Open(path)
58 if err != nil {
59 return nil, err
60 }
61 return png.Decode(f)
62 }