1package core
2
3import (
4 "reflect"
5 "testing"
6)
7
8func TestCleanScales(t *testing.T) {
9 for _, tc := range []struct {
10 w, h int
11 want []float64
12 }{
13 {5120, 2160, []float64{1, 1.25, 4.0 / 3, 1.6, 5.0 / 3, 2, 2.5, 8.0 / 3}},
14 {3840, 2160, []float64{1, 1.2, 1.25, 4.0 / 3, 1.5, 1.6, 5.0 / 3, 1.875, 2, 2.4, 2.5, 8.0 / 3, 3}},
15 } {
16 if got := CleanScales(tc.w, tc.h); !reflect.DeepEqual(got, tc.want) {
17 t.Errorf("%dx%d: %v", tc.w, tc.h, got)
18 }
19 }
20}
21
22func TestStepScale(t *testing.T) {
23 if s := StepScale(5120, 2160, 1, 1); s != 1.25 {
24 t.Fatal(s)
25 }
26 // 1.5 is not clean on 5K: up goes to 1.6, down to 4/3.
27 if s := StepScale(5120, 2160, 1.5, 1); s != 1.6 {
28 t.Fatal(s)
29 }
30 if s := StepScale(5120, 2160, 1.5, -1); s != 4.0/3 {
31 t.Fatal(s)
32 }
33 if s := StepScale(5120, 2160, 1, -1); s != 1 {
34 t.Fatal(s)
35 }
36 if s := StepScale(1920, 1080, 3, 1); s != 3 {
37 t.Fatal(s)
38 }
39}
40
41func TestSnapScale(t *testing.T) {
42 for in, want := range map[float64]float64{0: 1, -2: 1, 1.5: 1.5, 1.3333: 160.0 / 120, 9: 4} {
43 if got := SnapScale(in); got != want {
44 t.Errorf("%v: %v", in, got)
45 }
46 }
47}